2012-05-09 59 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组件进行增强,以便再次支持“选择”。不要犹豫,在创建后发布一个链接,以便人们投票。 –

相关问题