Reputation: 47
I created a Facelets page. In the page dynamically generated some buttons, each button has a ID, When submitted the event, I want to pass a button's ID to the action.(button is dynamically)
But i don't know how to pass dynamic parameters in JSF.
Upvotes: 1
Views: 1264
Reputation: 1108742
You can get the button component in the action method by UIComponent#getCurrentComponent()
:
public void submit() {
UIComponent button = UIComponent.getCurrentComponent(FacesContext.getCurrentInstance());
String id = button.getId(); // or button.getClientId();
// ...
}
Alternatively, if you're targeting a Servlet 3.0 / EL 2.2 container (Tomcat 7, Glassfish 3, etc), then you can just invoke methods with arguments in EL:
<h:commandButton action="#{bean.submit(component.id)}" /> <!-- or component.clientId -->
with
public void submit(String id) {
// ...
}
Upvotes: 2