I think a reusable design will make use of the Facade, Adapter, and Value Object design patterns.
A Facade is an easy-to-use API into a more complex API. I extend this to mean that even the data types are simple; primitives, Strings, and Lists in Java are the only inputs. The API we are talking about is your business logic, which is of course not within your Action/ActionForm objects themselves. This gets tricky when you've got an APi that requires 27 parameters. You want to have a simple way of building an object and passing it into your business model. Struts helps you do this by automatically populating your FormBean. If your FormBean actually uses the Adapter design pattern (mapping of one system to another), you can simply delegate property assignment to the real object your business model will use. You can simplify your business model by having your Facade take an input of a value object - a lightweight, properties-only object. If you're not famliar with design patterns, or even if you are and I'm not making sense because it's late on a Sunday, you'll probably benefit from an example. You'll need to put in your own proper formatting and validation, but it's a lot easier than I've probably made it sound. MyValueObject { int getAttr1(){return m_Attr1;} // return instance variable void setAttr1(int a_attr1){m_Attr1=a_attr1;} // set instance variable } MyFormBean { MyValueObject m_realObj; MyFormBean(){m_realObj = new MyValueObject();} String getAttr1(){ return new Integer(m_realObj.getAttr1()).toString();} void setAttr1(String a_attr1) { m_realObj.setAttr1(new Integer(a_attr1).intValue();}; ActionErrors validate() {//do validation here } // provide one extra method, not used by Struts,but rather used by // you in your Action process() method. } MyBusinessModel { MyValueObject m_valObj; MyBusinessModel(MyValueObject a_valObj){m_valObj = a_valObj;} String action1(){// use value object for data for processing } } Does this make any sense? I am suggesting that you use Strings or Lists in your Form Bean. Translate those to primitives inside a value object, and pass that value object off to the business model. --- [EMAIL PROTECTED] wrote: > Hi, > Some questions that have been in my mind after using Struts for a while. I am > still very confused as > the use of setter/getter in beans+struts environment. The setter and getter > are supposed to do > several things I think (from an OOP point of view): > > [1]setter - validate the input data, either reject it, or do some reformating > to get it to the format we > want > [2]getter - calculate values out of the private attributes if they are > needed. > > And almost 95% of the setters/getters that I code using the Struts Framework > as such as (as good > as a public attribute) : > > private String name; > > public String getName() { > return name; > } > > public void setName(String name) { > this.name = name; > } > > be it in the Bean (Business Level) or the Form Bean. Since I understand that > the PropertyUtils is > using the setters/getters to do the transfer between Bean<->Form Bean, we > have to provide all the > setter/getter functions for all the attributes. Okay, here's why I think > setter/getter should have no > use in Struts > > [1] setter - since this is the web front end, everything in the From is done > in one go, so that's why > we have a validate function instead of every setter having their own > validation function, so we > don't actually need any validation at all. If we are doing some internal > transformation to the values, > let say 400 degrees -> 40 degrees, it won't be something that the user wants > to see from the front > end, since he did enters 400 and it came out 40 the next time when he loads > it, the validate function > should took care of that and explains what's wrong with the value keyed in. > > [2] getter - it seemed that from the front end, every form input item wil be > an attribute, so there is not > much that we can do inside getter. > > Okay, let say I have a value that i want it to be an int (simple type) in the > Business Level Bean, how > would I transform this into String in the JSP?? The setter/getter of the > FormBean will have to be in > taking in and returning String. So not much choice actually in the FormBean. > Let's see, so if we > really want the value to be in int, the internal value wil be in int, and we > will want to use a > getter/setter as int values. But if we set the setter/getter to int values, > will the PropertyUtils do its job > in transforming the int value -> String values in the Form Bean? > > (what I did the work this around is to make another setter/getter pair, eg > int getAge(); String > getAgeStr(); void setAge(int age); void setAgeStr(String age); ) > > or worse? Use string all the way into the Bean itself? where we hold the > Buisness Level Logic?? > > Cheers, > Yee Keat > > __________________________________________________ Do You Yahoo!? Great stuff seeking new owners in Yahoo! Auctions! http://auctions.yahoo.com -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>