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

[jsr372-experts] Re: Concerns about validateWholeBean

From: manfred riem <manfred.riem_at_oracle.com>
Date: Mon, 08 Feb 2016 09:43:53 -0600

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
>