Farouk Alhassan
Farouk Alhassan

Reputation: 3808

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 do 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?

Upvotes: 2

Views: 1557

Answers (1)

Matt Handy
Matt Handy

Reputation: 30025

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.

Upvotes: 3

Related Questions