2011-07-08 44 views
0

我需要实现一个将列表传递给其后备bean的ice:commandButton。我不在portlet范围内,但在标记范围内。f:属性是否支持String以外的其他东西?

我知道当我从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"); 
    } 

您认为这样可行吗?谢谢

+0

它应该只是工作。你面临的问题是什么?这个问题并不清楚。 – BalusC

+0

没问题。在进行此操作之前,我还有其他任务需要执行。 **如果我用按钮触击了**,发现这种方式不可行,那么我肯定会大幅回滚。我期望在下周一进入按钮的事情 –

回答

0

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

+0

完美的澄清问题。所以属性**被存储在服务器端 –

相关问题