我有一个带有验证器和命令按钮的文本框。当文本框验证失败时,我想禁用命令按钮,否则应该启用它。我不想使用任何代码隐藏,因此它应该在 bean 中没有任何辅助属性的情况下工作。
那么我如何根据验证器状态告诉命令按钮被禁用/启用?
<h:outputLabel for="category" value="#{msg['category.create']}"/>
<h:inputText id="category" required="true" label="#{msg['category.create']}" value="#{CreateCategoryBean.newCategory.name}" >
<f:validator validatorId="Get.Validator.CategoryValidator" />
<f:ajax event="keyup" render="categorymessage" />
</h:inputText>
<h:messages for="category" id="categorymessage"/>
<h:commandButton id="submit" value="#{msg['default.create']}" action="#{CreateCategoryBean.CreateCategory()}"
由于您已经<f:ajax event="keyup">
,让它更新<h:commandButton>
以及你反过来在其中disabled
属性检查是否UIComponent#isValid() http://docs.oracle.com/javaee/6/api/javax/faces/component/UIInput.html#isValid%28%29 of <h:inputText>
不回来false
.
<h:inputText binding="#{category}" ...>
<f:ajax ... render="categoryMessage submit" />
</h:inputText>
<h:commandButton id="submit" ... disabled="#{not category.valid}" />
不需要额外的 bean 属性。上面的代码是完整的。
也可以看看:
- JSF 中的“绑定”属性如何工作?何时以及如何使用它? https://stackoverflow.com/questions/14911158/how-binding-attribute-in-jsf-works
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)