为每个设置h:selectOneMenu的值 [英] Setting value of a h:selectOneMenu from a for each

查看:83
本文介绍了为每个设置h:selectOneMenu的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是每个人都要迭代的产品列表,我需要在下面的下拉菜单中设置productGroupId.

This is the for each to iterate a list of products and I need to set the productGroupId in the drop down below.

 <c:forEach items="${productgroup.productList}" var="product">

 <h:selectOneMenu  value="${product.appleProdgroupId}">
<f:selectItems value="#{displayProductsBean.productGroupListDropDown}"/>
</h:selectOneMenu>

我已经尝试了所有组合,但无法正常工作...任何人都可以帮忙

I have tried all combination but it is not working ...can anyone please help

推荐答案

不清楚您对它不起作用"到底是什么意思.在到目前为止发布的代码中,我至少看到了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.

这篇关于为每个设置h:selectOneMenu的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆