2

I'm using primefaces with jsf and i want to make one of two fields required at least. that means that the error message will be displayed if this two fields are empties togheter: this is a sample of my code:

<h:outputLabel for="srcNumber" value="Originator MSISDN (EXAMPLE 32495959595)" />
<p:inputText id="srcNumber" value="#{cdrMmscRecBean.srcNumber}" label="srcNumber" />
<h:outputLabel for="destNumber" value="Destination MSISDN (EXAMPLE 32495959595)" />
<p:inputText id="destNumber" value="#{cdrMmscRecBean.destNumber} label="destNumber" />

thanks :)

Med
  • 35
  • 1
  • 6

2 Answers2

4

You can implement it this way:

<p:inputText id="srcNumber" value="#{cdrMmscRecBean.srcNumber}" label="srcNumber" 
     required="#{empty cdrMmscRecBean.destNumber}" requiredMessage="SRC Number Required">
    <p:ajax event="change" update="destNumber" />
</p:inputText>

<p:inputText id="destNumber" value="#{cdrMmscRecBean.destNumber}" label="destNumber"
     required="#{empty cdrMmscRecBean.srcNumber}" requiredMessage="DEST Number Required">
    <p:ajax event="change" update="srcNumber" />
</p:inputText>

For more reference on how to parametrize your validation message:

Qussay Najjar
  • 561
  • 3
  • 7
0

If you want to show the validation error use <p:message for="srcNumber" /> and same for test number, get rid of your outputLabels, this will show the validations warnings.

You neeed to add the required="true" flag to your inputTexts as well.

This is primefaces

EDIT Purpose of the h:outputLabel and its "for" attribute this here shows the outputLabel for using non primefaces to show validatoin messages if this is all your problem was then u just need to add the required="true" validation flag indicators on your input texts

Community
  • 1
  • 1
VeenarM
  • 1,263
  • 1
  • 10
  • 14
  • thanks VeenarM, the "output label" is here just for displying labels for each field not for displaing error message. my principal issue is how to display the error message just when the field are empties at the same time. – Med Apr 10 '14 at 07:52
  • just use the p:message , it only renders the messages in faces validaiton message. You need to submit your form to generate the render of those messages or as Qussay has mentioned if u attach an ajax evnt listener to it then you can have it being dynamic. – VeenarM Apr 10 '14 at 09:12