Sli*_*ady 4 attributes composite-component jsf-2
我们在这里有一个(在我们的观点中)非常简单的场景.但是我们在复合组件和f:属性标签上遇到了问题.我会尽量保持代码尽可能简单.
复合组件:
<cc:interface name="button">
...
<cc:attribute
name="actionListener"
required="true"
method-signature="void f(javax.faces.event.ActionEvent)"
target="button"
shortDescription="The action listener for this button." />
...
</cc:interface>
<cc:implementation>
<ice:commandButton
...
actionListener="#{cc.attrs.actionListener}"
...>
<cc:insertChildren />
</ice:commandButton>
</cc:implementation>
Run Code Online (Sandbox Code Playgroud)
...现在我们使用这样的组件:
<ctrl:button
...
actionListener="#{bean.method}"
...>
<f:attribute name="objectId" value="#{someObject.id}" />
</ctrl:button>
Run Code Online (Sandbox Code Playgroud)
现在我们需要访问动作侦听器方法中的"objectId"属性.我们已经尝试过这样的事情了:
public void method(ActionEvent event)
{
...
event.getComponent().getAttributes().get("objectId");
...
}
Run Code Online (Sandbox Code Playgroud)
但属性映射不包含objectId.这种方法有什么问题吗?解决此问题的推荐方法是什么?
如果有人可以帮助我们,那会很好.
谢谢!阿姆
<f:attribute>当无法将对象作为命令按钮/链接的附加参数传递时,这个hack是JSF 1.0/1.1的遗留物.从JSF 1.2开始,你应该使用<f:setPropertyActionListener>它.
<ctrl:button action="#{bean.method}">
<f:setPropertyActionListener target="#{bean.objectId}" value="#{someObject.id}" />
</ctrl:button>
Run Code Online (Sandbox Code Playgroud)
由于EL 2.2(它是Servlet 3.0的标准部分,但是在JBoss EL的帮助下可以实现Servlet 2.5 ),你甚至可以将整个对象作为方法参数传递:
<ctrl:button action="#{bean.method(someObject.id)}" />
Run Code Online (Sandbox Code Playgroud)