Subject: Re: What's a good practice to reuse formBeans with validation
From: "Pim" <[EMAIL PROTECTED]>
 ===
Hi Tea,

We've been struggeling with the same question for the last few days, but
before I continue, use the stuts (David Winterfeldt) validator, it's
awesome.

What we wanted was exactly the same as you: insert, update, delete,
different actions with different validations. If I want different
validations I want different formbeans (formbean for insert, one for update
and one for delete). The problem is that the html form section (<html:form
action = "youraction">)can only contain one action and so you can only go to
one formbean. If this form has multiple buttons then what do you do?

There are several solutions described in this userlist (look for the word
multiple in this list and look for multiple at jguru) Most of them come down
to skipping the validation at the formbean but validate at the action class.
If you submit the html form, set a hidden field with the action you want to
perform (insert, update etc) In the action class get the hidden field and
based on that, do your stuff.

The area we haven't checked is the area of using hyperlinks instead of
submit buttons, so the solution might be there.

We still haven't quite figured out how to solve the problem, we've got a few
solutions figured out but they need to be tested, so I can't give you a
clear answer.

Good luck!

Pim

"Tea Yu" <[EMAIL PROTECTED]> wrote in message
news:a6965u$kr8$[EMAIL PROTECTED]...
> Hi, consider the following scenario:
>
> a countryForm bean contains properties "id" and "name"
> actions to 1) insert, 2) update and 3) delete countries (not likely to
> happen except to remove wrong/test inputs)
>
> if I allow my users to delete a country by id (maybe a hyperlink), then I
> suppose the name field will be null.  How should I handle such a basic
> validation in countryForm as name shouldn't be null in case 1) and 2) but
> could be null in case 3)?  The same question applies to id field in case
> 1).
>
> Is this a business logic and not to be handled in form bean?  Thus only
> test if id is an integer:
>
> if(id != null){
>     try{
>         Integer.parseInt(id)
>     }catch(NumberFormatException nfe){
>         //chain up errors
>     }
> }
>
>
> in the actionForm:
>
> if("Delete".equals(mapping.getParameter())
>     //test id==null
>
>
> or should I turn to struts validator (which I guess rules could be
> included in the form)?  or to use 3 different formBeans?  |o|
>
> Nice day!
> Tea Yu
>
>



--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to