JSF与setValueExpression绑定只读? [英] JSF binding with setValueExpression read-only?
问题描述
我尝试在后台bean中创建一个InputField并将其添加到视图中,但是数据绑定似乎只是只读。
我创建一个UIInput在这样的Backing-Bean中:
UIComponent textInput = new UIInput();
textInput.setId(operandInputText);
textInput.setValueExpression(value,ef.createValueExpression(elCtx,#{row.operandValues [0]},String.class));
textInput.setValueExpression(rendered,ef.createValueExpression(elCtx,#{row.inputType =='text'},Boolean.class));
mInputPanelGroup.getChildren()。add(textInput);
panelGroup位于dataTable的列中,并绑定到bean:
< p:column id =operandColumn>
< h:panelGroup id =inputPanelGroupbinding =#{locateEmployeeBean.inputPanelGroup}>
< h:inputText id =testInputvalue =#{row.operandValues [0]}/>
< / h:panelGroup>
< / p:column>
< h:inputText />
PanelGroup里面只是用于测试,这是我发现我使用 setValueExpression(...)
所做的绑定至少是只读的。
在浏览器中,我现在有2个inputField,首先是'testInput',然后是'operandInputText'。
当我在'operandInputText'中输入一个值并提交时,该值不会被保存,但是当我在'testInput'-Field'中输入一个值时,它会被提交,另外该值显示在BOTH inputFields
operandValues是一个simpe对象数组:
private Object [] mOperandValues = new Object [2];
这可能与dataType有任何关系,我传递给 setValueExpression(。 ..)
?
我尝试了对象,但没有改变任何东西。
任何想法为什么会发生这种情况?
提前感谢
我找到了解决问题的办法。老实说,这是@BalusC使用Datatables的一篇文章:填充datatable是什么让我在正确的路径。
以前,我在PreRenderView阶段添加了组件,然后我看到您的示例,您填充了getter中的绑定组件ONCE(在RestoreView阶段中显然是较早的方法)。这就是我现在所做的工作,它的工作原理是完美的,Inputfields现在工作方式(读+写)。
非常感谢你的工作@BalusC! / p>
I try to create an InputField in the backing bean and add it to the view, but the databinding seems to work just read-only.
I create a UIInput in the Backing-Bean like this:
UIComponent textInput = new UIInput();
textInput.setId("operandInputText");
textInput.setValueExpression("value", ef.createValueExpression(elCtx, "#{row.operandValues[0]}", String.class));
textInput.setValueExpression("rendered", ef.createValueExpression(elCtx, "#{row.inputType == 'text'}", Boolean.class));
mInputPanelGroup.getChildren().add(textInput);
The panelGroup is inside a column of a dataTable and bound to the bean:
<p:column id="operandColumn">
<h:panelGroup id="inputPanelGroup" binding="#{locateEmployeeBean.inputPanelGroup}" >
<h:inputText id="testInput" value="#{row.operandValues[0]}" />
</h:panelGroup>
</p:column>
The <h:inputText/>
inside the PanelGroup is just for testing and this is where I found out that the binding I did with setValueExpression(...)
works at least read-only.
In the browser I now have 2 inputFields, first the 'testInput' and then 'operandInputText'. When I enter a value in 'operandInputText' and submit, the value does not get saved, but when I enter a value in the 'testInput'-Field, it get's submitted and in addition the value gets displayed in BOTH inputFields.
The operandValues is a simpe object array:
private Object[] mOperandValues = new Object[2];
Could this have anything to do with the dataType I pass to setValueExpression(...)
?
I tried Object, but that didn't change anything.
Any idea why this happens? Thanks in advance!
I found the solution to my problem. Honestly it was an article by @BalusC Using Datatables: Populate datatable what took me on the right path.
Previously I added the components during PreRenderView-Phase, then I saw in your example that you populate the bound component ONCE in the getter (which is then obviously way earlier during RestoreView-Phase). That is how I've done it now and it works flawlessly, the Inputfields now work both ways (read+write).
Thanks alot for your work @BalusC!
这篇关于JSF与setValueExpression绑定只读?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!