JSF2.2多字段验证消息未显示..消息与组件相关联

时间:2016-06-20 18:58:41

标签: jsf-2 jsf-2.2

我正在尝试验证JSF2.2中的.xhtml中的多个组件 我为此编写了一个自定义验证器。我从隐藏字段调用自定义验证器。调用验证器,但消息未出现在屏幕上。我有一个f:ajax电话。我也在ajax调用中包含了消息id。但是消息仍然没有出现在屏幕上。任何人都可以指导我这个。 ..我正在粘贴jsp和验证器类以供参考。

jsp是: -

<f:loadBundle basename="com.pMAT.resources.ApplicationResources" var="msgs"/>
<h:head>
<h:outputStylesheet library="css" name="pMAT.css"  />
<h:outputScript library="js" name="lib/jquery-2.2.4.min.js"></h:outputScript>
<h:outputScript library="js" name="pMATJS.js"></h:outputScript>
</h:head>
<h:body styleClass="bodystyle">

<h:form id="pmatsummcashflowform">
<div style="width:100%;">  <!-- Main Div -->
<!-- <table width="100%">
<tr>
<td width="15%"> -->

<div class="searchCriteria">
<div>
<div>
<div class="searchElements">

<h:outputLabel styleClass="searchCriteriaLabel" value="#{msgs.summarizedCashFlowLabel}"></h:outputLabel> 
<h:inputHidden>
<f:validator validatorId="multipleValidator" />
</h:inputHidden>
<h:message id="accportmessage" for="summcashflowradio" style="color: red"/>

<div  id="radiobuttondiv" class="radioCriteria">
<!-- <h:panelGroup id="radiobuttondiv" styleClass="radioCriteria">  -->

<h:selectOneRadio  id="summcashflowradio" enabledClass="accountNo" binding="#{PMATSummarizedCashFlow.summCashFlow}" value="#{PMATSummarizedCashFlow.summCashFlow}" layout="pageDirection">
<f:selectItem itemValue="ACCT" itemLabel="#{msgs.accountNo}" id="Radio1"/>
<f:selectItem itemValue="PORT" itemLabel="#{msgs.portfolioId}" id="Radio2"/>
<!--  <f:validator validatorId="multipleValidator" /> -->
</h:selectOneRadio>

</div>

<h:commandButton  id="cashflowretrieve" type="submit" styleClass="button b-dark-blue submitButton" value="#{msgs.submit}" action="#{PMATSummarizedCashFlow.submitCashFlow}">
<f:ajax execute="pmatsummcashflowform" render="accportmessage textSearch datatablegroup"></f:ajax>
</h:commandButton> 

<div class="searchElementsTextBox">
<h:inputText styleClass="txtSearchElementsAccount" id="txtSearchElementsAccount" value="#{PMATSummarizedCashFlow.accountElement}">
</h:inputText>

<h:inputText styleClass="txtSearchElementsPortfolio" id="txtSearchElementsPortfolio" value="#{PMATSummarizedCashFlow.accountPortfolio}">
</h:inputText>
</div>

</div>

</div>

<!-- Set Div As your requirement -->
</div>
</div>
<!--  </td>
</tr>
<tr>
<td width="85%"> -->
<div class="hidefilterdiv">
<h:commandButton id="hidefilter" value="Hide Filters"></h:commandButton>
</div>
<div class="searchResults">
<div class="innerResultCashSumm">
<div>
<h:panelGrid id="textSearch" style="width:100%">
</h:panelGrid>
</div>

<div id="cashSumm" class="CashsummdataTable">
<h:panelGrid id="datatablegroup">
<h:panelGroup>
<h:dataTable value="#{pMATSummarizedCashFlowResults.summarizeCashFlow}" rendered="#{PMATSummarizedCashFlow.tbRender=='true'}" var="o">
<h:column>
<!-- column header -->
<f:facet name="header"><h:outputLabel value="Portfolio ID" styleClass="cashsummtableheader"></h:outputLabel></f:facet>
<!-- row record -->
#{o.portfolio_id}
</h:column>
<h:column footerClass="cashsummTable">
<!-- column header -->
<f:facet name="header"><h:outputLabel value="Account Number" styleClass="cashsummtableheader"></h:outputLabel></f:facet>
<!-- row record -->
#{o.account_number}
</h:column>
</h:dataTable>
</h:panelGroup>
</h:panelGrid>
</div>

</div> 
</h:form>
</h:body>

=================

,自定义验证器类是: -

import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

@FacesValidator("multipleValidator")
public class MultipleValidator implements Validator{

@Override
public void validate(FacesContext context, UIComponent component, Object obj) {

System.out.println("IN MULTIPLE VALIDATOR");
Object inputBeforeValidatorSub = ((UIInput) context.getViewRoot().findComponent("pmatsummcashflowform:txtSearchElementsAccount")).getSubmittedValue();

Object inputBeforeValidatorSub1 = ((UIInput) context.getViewRoot().findComponent("pmatsummcashflowform:txtSearchElementsPortfolio")).getSubmittedValue();

Object inputsummCashFlow = ((UIInput) context.getViewRoot().findComponent("pmatsummcashflowform:summcashflowradio")).getSubmittedValue();


System.out.println("IN MULTIPLE VALIDATOR RADIO value"+inputsummCashFlow);
if (inputsummCashFlow == null || ("").equals(inputsummCashFlow) ) { //|| !inputAfterValidatorSub.equals("")) {
throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Please select a radio value", null));
}


//Object inputAfterValidatorSub = ((UIInput) context.getViewRoot().findComponent("multipleInputForm:inputAfterValidator")).getSubmittedValue();
System.out.println("IN MULTIPLE VALIDATOR value"+inputBeforeValidatorSub);
if (inputBeforeValidatorSub == null || ("").equals(inputBeforeValidatorSub) ) { //|| !inputAfterValidatorSub.equals("")) {
throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Missing account Number", null));
}

System.out.println("IN MULTIPLE VALIDATOR1 value"+inputBeforeValidatorSub1);
if (inputBeforeValidatorSub1 == null || ("").equals(inputBeforeValidatorSub1)) { //|| !inputAfterValidatorSub.equals("")) {
throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Missing portfolio number", null));
}


}
}

0 个答案:

没有答案