components lose functionality after page fails validation

UI Components for JSF
Post Reply
trud9340
Posts: 17
Joined: 29 Oct 2014, 21:29

29 Oct 2014, 21:35

I am brand new to PF so bear with me.
I created a form with a few fields on it, including a p:calendar. All fields are required.
When the page first loads, the p:calendar works fine, but if I force the required validation to fail by leaving a field blank, the calendar popup stops working. I also tried this with a p:inputMask with the same results (after failed validation, the mask stops working and it just becomes a normal input field).

JSF 2, PF 5.1, Tomcat 7

Code: Select all

<?xml version="1.0"?>

<f:view xmlns="http://www.w3.org/1999/xhtml"
	xmlns:c="http://java.sun.com/jsp/jstl/core"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.org/ui"
	xmlns:ui="http://java.sun.com/jsf/facelets">
	<h:head />
	<h:body>
		<h:form prependId="false" id="createDisputeForm">
			<h:panelGroup id="pgroup">

				<table>
					<tr>
						<td><p:outputLabel value="Health Plan:" /></td>
						<td><p:inputText id="healthPlanName"
								value="#{CreateDisputeBean.healthPlanName}" required="true"
								requiredMessage="Required" /></td>
						<td><p:message for="healthPlanName" /></td>
					</tr>

					<tr>
						<td><p:outputLabel value="Provider:" /></td>
						<td><p:inputText id="providerName"
								value="#{CreateDisputeBean.providerName}" required="true"
								requiredMessage="Required" /></td>
						<td><p:message for="providerName" /></td>
					</tr>

					<tr>
						<td><p:outputLabel value="Patient Name:" /></td>
						<td><p:inputText id="patientName"
								value="#{CreateDisputeBean.patientName}" required="true"
								requiredMessage="Required" /></td>
						<td><p:message for="patientName" /></td>
					</tr>

					<tr>
						<td><p:outputLabel value="Patient ID Number:" /></td>
						<td><p:inputText id="patientIdNumber"
								value="#{CreateDisputeBean.patientIdNumber}" required="true"
								requiredMessage="Required" /></td>
						<td><p:message for="patientIdNumber" /></td>
					</tr>

					<tr>
						<td><p:outputLabel value="Date of Service(MM/DD/YYYY):" /></td>
						<td><p:inputMask id="dateOfService" mask="99/99/9999"
								required="true" requiredMessage="Required"
								value="#{CreateDisputeBean.dateOfService}" /></td>
						<td><p:message for="dateOfService" /></td>
					</tr>
				</table>
				<p:commandButton value="Submit" update="@form" process="@form"
					action="#{CreateDisputeBean.submit}" />
			</h:panelGroup>
		</h:form>
	</h:body>
</f:view>

Mathieu-Castets
Posts: 45
Joined: 03 Jul 2014, 19:04
Location: Biarritz, France

30 Oct 2014, 17:30

You should try to remove process="@form" from your commandButton
PrimeFaces 5.3 - PF Extensions 4.0.0 - OmniFaces 2.2 - Mojara 2.2.12 - GlassFish 4.1.1 - Java 7 - Netbeans 8.1

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

The process="@form" attribute is harmless, it is actually the default.
I don't see the update attribute being a cause but you never know. You shouldn't need to if you are using p:message tags for the individual input fields, these are automatically updated.
Where you could have problems is with the action attribute. The action attribute expects an EL expression that is evaluated to a String result. This result is the navigation case which tells JSF which page to display next. If the navigation case is null or matches the current one then the view is refreshed otherwise the appropriate page is sent in response.
If the method you call in the EL expression does not have a signature of String methodName(void) (ie a method which returns a String and takes no parameters) then odd things can happen.

Another thing: the default ajax mode for a commandButton is that the form is submitted using an AJAX request. In this case it is better to use an actionListener to trigger if you don't need to navigate to another page. Even then it is better to use an actionListener to do the save and action to navigate.
The evaluation order is SUBMIT -> Validation -> evaluate actionListener -> evaluate action and navigate. If the Validation phase fails the actionListener and action are not evaluated.

A tip for the OP: check for server side stack traces and JavaScript errors in your page.
Another tip: include both xhtml and bean code snippets as this makes helping you easier for us.
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

trud9340
Posts: 17
Joined: 29 Oct 2014, 21:29

30 Oct 2014, 22:06

andyba wrote:The process="@form" attribute is harmless, it is actually the default.
I don't see the update attribute being a cause but you never know. You shouldn't need to if you are using p:message tags for the individual input fields, these are automatically updated.
Where you could have problems is with the action attribute. The action attribute expects an EL expression that is evaluated to a String result. This result is the navigation case which tells JSF which page to display next. If the navigation case is null or matches the current one then the view is refreshed otherwise the appropriate page is sent in response.
If the method you call in the EL expression does not have a signature of String methodName(void) (ie a method which returns a String and takes no parameters) then odd things can happen.

Another thing: the default ajax mode for a commandButton is that the form is submitted using an AJAX request. In this case it is better to use an actionListener to trigger if you don't need to navigate to another page. Even then it is better to use an actionListener to do the save and action to navigate.
The evaluation order is SUBMIT -> Validation -> evaluate actionListener -> evaluate action and navigate. If the Validation phase fails the actionListener and action are not evaluated.

A tip for the OP: check for server side stack traces and JavaScript errors in your page.
Another tip: include both xhtml and bean code snippets as this makes helping you easier for us.
There are no server or javascript errors showing up. The only thing I can see are the phases being spit out by the debugphaselistener.

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

One thing, your xhtml header is wrong, you have no doctype.
For example

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
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

trud9340
Posts: 17
Joined: 29 Oct 2014, 21:29

03 Nov 2014, 21:53

andyba wrote:One thing, your xhtml header is wrong, you have no doctype.
For example

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
I updated my header to match what you posted but it had not change on the behavior.
Could this be an issue with the push server? Do I need to include a push server in my lib folder?

I also was able to gather some more information regarding the behavior. If I initialize the calendar field with a date, the issue goes away. It's only when the value is initialized to null or cleared out before the form is submitted that the calendar popup stops functioning. This same behavior even happens with a simple radio button - if it is set to required, and it is left unselected, it becomes disable on the subsequent form refresh (following failed validation).

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

04 Nov 2014, 13:03

Didn't see any code in your sample that requires Server Push but I may have missed it.
You may want to check to see if your web app handles nulls as empty Strings, Google for that for the solution.
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

trud9340
Posts: 17
Joined: 29 Oct 2014, 21:29

04 Nov 2014, 22:30

andyba wrote:Didn't see any code in your sample that requires Server Push but I may have missed it.
You may want to check to see if your web app handles nulls as empty Strings, Google for that for the solution.
The solution was to change my bean to View scope (it was set to request). Thank you for your time!

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

05 Nov 2014, 00:41

Next time please post a full but minimal example... so 100% running code and xhtml but stripped of all non-relevant pieces...

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 22 guests