当两个必需的 selectOneMenu 组件没有空值时,我需要启用 commandButton
这是我的看法:
<p:selectOneMenu converter="omnifaces.SelectItemsConverter" id="countries" required="true" value="#{countryBean.selectedCountry}">
<f:selectItem itemLabel="#{msg['choose.option']}" />
<f:selectItems value="#{countryBean.countries}" var="country" itemLabel="#{country.name}" />
<f:ajax listener="#{countryBean.changeCountry}" render="cities" update="findPeopleButton" />
</p:selectOneMenu>
<p:selectOneMenu converter="omnifaces.SelectItemsConverter" id="cities" required="true" value="#{countryBean.city}">
<f:selectItem itemLabel="#{msg['choose.option']}" />
<f:selectItems value="#{countryBean.cities}" var="city" itemLabel="#{city.name}" />
<f:ajax listener="#{countryBean.verifyRequiredFields}" update="findPeopleButton" />
</p:selectOneMenu>
<p:commandButton icon="ui-icon-search"
disabled="#{countryBean.disablePeopleButton}"
id="findPeopleButton"
onclick="peopleDialog.show()" />
我在视图加载时禁用了该按钮,然后当我为每个 selectOneMenu 选择值时,该按钮启用,但之后当我设置某个 selectOneMenu 的空值时,我收到一条必需的验证错误消息,并且该按钮保持启用状态
这是我的支持 bean:
private Country country; // +getter+setter
private City city; // +getter+setter
private List<Country> countries; // +getter
private List<City> cities; // +getter
private boolean disablePeopleButton; // +getter+setter
@EJB
private CountryService countryService;
@PostConstruct
public void init() {
disablePeopleButton = true;
countries = countryService.getCountries();
}
public void changeCountry() {
cities = countryService.getCities(country);
}
public void verifyRequiredFields() {
if (country != null && city != null) {
disablePeopleButton = false;
} else {
disablePeopleButton = true;
}
}
我能做些什么来修复它?