【问题标题】:how to obtain selected values from a rich:orderingList?如何从 Rich:orderingList 中获取选定的值?
【发布时间】:2012-05-17 22:26:51
【问题描述】:

我正在使用 Richfaces 4,并尝试在 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 backing bean中的函数,我从这里改编自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方法。

【问题讨论】:

    标签: jsf-2 richfaces


    【解决方案1】:

    几个问题以便更好地理解您的问题。

    目的是什么:

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

    为什么要在每次点击时呈现 orderingList,因为它假设只有在点击“删除”按钮时才会被修改?

    为什么会这样:

    selection="${selectionBean.selectedCategories}"
    

    以“$”符号而不是“#”开头? (不应阻塞)。

    最后,我在组件上找不到“选择”属性。见VDL。你确定语法吗?

    问候

    【讨论】:

    • 1.你是对的,渲染不是必需的,但我认为它不会改变问题。 2. 糟糕,打错了,应该是“#” 3. 至少在 3.3 中,“selection”属性就在那里,如下所示:docs.jboss.org/richfaces/latest_3_3_X/en/devguide/html/…。也许他们将它用于第 4 版,尽管我认为它应该在两个版本之间保持不变:community.jboss.org/wiki/…
    • 我认为从 3.3 到 4.x 的“选择”属性确实被删除了。所以最好的方法是在 RichFaces JIRA 上创建一个问题,并要求对 rich:orderingList 组件进行增强,以便再次支持“选择”。不要犹豫,在创建问题后发布链接,以便人们投票。
    • 我在迁移到richfaces 4.x后也遇到了这个问题,希望得到任何解决方案...
    • 我找不到任何 JIRA 条目,所以我创建了一个:RF-13662。请为它投票!
    猜你喜欢
    • 2018-02-28
    • 2021-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-15
    • 2011-11-27
    • 2023-03-26
    • 2011-04-06
    相关资源
    最近更新 更多