2

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?

Farouk Alhassan
  • 3,780
  • 9
  • 51
  • 74

1 Answers1

3

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.

Matt Handy
  • 29,855
  • 2
  • 89
  • 112