首页 > 解决方案 > h:selectOneMenu 在 Myfaces 从 1.1.4 升级到 1.1.8 后不起作用

问题描述

我正在使用 JSF 1 并尝试将 Myfaces 版本从 1.1.4 更新到 1.1.8 我在 myxhtml 页面中有类似的内容,

<h:selectOneMenu id="orgCountry"  value="#{crud.orgAddress.country}
<f:selectItem itemLabel="#{messageResources.dropDownPleaseSelect}" itemValue=""/>
<f:selectItem itemLabel="#{crud.usrbld.countryName}" itemValue="#{crud.usrbld.countryId}"/>
<f:selectItems value="#{getSelectItems('countryDAOCrud')}"/>
<a4j:support id="countryDropDown" event="onchange" ajaxSingle="true" reRender="orgState" oncomplete="updateStateDropdown()"/>

</h:selectOneMenu>

getselectItems 是一个普通的方法,

getselectItems (){
 list= gettingfromDB
 converting into selectItem type

country 是一个普通的 pojo 类,带有 hash 和 equals 方法

使用 Myfaces 1.1.4 时,一切正常,但升级到 Myfaces 1.1.8 时,我的提交失败,这是由于验证错误,即 ParametrizableFacesMessage "{0}": Value is not a valid option .
此错误的原因是 _SelectItemUtil 中的 matchvalue 方法,即,

Object itemValue = item.getValue();
                if (value==itemValue || (itemValue.equals(value)))
                {
                    return true;
                }   

所以这里的值是从下拉列表中选择的值,itemValue 是 SelectItem 的项目之一(这是在迭代器循环中),这里的值是我的类类型,itemValue 是字符串,因为它们从不匹配验证总是失败。而在 Myfaces 1.1.4 中, itemValue 被转换为类对象类型,因此比较返回成功。我将无法升级 JSF 版本。任何人都可以帮我解决这个问题。在此先感谢。

标签: myfaces

解决方案


我不得不覆盖jar方法来解决这个问题


推荐阅读