Define JSF container form identifier

I need to determine the form field id from the action handler. The field is part of the included facelets component, so the shape will change.

included.xhtml

<ui:component>
  <h:inputText id="contained_field"/>
  <h:commandButton actionListener="#{backingBean.update}" value="Submit"/>
</ui:component>

example_containing.xhtml

<h:form id="containing_form">
  <ui:include src="/included.xhtml"/>
</h:form>

How to determine the form identifier in a method updateat runtime? Or better yet, the ID of the input field directly.

+3
source share
3 answers

Bind the button to your bean support, then use getParent () until you find the closest form.

+5
source

jsight. ( JSF , ), . h: form , , Form: containsfield. : JSF, , , (parentNamingContainerId:) * componentId

0

Since the update method is of type actionListener, you can access your user interface component as follows

public void update(javax.faces.event.ActionEvent ac) {
      javax.faces.component.UIComponent myCommand = ac.getComponent( );
      String id = myCommand.getId(); // get the id of the firing component

      ..... your code .........

}
0
source

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


All Articles