【问题标题】:How can I retrieve the item that the user selected from the drop down? in jsf如何检索用户从下拉列表中选择的项目?在jsf中
【发布时间】:2011-12-08 12:58:06
【问题描述】:

我的问题是如何在 backing bean 中检索所选项目

在我的视图页面中,我有一个选择框组件:

<h:selectOneMenu id="materialCat" value="#
{materialMasterBean.materialDTOs.materialCategoryId}" required="true" requiredMessage="Material Category is Mandatory"> <f:selectItem itemLabel="select" itemValue="-1" /> <f:selectItems value="#{materialMasterBean.materialCatList}" />
</h:selectOneMenu>

这是我的后盾

` public ArrayList getMaterialCatList() { 如果(materialCatList == null) {

        materialCatList= new ArrayList<SelectItem>();
        ArrayList<MaterialDTO> temp;
        try {
                temp= getAdminDelegate().getMaterialLsit();
                for (int i = 0; i < temp.size(); i++)
                    {
                    MaterialDTO materialDTO = temp.get(i);
                        item = new SelectItem(materialDTO.getMaterialCategoryId(),materialDTO.getMaterialCategory());
                        materialCatList.add(item);
                    }
            } catch (Exception e) {
        // TODO Auto-generated catch block
                        e.printStackTrace();
                }

        return materialCatList;
    }
    else
    {
        return materialCatList;
    }

}

` 我也支持 Bean:

private MaterialDTO materialDTOs; 请帮帮我

【问题讨论】:

  • 到底是什么问题?您不能在操作方法中访问materialDTOs.getMaterialCategoryId() 吗? JSF 已经在那里设置了它。
  • 是的,对。这就是问题所在。
  • 为什么会有问题?究竟会发生什么?您描述的具体问题确实不清楚。
  • 呃,只是在您绑定到命令链接或按钮的操作方法中?您是否曾经阅读过一本不错的 JSF 书籍/教程的第 1 章?它与其他输入字段或其他内容没有什么不同。
  • 只需编辑这个问题并解释清楚。请尝试写正式的英语。不是每个人都能理解街头/幼稚的谈话,如“u”、“ur”等。

标签: jsf


【解决方案1】:

如果你用value="#{bean.filed}属性绑定它,你可以在你的bean中访问它

编辑:here 是一个关于如何做选择框的例子,我认为你误解了一些事情。您想在列表中选择一个MaterialDTO 对象吗?还是身份证?您不需要带有SelectItem 的 ArrayList ...

【讨论】:

  • 我试过了,但它给出了 javax.el.PropertyNotWritableException 错误:/pages/MaterialMasterl.xhtml @45,73 binding="materialMasterBean.materialCode": Illegal Syntax for Set Operation
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-11-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多