【发布时间】:2016-08-02 11:33:32
【问题描述】:
我有一个p:dataTable,其中每一行都有一个p:commondButton 和一个h:outputText 来显示项目的名称。
单击p:commandButton 会调用anfrageErfassenModel.applyProjekt() actionListener 并应立即
为anfrageErfassenModel.anfrage.name 更新p:inputText 中的值。
JSF 页面 - anfrageErfassen.xhtml:
<h:form id="formAnfrageErfassen">
<p:panelGrid columns="3" id="anfrage">
<p:outputLabel for="name" value="#{bundle['anfrage.name']}"/>
<p:inputText id="name" value="#{anfrageErfassenModel.anfrage.name}" required="true" />
<p:message for="name" id="message4name" display="text"/>
</p:panelGrid>
<p:dataTable var="projekt" ...>
<p:column>
<p:commandButton icon="fa fa-check"
title="Apply Project"
update=":formAnfrageErfassen:anfrage"
immediate="true"
actionListener="#{anfrageErfassenModel.applyProjekt(projekt)}"/>
</p:column>
<p:column>
<h:outputText value="#{projekt.name}"/>
</p:column>
</p:dataTable>
</h:form>
Bean - AnfrageErfassenModel.java:
@Named
@ViewScoped
public class AnfrageErfassenModel implements Serializable {
private Anfrage anfrage; // with getter / setter
public void applyProjekt(final Projekt projekt) {
logger.entry(projekt);
anfrage = anfrageRestClient.create();
anfrage.setName(projekt.getName()); // take name from projekt
logger.debug("anfrage.name=" + anfrage.getName());
logger.exit();
}
}
actionListener 调用 anfrage.setName(projekt.getName()) 导致模型的值按预期设置
-> 但是p:inputText 没有更新!
我知道immediate="true" 的意思是,APPLY_REQUEST_VALUES 阶段之后是 RENDER_RESPONSE 阶段!
我必须怎么做才能使用模型的当前值更新 inputText 字段的值?
使用 p:outputText 而不是 p:inputText 有效,但我需要 inputText 因为该字段必须可由用户编辑!
我在 WildFly 10.0.0.Final 上使用 Primefaces 6.0。
感谢和问候, 雷纳
【问题讨论】:
-
你尝试添加
<p:ajax listner="#{managedBean.yourMethod()}" update =":Yourcomponante" />??? -
@YagamiLight:
p:commandButton中内置了 Ajax。那里不需要添加ajax标签。 -
@Kukeltje 相信我有时它确实有效
-
你检查过你在commandButton的update属性中使用的id是否正确吗?例如。表单不是偶然嵌套在命名容器中的吗?
-
如果您有明确的需要,我会相信您。你现在说'有时'....我个人从来不需要在 commandButton 中添加一个 ajax 标签来让它更新一些东西。如果更新不起作用,则 60% 的时间是错误的引用(缺少命名容器) 20% 的时间是拼写错误,20% 的时间是未调用 action/actionListener 的错误,因此更新不应该发生。请记住, outputText 有效!顺便说一句,这意味着我对命名容器的评论无效
标签: jsf primefaces