[英]Escape a primefaces/jsf page that has required fields
我有一个jsf页面
<h:inputText required="true">
属性。 当我单击添加按钮时,如果该字段为空白,我想看到一个错误。
我有一个<f:message>
来显示它。
但是,我如何才能转义(取消)该字段为空白的页面? 就我而言,它会不断发布错误消息,并且我必须在该字段中输入内容才能转到另一页。
如果您的取消按钮是POST请求,例如<p:commandButton>
, <h:commandButton>
, <p:commandLink>
或<h:commandLink>
您可以将取消按钮放在具有<h:inputText>
的表单之外,以便不提交表单
<h:form>
<h:inputText value="#{bean.string}" required="true"/>
</h:form>
<h:form>
<p:commandButton value="Cancel" action="anotherpage.xhtml"/>
</h:form>
如果导航时没有任何操作或方法调用,则可以使用GET请求,例如<h:button>
, <p:button>
, <h:link>
或<h:outputLink>
。
例:
<h:form>
<h:inputText value="#{bean.string}" required="true"/>
<p:button value="Cancel" outcome="anotherpage.xhtml"/>
</h:form>
您可以在<p:commandButton>
使用immediate="true"
。 然后它将跳过验证。
例如:
<p:commandButton action="#{managedBean.action}" value="Cancel" immediate="true" />
如果您想取消或浏览,请不要在提交时处理表单。
即不要
<h:form>
...
<p:commandButton value="Cancel" action="#{bean.cancel}" />
</h:form>
但是就做
<h:form>
...
<p:commandButton value="Cancel" action="#{bean.cancel}" process="@this" />
</h:form>
或者,如果您还是只在cancel()
方法中返回导航结果,那就更好了
<h:form>
...
<p:button value="Cancel" outcome="otherpage.xhtml" />
</h:form>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.