简体   繁体   English

如何在selectItems中使用selectOneMenu和object

[英]how to use selectOneMenu with object in selectItems

I don`t understand how to use ArrayList of objects in f:selectitems. 我不明白如何在f:selectitems中使用对象的ArrayList I use composite components and code below is not work: 我使用复合组件,下面的代码不起作用:

<h:selectOneMenu id="kladrRegion-dctKladrRegion" 
                                     tabindex="100"
                                     value="#{cc.attrs.kladrRegion}"
                                     styleClass="comboBox ui-corner-all   inputText ui-inputfield kladrSearchFormInput kladrSearchFormSelectWidth selectHight"  
                                     style="font-size: 13px; width: 300px;"
                                     binding="#{cc.attrs.cbKladrRegion}" >
                        <f:selectItems value="#{cc.attrs.kladrRegions}" var="region" 
                                       itemLabel="#{region.value}" itemValue="#{region.id}" />                                
                        <f:ajax  
                            listener="#{cc.attrs.kladrRegionChange}" />
                    </h:selectOneMenu>

This code does not work, because the attribute var receive a new value after adding a second composite component. 此代码不起作用,因为属性var在添加第二个复合组件后会收到新值。 In the previous composite components selectOneMenu will not be displayed. 在之前的复合组件中,将不会显示selectOneMenu How to make a drop-down list in this case? 在这种情况下如何制作一个下拉列表?

I found solution of my problem. 我找到了解决问题的方法。 Follow to this post: JSF 2 composites and binding for validation 关注这篇文章: JSF 2复合和绑定验证

SelectOneMenu needs to have "binding" attribute with unique value. SelectOneMenu需要具有唯一值的“绑定”属性。 After adding second composite component Error <f:ajax> contains an unknown id 添加第二个复合组件后,错误<f:ajax>包含未知的ID

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM