JSF 2.0 dynamic attributes without creating new components
How do you add new attributes to a component that doesn't define those attributes without creating your own.
I want to d开发者_开发百科o something like this
<h:commandButton actionListener="#{manager.saveNew}" value="#{i18n['School.create']}" secured="true" />
or at least, a way to allow the developer to assign the secure attribute.
any ideas?
You can use f:attribute
inside your h:commandButton
.
<h:commandButton actionListener="#{manager.saveNew}
value="#{i18n['School.create']}">
<f:attribute name="secured" value="true" />
</h:commandButton>
And in your action method:
public void saveNew(ActionEvent event) {
String secured = (String) event.getComponent().getAttributes().get("secured");
}
Here is a comprehensive tutorial on this topic.
精彩评论