Conditionally displayed input component does not update value

Using jsf 2 and Primefaces 3.4

I know that there are many similar questions, but none of them work on this.

When the "inner" grid panel is displayed with a fixed value of "true" ( <h:panelGrid id="inner" rendered="true"> ) => after pressing the control button, the input component correctly updates the value # {tableMatchesBean.mergedAuthorAjax},

but if the rendering of this panel is conditional : <h:panelGrid rendered="#{spellCheckBean.renderInputMerge}"> => then the input component is silent (no trace called by tableMatchesBean.mergedAuthorAjax).

Note. I used nested grids to place the rendering condition in the parent element of the component that should be conditionally rendered (output and input components). Any help was appreciated.

[EDIT after comment:] What the xhtml page does:
- when the user clicks on the "merge" parameter in selectOnebutton, the ajax update switches "renderInputMerge" to true, which leads to the display of the "external" component. It is working fine. This component has an input field that displays OK.
- after the user clicks on the commandLink button, I need to get the value of this input field. As explained above, I have a problem with this.

xhtml:

 <h:body style ="width:100%"> <h:form id = "currMatch"> <h:panelGrid> <p:selectOneButton id ="selection" value="#{spellCheckBean.optionChosen}"> <f:selectItem itemLabel="keep both" itemValue="1" /> <f:selectItem itemLabel="delete both" itemValue="2" /> <f:selectItem itemLabel="merge" itemValue="3" /> <p:ajax update="outer" /> </p:selectOneButton> </h:panelGrid> <h:panelGrid id="outer" > <h:panelGrid id="inner" rendered="#{spellCheckBean.renderInputMerge}"> <!-- **the line above does not update**, this one does <h:panelGrid rendered="true">--> <h:outputText value="our suggestion: " style ="margin-left: auto; margin-right: auto"/> <h:inputText id ="testinput" value="#{tableMatchesBean.mergedAuthorAjax}"> </h:inputText> </h:panelGrid> </h:panelGrid> <p:commandButton action="#{tableMatchesBean.next_()}" title="Add" value="next" update ="currMatch" > </p:commandButton> </h:form> </h:body> 

+4
source share
2 answers

Your rendered condition obviously depends on the query range variable, for example. The property of the managed area of ​​the request bean or request parameter. The form presents the accounts as a completely independent and new request if all managed requests managed by beans are recreated, and all properties are set to the default value. If the rendered attribute evaluates to false during the collection of the submitted values ​​(the request phase of the application form), they simply will not be collected.

There are basically 2 ways to solve this problem:

  • Make sure that the condition underlying the rendered attribute is correctly initialized in the constructor (post) of the object with the bean request, so that it returns exactly the same value during the submit as form processing request as it was during the enduser form display request.

  • Put the bean in scope. This way the bean instance will work as long as you interact with the same ajax view or return void or null in the action method.

See also:

+4
source

Try using the jstl c:if tag instead of rendered . This works for me.

-3
source

Source: https://habr.com/ru/post/1433334/


All Articles