f:属性是否支持除String之外的其他内容?

时间:2011-07-08 10:56:53

标签: list jsf tags icefaces

我需要实现一个将列表传递给其支持bean的ice:commandButton。我不是在portlet范围内,而是在标记范围内。

我知道当我从actionListener中检索f:attribute时,我得到一个必须要转换的对象。

我想知道我是否可以将f:属性映射到List<MyClass>,其中列表的实际实例实际上 ArrayListMyClass是可序列化的。

类似的东西:

MyTag.xhtml

<ice:commandButton actionListener="#{TagBean.doPrintItems}">
    <f:attribute name="collection" value="#{items}" />
</ice:commandButton>
//[other things]

MyPortlet.jspx

<my:printPopup items="#{BackingBean.itemsToPrint}" />

BackingBean.java

class BackingBean {
    private List<MyClass> itemsToPrint;

    //getter and setter of course
}

TagBean.java

class TagBean {
    private List<MyClass> collection;

    //getter and setter of course
    public void doPrint(ActionEvent e) {
        collection = (List<MyClass>) e.getComponent().getAttributes().get("collection");
    }

你认为这是可行的吗?感谢

1 个答案:

答案 0 :(得分:0)

<f:attribute>使您可以添加自定义组件属性。它们将存储在服务器端的组件树状态中。所以它可以是你想要的任何Java对象类型。方法UIComponent#getAttributes()也暗示了更少或更多;它会返回Map<String, Object>,而不是Map<String, String>。我相信您的疑问是基于HTTP请求参数只能是字符串的事实。但不应将组件属性与HTTP请求参数混淆。

相关问题