2012-05-09 56 views
2

我正在使用Richfaces 4,並嘗試獲取rich:orderingList中的選定項目。我想要這些,以便我可以通過按下「刪除」按鈕將它們從列表中刪除。所以對我有這樣的:如何從rich:orderingList中獲取選定值?

<rich:orderingList id="categoriesList" listHeight="100px" 
    listWidth="300px" value="#{selectionBean.availableCategories}" 
    selection="${selectionBean.selectedCategories}" 
    valueChangeListener="#{selectionBean.takeSelection}" > 
    <a4j:ajax event="click" render="categoriesList" execute="@this" /> 
</rich:orderingList> 

而在@ViewScoped支持豆的功能,這是我改編自這裏https://community.jboss.org/message/561295

private List<String> availableCategories; 

private List<String> selectedCategories; 

............................... 

public void takeSelection(AjaxBehaviorEvent event) { 
    System.out.println("ABE In takeSelection..."); 

    System.out.println(" Trying to find component with offering elements..."); 
    UIComponent component = event.getComponent(); 
    System.out.println(" Found: " + (component == null ? "<null>" : (component.getClass().getName() + " - " + component.getId()))); 
    if(component != null) { 
     System.out.println(" Component that fired the event: " + component.getClass().getSimpleName() + " - " + component.getId()); 
     UIOrderingList orderingList = (UIOrderingList) component; 

     System.out.println(" selectedCategories are "+ selectedCategories); 
    } 
    System.out.println(type + " Leaving takeSelection"); 
} 

的問題是,當我點擊列表中選擇一個項目,儘管我看到發送了Ajax請求,但未更新selectedCategories列表,也未調用takeSelection方法。

回答

0

有幾個問題才能更好地理解你的問題。

什麼目的:

<a4j:ajax event="click" render="categoriesList" execute="@this" /> 

爲什麼呈現在每個點擊,因爲它假設orderingList僅被修改的「刪除」按鈕,點擊的時候?

爲什麼:

selection="${selectionBean.selectedCategories}" 

開始以 「$」 符號,而不是一個 「#」? (不應該被阻止)。

最後,我無法在組件上找到「選擇」屬性。見VDL。你確定語法嗎?

Regards

+0

嗨,謝謝你的回答/問題。 – yorick456

+0

1.你說得對,渲染沒有必要,但我認爲它不會改變問題。 2.糟糕,這是一個錯字,應該是「#」 3.「選擇」屬性在那裏,至少在3.3,如下所示:http://docs.jboss.org/richfaces/latest_3_3_X/ EN/devguide/HTML/rich_orderingList.html#d0e38485。也許他們拿出了第4版,儘管我認爲它應該在兩個版本之間保持不變:https://community.jboss.org/wiki/RichFacesMigrationGuide33x-4xMigration-ComponentsMigration-RichInputComponents – yorick456

+2

我認爲「選擇」屬性已經真正從3.3到4.x中刪除了。所以最好的方法是在RichFaces JIRA上創建一個問題,並要求對rich:orderingList組件進行增強,以便再次支持「選擇」。不要猶豫,在創建後發佈一個鏈接,以便人們投票。 –

相關問題