Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Validation primefaces选项卡视图在选项卡更改时跳过表单验证_Validation_Jsf 2_Primefaces_Onchange_Tabview - Fatal编程技术网

Validation primefaces选项卡视图在选项卡更改时跳过表单验证

Validation primefaces选项卡视图在选项卡更改时跳过表单验证,validation,jsf-2,primefaces,onchange,tabview,Validation,Jsf 2,Primefaces,Onchange,Tabview,我使用的是PrimeFaces3.3和Mojarra 2.17 我有一个包含p:tabView的页面。第二个选项卡包含一个文本框和required=“true”。当我从第二个选项卡导航到第一个选项卡时,它将验证文本框是否为空并显示错误消息(我有一个PhaseListener类在全局p:messages中显示错误)。如何跳过此验证 我在以下方面找不到任何解决方案: 我不想使用PrimeFacesp:wizard My tabView.xhtml: <p:tabView id="tab

我使用的是PrimeFaces3.3和Mojarra 2.17

我有一个包含
p:tabView
的页面。第二个选项卡包含一个文本框和
required=“true”
。当我从第二个选项卡导航到第一个选项卡时,它将验证文本框是否为空并显示错误消息(我有一个
PhaseListener
类在全局
p:messages
中显示错误)。如何跳过此验证

我在以下方面找不到任何解决方案:

我不想使用PrimeFaces
p:wizard

My tabView.xhtml:

<p:tabView id="tabView" dynamic="true" cache="false" activeIndex="0" >  
      <p:ajax event="tabChange" listener="#{test.onTabChange}"/> 
      <p:tab id="tab1" title="Tab1">
        <ui:include src="#{test.tab1}"></ui:include>
      </p:tab>
      <p:tab id="tab2" title="Tab2">  
        <ui:include src="#{test.tab2}"></ui:include>
      </p:tab>
</p:tabView>
My tab1.xhtml:

<h:form id="form1">    
    <p:messages globalOnly="true" />
    tab1 page
    <br/>
</h:form>
在ajax事件标记中添加
immediate=“true”
属性。这将阻止验证您的字段,只调用您的侦听器:

<p:ajax event="tabChange" listener="#{test.onTabChange}" immediate="true"/>

我通过添加代码解决了问题:
FacesContext.getCurrentInstance().renderResponse()
在backign bean中的TabChangeEvent方法下

例如:


错误消息只是停留在以前的提交中,还是在ju更改选项卡时显示?请尝试在
p:ajax
中添加
process=“@none”
。如果添加process=“@none”,则选项卡更改不起作用。如果process=“@this”,错误仍然存在。我认为问题更多地取决于tabView如何处理选项卡更改<代码>只需列出,不需要管理当前设置中的选项卡更改,您没有那么多选项。您可以做的一件事是使用EL使
required
属性有条件expression@kolossus,你能再解释一下吗?我当前的设置还需要什么选项?以及如何使用EL表达式使所需的属性有条件?
<h:form id="form2">
    <p:messages globalOnly="true" />
    <p>
        tab2 page
    </p>
    <p:inputText id="txt1" required="true" />
    <p:message for="txt1" display="text" />
    <p:commandButton value="Submit" update="@form" />
</h:form>
public class MyPhaseListener implements PhaseListener {
    @Override
    public void afterPhase(PhaseEvent e) {
        if (e.getPhaseId() == PhaseId.PROCESS_VALIDATIONS) {
            if (FacesContext.getCurrentInstance().getMessageList().size() > 0) {
                String number = String.valueOf(FacesContext.getCurrentInstance().getMessageList().size());
                String errorMsg = "there are " + number + " errors.";
                FacesContext.getCurrentInstance().addMessage(
                        null,
                        new FacesMessage(FacesMessage.SEVERITY_ERROR, errorMsg,
                                errorMsg));
            }
        }
    }
}
<p:ajax event="tabChange" listener="#{test.onTabChange}" immediate="true"/>
public void onTabChange(TabChangeEvent event) {              
  this.setTab1("tab1.xhtml");
  this.setTab2("tab2.xhtml");
  FacesContext.getCurrentInstance().renderResponse();
}