开发者

Does f:attribute support other things than String?

I have the need to implement an ice:commandButton that passes a list to its backing bean. I'm not in a portlet scope, but in a tag scope.

I know that when I retrieve an f:attribute from the actionListener I get an 开发者_如何学Cobject that has to be casted.

I want to know if I can map f:attribute to a List<MyClass>, where the actual instance of the list is actually an ArrayList and MyClass is serializable.

Something like:

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");
    }

Do you think this is feasible? Thanks


The <f:attribute> gives you the possibility to add custom component attributes. They will be stored in the component tree state in the server side. So it can be any Java object type you want. The method UIComponent#getAttributes() also hints that less or more; it returns a Map<String, Object>, not a Map<String, String>. I believe your doubt is based on the fact that HTTP request parameters can only be strings. But component attributes should not be confused with HTTP request parameters.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜