而无需创建新组件

而无需创建新组件

本文介绍了JSF 2.0动态属性,而无需创建新组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将新属性添加到没有创建自己属性就无法定义这些属性的组件中.

我想做这样的事情

<h:commandButton actionListener="#{manager.saveNew}" value="#{i18n['School.create']}" secured="true" />

或者至少是一种允许开发人员分配安全属性的方法.

有什么想法吗?

解决方案

您可以在h:commandButton中使用f:attribute.

<h:commandButton actionListener="#{manager.saveNew}
                 value="#{i18n['School.create']}">
     <f:attribute name="secured" value="true" />
</h:commandButton>

在您的操作方法中:

public void saveNew(ActionEvent event) {
   String secured = (String) event.getComponent().getAttributes().get("secured");
}

这是关于此主题的综合教程. /p>

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?

解决方案

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.

这篇关于JSF 2.0动态属性,而无需创建新组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-28 05:54