2

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!

Budenzauber
  • 113
  • 2
  • 10

1 Answers1

2

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!

Budenzauber
  • 113
  • 2
  • 10