且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为每个设置h:selectOneMenu的值

更新时间:2023-10-11 21:42:40

不清楚您对它不起作用"到底是什么意思.在到目前为止发布的代码中,我至少看到了3种可能的原因:

It's unclear what exactly you mean with "It is not working". In the code posted so far I see at least 3 possible causes:

您的第一个问题是,需要使用#{}语法而不是${}语法,以便能够自动创建托管bean(如果它们在范围内还不存在).

Your first problem is that you need to use #{} syntax instead of ${} syntax in order to be able to autocreate managed beans if they do not exist in the scope yet.

<c:forEach items="#{productgroup.productList}" var="product">
    <h:selectOneMenu value="#{product.appleProdgroupId}">
        <f:selectItems value="#{displayProductsBean.productGroupListDropDown}" />
    </h:selectOneMenu>
</c:forEach>

您的第二个问题可能是<c:forEach>,但这取决于运行此代码的上下文. <c:forEach>即是视图构建时间标签.如果上述方法无效,则需要<ui:repeat>.

Your second problem is potentially the <c:forEach>, but that depends on the context where this code is running. The <c:forEach> is namely a view build time tag. If the above doesn't work, you'd need <ui:repeat> instead.

<ui:repeat value="#{productgroup.productList}" var="product">
    <h:selectOneMenu value="#{product.appleProdgroupId}">
        <f:selectItems value="#{displayProductsBean.productGroupListDropDown}" />
    </h:selectOneMenu>
</ui:repeat>

如果仍然不起作用,则需要附加<h:messages/>来了解任何缺少的转换/验证错误.

If that still doesn't work, then you'd need to attach a <h:messages/> to learn about any missing conversion/validation errors.

<h:messages />

例如,您可以获取无效值"在表单提交请求期间未正确(预)初始化<f:selectItems>后面的列表时,发生验证错误.

You can for example get a "Value not valid" validation error when the list behind <f:selectItems> is not properly (pre)initialized during the form submit request.