struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Struts Newsgroup (@Basebeans.com) <str...@basebeans.com>
Subject What's a good practice to reuse formBeans with validation
Date Fri, 08 Mar 2002 02:10:01 GMT
Subject: What's a good practice to reuse formBeans with validation
From: "Tea Yu" <teayu@hknet.com>
 ===
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:struts-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:struts-user-help@jakarta.apache.org>


Mime
View raw message