我在Primefaces 5.3中使用JSF,并且在启用/禁用命令按钮时遇到问题。
首先,我有这个输入:
<h:inputText id="series" value="#{bean.series}"
required="false" converterMessage="Please enter three digits" >
<f:validateRegex pattern="[0-9]{3}" />
<p:ajax event="keyup" update="download"/>
</h:inputText>
在后备 Bean 中,此字段是整数
private Integer series;
我的目标是在输入不为空时启用/禁用"下载"按钮。我不在乎它是否无效,但只在它不包含字符的情况下。
<h:commandButton id="download" value="Download"
action="#{bean.download}"
disabled="#{empty bean.series}"/>
更新事件在 keyup 上触发,但由于验证,后备 Bean 中的属性 'series' 始终为 null。
你能帮我一个解决方案吗? 谢谢
首先让我声明该要求是不合逻辑的,因为如果值无效,则无法(至少在代码中没有其他更改的情况下(通过按钮提交表单。
但是,如果您真的想要这样做,请使用在验证失败/时禁用/启用h:commandButton中所做的操作/也可以
<h:inputText id="series" value="#{bean.series}"
required="false" converterMessage="Please enter three digits" binding="#{series}">
<f:validateRegex pattern="[0-9]{3}" />
<p:ajax event="keyup" update="download"/>
</h:inputText>
<h:commandButton id="download" value="Download"
action="#{bean.download}"
disabled="#{ ... EL using 'empty bean.series' and 'series.valid' ..." />
EL 必须由您定义,因为您最清楚空/不空和有效/无效的哪些组合应该禁用按钮