jsf-2 - 使用 f :attribute inside a composite component

标签 jsf-2 attributes composite-component

我们有一个(在我们看来)非常简单的场景。但是我们不知何故卡在了复合组件和 f:attribute 标签上。我会尽量保持代码简单。

复合组件:

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

...现在我们像这样使用组件:

<ctrl:button
    ...
    actionListener="#{bean.method}"
    ...>
    <f:attribute name="objectId" value="#{someObject.id}" />
</ctrl:button>

现在我们需要访问 Action 监听器方法中的“objectId”属性。我们已经尝试过这样的事情:

public void method(ActionEvent event)
{
    ...
    event.getComponent().getAttributes().get("objectId");
    ...
}

但是属性映射不包含 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>

由于 EL 2.2(这是 Servlet 3.0 的标准部分,但对于 Servlet 2.5 可在 JBoss EL 的帮助下实现),您甚至可以将整个对象作为方法参数传递:
<ctrl:button action="#{bean.method(someObject.id)}" />

关于jsf-2 - 使用 f :attribute inside a composite component,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9032771/

相关文章:

javascript - 如何使同一个 JSF 复合组件包含多次以拥有自己的 javascript 范围?

jsf-2 - JSF,复合组件 : method call with default attribute value as parameter

jsf - JSF 新手 : composition vs composite

jsf - 如何在h :outputText中写单引号和双引号

validation - 在 JSF 中验证字段并抛出异常,但将错误消息附加到另一个字段?

ios - 具有不同 NSMutableParagraphStyle 的 Nsattributedstring

mongodb - 不使用 golang 的带有部分属性的 mgo 查找文档

delphi - Delphi 属性真实世界示例在哪里?

jsf - JSESSIONID cookie 何时添加到响应中

jsf-2 - JSF 对话