JSF 2.0 dynamic attributes without creating new components

怎甘沉沦 提交于 2020-01-23 12:18:52

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/5712364/jsf-2-0-dynamic-attributes-without-creating-new-components

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!