2011-07-08 46 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

完美的澄清問題。所以屬性**被存儲在服務器端 –

相關問題