multiple warning messages for a required field

UI Components for JSF
burakh79
Posts: 80
Joined: 17 Apr 2014, 10:22

28 Oct 2014, 12:47

Hi,
How can I display for some conditions like if the field is empty and if it is not empty and the value on it exists on a list, I built the conditions with if statements and used

Code: Select all

FacesContext.getCurrentInstance().addMessage(
					null,
					new FacesMessage(FacesMessage.SEVERITY_ERROR, null,
							"Required field !!!"));

Code: Select all

FacesContext.getCurrentInstance().addMessage(
					null,
					new FacesMessage(FacesMessage.SEVERITY_ERROR, null,
							"Same number exists on the list !!!"));
but I couldn't make it work, I used p:messages and p:message
Primefaces 5.0
JSF 2.0
Eclipse Kepler
Apache Tomcat 7.0
Mozilla Firefox 30.0

tandraschko
PrimeFaces Core Developer
Posts: 3979
Joined: 03 Dec 2010, 14:11
Location: Bavaria, DE
Contact:

28 Oct 2014, 14:00

you must update the p:messages tag.
Thomas Andraschko

PrimeFaces | PrimeFaces Extensions

Apache Member | OpenWebBeans, DeltaSpike, MyFaces, BVal, TomEE

Sponsor me: https://github.com/sponsors/tandraschko
Blog: http://tandraschko.blogspot.de/
Twitter: https://twitter.com/TAndraschko

burakh79
Posts: 80
Joined: 17 Apr 2014, 10:22

28 Oct 2014, 14:13

I wrote autoUpdate="true" but again same problem

Code: Select all

<h:outputText value="TC Kimlik * :" />
					<p:inputText id="tcidno2" value="#{KisiInfoProcess.tcidnok}" 
					  required="true" requiredMessage="Required field !!!" label="TC Kimlik" />
					
					<p:messages for="tcidno2" display="text" id="messages" showDetail="true" autoUpdate="true" closable="false" />
Primefaces 5.0
JSF 2.0
Eclipse Kepler
Apache Tomcat 7.0
Mozilla Firefox 30.0

tandraschko
PrimeFaces Core Developer
Posts: 3979
Joined: 03 Dec 2010, 14:11
Location: Bavaria, DE
Contact:

28 Oct 2014, 14:36

Then i don't understand your problem.
If you add FacesMessages via code and update p:messages, it works for sure.
You should start debugging your code.
Thomas Andraschko

PrimeFaces | PrimeFaces Extensions

Apache Member | OpenWebBeans, DeltaSpike, MyFaces, BVal, TomEE

Sponsor me: https://github.com/sponsors/tandraschko
Blog: http://tandraschko.blogspot.de/
Twitter: https://twitter.com/TAndraschko

burakh79
Posts: 80
Joined: 17 Apr 2014, 10:22

30 Oct 2014, 17:03

I put rendered to two p:message then set true false using conditions to display the message but again it didn't work, I think there is no flexibility in primeface when showing two messages for an inputtext.

Code: Select all

<p:message for="tcidno2" id="messages111" autoUpdate="true" rendered="#{KisiInfoProcess.uyarimesaji}"/>
<p:message for="tcidno2" id="messages222" autoUpdate="true" rendered="#{KisiInfoProcess.gereklialan}"/>

Code: Select all

				FacesContext.getCurrentInstance().addMessage(
						"tcidno2",
						new FacesMessage(FacesMessage.SEVERITY_WARN, "Uyarı!",
								"Aynı TC Kimlik no ile kayıt yapamazsınız."));

			FacesContext.getCurrentInstance().addMessage(
					"tcidno2",
					new FacesMessage(FacesMessage.SEVERITY_ERROR, "Zorunlu alan!",
							"Zorunlu alan !!!"));
On the link below also there is no example for having two warning messages for a required field
One with manage bean executing method of facescontext and p:messages for complete warning message for four inputtexts and p:message for one inputtext
http://www.primefaces.org/showcase/ui/m ... ages.xhtml
Primefaces 5.0
JSF 2.0
Eclipse Kepler
Apache Tomcat 7.0
Mozilla Firefox 30.0

User avatar
andyba
Expert Member
Posts: 2473
Joined: 31 Mar 2011, 16:27
Location: Steinfeld, near Bremen/Osnabrück, DE
Contact:

30 Oct 2014, 18:33

Why do it that way, simply use one FacesMessage and add all the text you want to it.
PF 4.x (Elite versions), PF 5, Pf 5.1, PF 6.0
Glassfish 4.1, Mojarra 2.x, Java 8, Payara 4.1.1.
If you haven't read the forum rules read them now

burakh79
Posts: 80
Joined: 17 Apr 2014, 10:22

30 Oct 2014, 18:40

Because if the field is empty there will be message saying "required filed !!!" then if the field is not empty and the value in it is exist in the database table field then it will say "there is an existing element in the database"
Primefaces 5.0
JSF 2.0
Eclipse Kepler
Apache Tomcat 7.0
Mozilla Firefox 30.0

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

31 Oct 2014, 12:11

afaics, you can still do that with one p:message...

burakh79
Posts: 80
Joined: 17 Apr 2014, 10:22

31 Oct 2014, 13:23

I tried all the options to make it happen
Can you give sample code showing how to do that ?
Primefaces 5.0
JSF 2.0
Eclipse Kepler
Apache Tomcat 7.0
Mozilla Firefox 30.0

User avatar
andyba
Expert Member
Posts: 2473
Joined: 31 Mar 2011, 16:27
Location: Steinfeld, near Bremen/Osnabrück, DE
Contact:

31 Oct 2014, 13:43

You only need 1 p:message for each validated input field. IIRC validation fails fast for each field. This means that the first validation to fail produces a message which will be displayed in the p:message component and no further validation will be attempted for that field.
If you are using a Validator then you are required to throw a ValidationException with the validation error message in it. As you can only do this once it tends to support my supposition above. Validator message generated like this are routed to the associated p:message component for you.
PF 4.x (Elite versions), PF 5, Pf 5.1, PF 6.0
Glassfish 4.1, Mojarra 2.x, Java 8, Payara 4.1.1.
If you haven't read the forum rules read them now

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 52 guests