jQuery in Action, 2nd edition*
The moose likes JSF and the fly likes Validation Problem ... again! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Validation Problem ... again!" Watch "Validation Problem ... again!" New topic
Author

Validation Problem ... again!

Tommaso Tama
Greenhorn

Joined: Oct 13, 2010
Posts: 11
Dear all,

this problem is driving me crazy ...

Well, I have a page with many information.
The user has to provide free text (such as surname and name) or he has to choose from a pop up.



Pressing the ? button (Job Type) a rich modal panel with a table will be displayed (the ? is a custom component).
The value of the first column of the table is a link (ajax link). Clicking the link, a value of a backing bean will be updated and the job type input text will be reRendered.

The same for Sport.

All the fields in the page are required.
Let's submit the form without filling the whole form (for example, sport)




Let's fill now the missing value fot Sport. It works!
But if a try to change the value of Job Type, well, IT DOES NOT WORK. Only the label is updated (MARITTIMO PASSEGGERI, in this case) but the input text holds the old value.
The set method of the backing bean is not triggered.



I tried many ways, none worked (immediate=true, force the process of the input text).
Is there a way to bypass this behaviour?

In other words, if the form has a validation problem, I cannot change anymore the backing bean values with an HtmlCommandLink.

Can you help me? I can post the source code.

Please, I'm running in circle in vain ...

Many thanks,
Tom


Max Katz
Ranch Hand

Joined: Aug 03, 2009
Posts: 72
Why do you say it's a validation problem? It looks like all your fields are filled in, you are just trying to change the job title value, correct?
Tommaso Tama
Greenhorn

Joined: Oct 13, 2010
Posts: 11
Max Katz wrote:Why do you say it's a validation problem? It looks like all your fields are filled in, you are just trying to change the job title value, correct?


The problem appears after submitting an incomplete form (if you forget to fill a required field).
After this, I cannot change the value of the field JOB. The backing bean is not updated, the set method is not triggered.

I will try to explain better.
All the fields are required (attribute required = true set)
Suppose that we have 3 fields: surname, job, sport.
Surname is free text. Job and sport are linked to two backing bean properties (bJob, bSport)
The ? shows a modal panel with a table. The first column has an ajax link that updates the backing bean property and that reRenders the related input text.

CASE 1
----------
FIELD FILLED
----------------------------
SURNAME Y
JOB Y
SPORT N


Perform the submit.
FacesMessage appears: sport is a mandatory field.
Press ? near sport. The popup appears. Choose a value. Sport is correctly updated.
Then I want to change job value. Press ? near job. The popup appears. Choose a value. Job is NOT updated.


CASE 2
----------
FIELD FILLED
----------------------------
SURNAME N
JOB Y
SPORT Y


Perform the submit.
FacesMessage appears: surname is a mandatory field.
Fill surname.
Press ? near sport. The popup appears. Choose a value. Sport is NOT updated.
Then I want to change job value. Press ? near job. The popup appears. Choose a value. Job is NOT updated.

The problem is that after a submit of an incomplete form, my ajax call can update ONLY field that are incomplete. I cannot change the value of filled field with my ajax call.

Many thanks!
Max Katz
Ranch Hand

Joined: Aug 03, 2009
Posts: 72
Got it. Please post page code.
Tommaso Tama
Greenhorn

Joined: Oct 13, 2010
Posts: 11
Ok, here you are the core problem.

The page. I have two required "input text".
A command button that changes the bean value and reRenderes the "job" object.



Here the simple manager:



Let's do this:

Write something on the Job input text (such as "teacher").
Leave empty the surname.
Save.
Validation error appears (surname is mandatory).
Press "Set job to Programmer": nothing happens.

Checking the bean value, I discovered that it is correctly updated, indeed the component on the page is not updated!

Well, according to the JBoss Docs I found:

Ajax region is a key ajax component. It limits the part of the component tree to be processed on the server side when ajax request comes. Processing means invocation during Decode, Validation and Model Update phase. Most common reasons to use a region are:

-avoiding the aborting of the JSF lifecycle processing during the validation of other form input unnecessary for given ajax request;
-defining the different strategies when events will be delivered (immediate="true/false")
-showing an individual indicator of an ajax status
-increasing the performance of the rendering processing (selfRendered="true/false", renderRegionOnly="true/false")

The following two examples show the situation when a validation error does not allow to process an ajax input. Type the name. The outputText component should reappear after you. However, in the first case, this activity will be aborted because of the other field with required="true". You will see only the error message while the "Job" field is empty.


Here you are the example:


Form1: the behaviour is incorrect. I need to fill the job and then the name.
Form2: the behaviour is correct. I do not need to fill the job to see the correct value.

Unfortunately using Ajax region does not help (indeed I used it in a bad way ...) because my fields are both REQUIRED. That's the main different.

Any idea?

Many thanks.




Tommaso Tama
Greenhorn

Joined: Oct 13, 2010
Posts: 11
Checking the bean value, I discovered that it is correctly updated, indeed the component on the page is not updated!


So, how to force jsf to update the JOB input text component?
 
 
subject: Validation Problem ... again!