转义具有必填字段的primefaces/jsf页面 [英] Escape a primefaces/jsf page that has required fields

查看:93
本文介绍了转义具有必填字段的primefaces/jsf页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个jsf页面,

<h:inputText required="true">属性. 当我单击添加按钮时,如果该字段为空白,我想看到一个错误.

<h:inputText required="true"> attribute. When I click on my add button, I want to see an error if the field is blank.

我有一个<f:message>来显示它.

但是我如何才能转义(取消)该字段为空白的页面?就我而言,它会不断发布错误消息,并且我必须在该字段中输入一些内容才能转到另一页.

But how can I escape (cancel) the page with that field blank? In my case it continually posts the error message and I have to enter something in the field to go to another page.

推荐答案

如果您的取消按钮是 POST 请求,例如<p:commandButton><h:commandButton><p:commandLink><h:commandLink>

If your cancel button is a POST requests e.g. <p:commandButton>,<h:commandButton>, <p:commandLink>, or <h:commandLink>

您可以将取消按钮放在具有 <h:inputText> 的表单之外,以便不提交表单

You can put your cancel button outside the form that has the <h:inputText> so that form is not submitted

<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>.


If you are navigating without any actions or method invocation, then you can use GET requests e.g. <h:button>, <p:button>, <h:link> or <h:outputLink>.

示例:

 <h:form>
    <h:inputText value="#{bean.string}" required="true"/>
    <p:button value="Cancel" outcome="anotherpage.xhtml"/>
 </h:form>

这篇关于转义具有必填字段的primefaces/jsf页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆