jsr372-experts@javaserverfaces-spec-public.java.net

[jsr372-experts] Re: Concerns about validateWholeBean

From: Michael Müller <michael.mueller_at_mueller-bruehl.de>
Date: Mon, 8 Feb 2016 17:06:30 +0100

Hi Manfred,

Because I have some input fields nested in the f:ajax, every input
triggers the partial request. Every field would be single validated.
Can't we trigger the group validation (I prefer this to a whole bean
validation) by the way?

Or, if sombody likes to trigger the group validation independent from
the single field trigger, then we need to define a special trigger
condition. It shall not be triggered on submit of the form - this seems
to be much too late. And not by hitting any button. Just when the user
performed some input.

Maybe
<f:validationGroup group="..." trigger="...."/>
A trigger condition might be "fieldA not empty and fieldB not empty"...

To me, triggering the group validation togehter with the user input
(ajaxified field) would fit.

To my example: I just ried to wrap the whole thing into an f:ajax. Sine
rendering tho whole div will destroy the focus, I prefer to ajaxify each
single field:

<h:message for="ageValidator"/>
<h:inputText id="ageDays" value="#{grouper.ageDays}">
   <f:validateBean id="ageValidator"
validationGroups="javax.validation.groups.Default,de.muellerbruehl.jsf23.Age"/>
   <f:ajax render="msgAgeDays ageValidator"
validate="de.muellerbruehl.jsf23.Age"/>
</h:inputText>
<h:message id="msgAgeDays" for="ageDays"/>

<h:inputText id="ageYears" value="#{grouper.ageYears}">
   <f:validateBean
validationGroups="javax.validation.groups.Default,de.muellerbruehl.jsf23.Age"/>
   <f:ajax render="msgAgeYears ageValidator"
validate="de.muellerbruehl.jsf23.Age"/>
</h:inputText>
<h:message id="msgAgeYears" for="ageYears"/>

And writing down this example, I got the idea to add a validate
attribute to the f:ajax. This way, the JSF user might trigger the multi
field validation on his preferred place.

Herzliche Grüße - Best Regards,

Michael Müller
Brühl, Germany
blog.mueller-bruehl.de <http://blog.mueller-bruehl.de/>
it-rezension.de <http://it-rezension.de/>
@muellermi


Read my books
"Web Development with Java and JSF": https://leanpub.com/jsf
"Java Lambdas und (parallel) Streams" Deutsche Ausgabe:
https://leanpub.com/lambdas-de
"Java Lambdas and (parallel) Streams" English edition:
https://leanpub.com/lambdas

Am 08.02.2016 um 16:43 schrieb manfred riem:
> Hi Michael,
>
> If you are using f:ajax you need to make sure you submit something.
> You cannot just have f:ajax do a re-render.
>
> Thanks!
>
> Kind regards,
> Manfred Riem
>
> On 2/7/16, 6:58 AM, Michael Müller wrote:
>> Hi experts,
>>
>> In a real worl application hospitals and people of the healthcare
>> sector have to report comprehensiove information to a central
>> institute. For each domain the user might fullfill a form - from a
>> handfull of input fields up to a tabbed page with several hundresds
>> of fields or lists. Usuall it takes some time to fullfill such a
>> form. Thus, the user may store the data at any time and continue
>> after a break. Once he has finished, he "sends" the data to the
>> institute.
>>
>> Some requirements:
>> - provide the user straight feedback
>> - offer or hide conditional fields depending on the previous user input
>> - check the input, thus it is compatible to the database at any time
>> - check the whole form whnen the user clicks onto the send button
>>
>> I made some tests, how to solve this with our new multi field
>> validation.
>>
>> Provide straight feedback and store at any time needs to use ajax:
>> Every single field is pushed into the model to store an intermediate
>> version.
>>
>> And to provide straight feedback on conditional fields or interacting
>> fields requires an immediate multi field validation. It seems (unless
>> I did not understand it right), that we can't use validateWholeBean
>> for this. As the name states, it validates the whole bean and not a
>> single group. As a workarround I split the data and used multiple
>> backing beans for a single form. I tried to validate just after the
>> input using ajax. Sadly, validateWholeBeans became active only after
>> clicking the submit button.
>>
>> Here an excerpt of the form:
>>
>> <div jsf:id="age">
>> <f:ajax render="age">
>> <h:message for="ageValidator"/>
>> <h:inputText id="ageDays" value="#{grouper.ageDays}">
>> <f:validateBean id="ageValidator"
>> validationGroups="javax.validation.groups.Default,de.muellerbruehl.jsf23.Age"/>
>> </h:inputText>
>> <h:message for="ageDays"/>
>>
>> <h:inputText id="ageYears" value="#{grouper.ageYears}">
>> <f:validateBean
>> validationGroups="javax.validation.groups.Default,de.muellerbruehl.jsf23.Age"/>
>> </h:inputText>
>> <h:message for="ageYears"/>
>> <f:validateWholeBean value="#{grouper}"
>> validationGroups="de.muellerbruehl.jsf23.Age" id="ageValidator"/>
>> </f:ajax>
>> </div>
>>
>> <div jsf:id="email">
>> <f:ajax render="emailValidator">
>> <h:message for="ageValidator"/>
>> <h:inputText value="#{emailBean.email1}">
>> <f:validateBean
>> validationGroups="javax.validation.groups.Default,de.muellerbruehl.jsf23.Email"/>
>> </h:inputText>
>>
>> <h:inputText value="#{emailBean.email2}">
>> <f:validateBean
>> validationGroups="javax.validation.groups.Default,de.muellerbruehl.jsf23.Email"/>
>> </h:inputText>
>>
>> <f:validateWholeBean value="#{emailBean}"
>> validationGroups="de.muellerbruehl.jsf23.Email" id="emailValidator"/>
>> </f:ajax>
>> </div>
>>
>> <h:commandButton value="submit"/>
>>
>> No matter, whether I include the f:validateWholeBean into the f:ajax,
>> it it validated on submit only.
>>
>> I propose to enhance the multi field validation:
>>
>> - let the user define a couple of multi field validation
>> (f:validateWholeBean or a new tag like f:validateGroup)
>> - if a single field of this group is validated, validate the whole
>> group too (no matter whether the validateWholeBean is place into a
>> f:ajax)
>>
>> or
>> - add an attribute validateGroup="someGroup" to the f:validateBean
>> tag, e.g.
>> <f:validateBean
>> validationGroups="javax.validation.groups.Default,de.muellerbruehl.jsf23.Email"
>> validateGroup="de.muellerbruehl.jsf23.Email"/>
>> - on a partial request (in case of ajax), if validateGroup is
>> declared, create a temp. copy of the bean and perform a group
>> validation for the declared group.
>>
>> What do you think about this?
>>
>>
>> --
>>
>> Herzliche Grüße - Best Regards,
>>
>> Michael Müller
>> Brühl, Germany
>> blog.mueller-bruehl.de <http://blog.mueller-bruehl.de/>
>> it-rezension.de <http://it-rezension.de/>
>> @muellermi
>>
>>
>> Read my books
>> "Web Development with Java and JSF": https://leanpub.com/jsf
>> "Java Lambdas und (parallel) Streams" Deutsche Ausgabe:
>> https://leanpub.com/lambdas-de
>> "Java Lambdas and (parallel) Streams" English edition:
>> https://leanpub.com/lambdas
>>
>