【发布时间】:2018-11-26 21:05:55
【问题描述】:
我正在尝试以编程方式创建 Primefaces UIComponents,但不知何故我无法将数据获取到 Backing Bean。不确定是 Ajax 还是我为 InputText 设置的值。 我想以编程方式编写的代码:
<p:inputText id="id_test" value="#{myBean.value}">
<p:ajax />
</p:inputText>
这是我尝试解决问题的方法:
private String value; // Getter&Setter
public void buildComponent(){
FacesContext fc = FacesContext.getCurrentInstance();
Application ap = fc.getApplication();
InputText inputText = (InputText) ap.createComponent(fc, "org.primefaces.component.InputText", "org.primefaces.component.InputTextRenderer")
inputText.setValue(value);
inputText.setId("id_test");
AjaxBehavior ajaxBehavior = (AjaxBehavior) ap.createBehavior(AjaxBehavior.BEHAVIOR_ID);
inputText.addClientBehavior(inputText.getDefaultEventName(), behavior);
}
【问题讨论】:
-
您已将具体的字符串值设置为
InputText.setValue(),但您需要提供实际的ValueExpression。 -
谢谢你帮我解决了。
-
所以这里解决的实际问题与 Primefaces 和 AJAX 无关,可以简化为与 stackoverflow.com/questions/3510614/… 重复的问题
-
@Selaron 是的,你是对的。为我的无知道歉!
-
不是问题,不是判断,只是结论。我们的开发人员一直在寻找最复杂的方向,即使根本原因就像打字错误一样简单;-)
标签: jsf primefaces