I have this JSF (Java EE 7, provided by GlassFish 4.1 + PrimeFaces 5.1) form containing database connection information like host name, port number, etc. Also part of this form is a URL field. I want this field to be editable, but I also want to be able to set the value based on the other fields.
To do so I created a button with an action listener where I'm reading the posted data from the request parameter map and generate the new URL value. Then I want to put the new value in the URL field and use that value instead of the posted data. What I tried is to get the component as EditableValueHolder and set the submitted value and render the response. I also tried setting the component's value and calling resetValue.
The best result was the URL field being updates after two clicks.
XHTML:
<p:inputText id="url"
             size="50"
             value="#{database.url}"/>
<p:commandButton icon="ui-icon-arrowrefresh-1-w"
                 immediate="true"
                 actionListener="#{database.createConnectionURL('namingContainer')}">
  <p:ajax update="url" />
</p:commandButton>
Bean (using OmniFaces):
UIComponent urlComponent = Faces.getViewRoot().findComponent(namingContainer + "url");
if (urlComponent instanceof EditableValueHolder) {
  EditableValueHolder editValHolder = (EditableValueHolder) urlComponent;
  editValHolder.setSubmittedValue(urlValue);
}
Faces.getContext().renderResponse();
 
     
    