0

I am trying to validate multiple components in a .xhtml in JSF2.2 I have written a custom validator for the same. I am calling the custom validator from a hidden field . The validator gets called but the message is not appearing on the screen. I have got a f:ajax call. I have included the message id in the ajax call too. But still the message does not appear on the screen. Can anyone please guide me on this. .. I am pasting the jsp and the validator class for reference.

The jsp is :-

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

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

and the custom validator class is :-

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));
}


}
}
  • The error which i get is :- [WARNING ] There are some unhandled FacesMessages, this means not every FacesMessage had a chance to be rendered. These unhandled FacesMessages are: - Please select a radio value – user5505256 Jun 20 '16 at 19:00
  • The message will be shown on the component associated with the validator. On a side node, even though I am deaf, in a future question please don't yell in the title. That's unprofessional. – BalusC Jun 20 '16 at 19:09
  • I have already associated a component to the validator but still the message is not appearing – user5505256 Jun 20 '16 at 19:26
  • You didn't associate the h:message with that component. – BalusC Jun 20 '16 at 20:21

0 Answers0