There is one problem/issue with the EmployeeForm objects. It is likely
the attributes for EmployeeForm will have to be all Strings
after all.  The reason is as follows: Let's say you have a web form
where you enter new employee information. This form has a numeric
field. Let's say it's something like vacationDaysPerYear of type
Integer. If the user enters in a String into this field, the Struts
controller servlet (ActionServlet) will try to call the
SetVacationDaysPerYear(String) setter method. This method will
throw an exception, which will come back to the user as an ugly
exception stack trace(instead of a nice message saying 'The
number of vacation days must be a valid integer'.

One possible solution to this problem is to use Javascript to validate
the data types of data-entry fields right on the browser. Many don't
like this approach. Another possible solution is to make a custom
extension to the controller servlet that does something more user-
friendly when such an error occurs. Again, some would not like this
approach because they are reluctant to make modifications to framework
code. The last solution I can think of is to make all the attributes of
the bean Strings. Then you would allow the vacationDaysPerYear property
in the form bean to be populated by the controller servlet to, for
example, 'hello world'. In the bean's validate method, you would
check for data-type integrity. As far as the business/data code is
concerned, it should never use the get/setVacationDaysPerYear methods,
which operate only on Strings. This tier would always use the
get/setVacationDaysPerYearAsInteger methods. However, there is an
implicit assumption that the String which is used to store the data
behind the scenes has to be validated by the struts layer before it
ever gets to the business/data tier. Basically, part of your
EmployeeBean would look like the following in this way of doing
things...


public class EmployeeBean extends ActionForm {
    private String vacationDaysPerYear //really an integer

    public String getVacationDaysPerYear() {
      return vacationDaysPerYear;
    }

    public void setVacationDaysPerYear(String vacationDaysPerYear) {
      this.vacationDaysPerYear = vacationDaysPerYear;
    }

    public Integer getVacationDaysPerYearAsInt() {
      //stringToInteger is a utility method
      return stringToInteger(vacationDaysPerYear);
    }

    public void setVacationDaysPerYear(
        Integer vacationDaysPerYear) {
      //integerToString is a utility method
      this.vacationDaysPerYear =
        integerToString(vacationDaysPerYear);
    }

    public ActionError[] validate() {
      //check that vacationDaysPerYear is a valid Integer
    }
}

The data type integrity of the bean's non-string fields is
therefore a potential issue, since there are public methods
that allow this value to be set to any string, and it is
the programmers responsibility to make sure an invalid value
never stays there for long, and certainly never makes it
to the business/data tier. Sloppy programming can introduce
bugs, and the design itself may seem messy to someone who wants
very clear separation between presentation and business logic.

Depending on how you feel about this whole thing, you may decide
to keep your web-tier beans and your data/business beans
as separate entities. You should really think about what your
application's requirements are (now, and potentially
in the future) before you make a decision.

>From: Rick Reumann <[EMAIL PROTECTED]>
>Reply-To: Rick Reumann <[EMAIL PROTECTED]>
>To: "Vladimir Levin" <[EMAIL PROTECTED]>
>Subject: Re[2]: Does this tag exist & architecture [was] This hopefully is 
>a simple question that has been dealt with
>Date: Fri, 29 Mar 2002 23:41:40 -0500
>MIME-Version: 1.0
>Received: from [161.58.154.244] by hotmail.com (3.2) with ESMTP id 
>MHotMailBE6E8D0E00524004320EA13A9AF4ED370; Fri, 29 Mar 2002 20:41:51 -0800
>Received: from 653227hfc119.tampabay.rr.com (653227hfc119.tampabay.rr.com 
>[65.32.27.119]) by burridge.iserver.net (8.11.6) id g2U4fmX03029; Fri, 29 
>Mar 2002 23:41:48 -0500 (EST)
>From [EMAIL PROTECTED] Fri, 29 Mar 2002 20:43:41 -0800
>X-Mailer: The Bat! (v1.60) Personal
>X-Priority: 3 (Normal)
>Message-ID: <[EMAIL PROTECTED]>
>In-Reply-To: <[EMAIL PROTECTED]>
>References: <[EMAIL PROTECTED]>
>
>  Thanks Vladmir for your response. I agree with what you wrote. My
>  only question is even what you presented is still 3 tier is it not?
>  In other words having the form beans also with methods
>  "setXXXAsCalendar()" still allows for the 3 tiers (where for example
>  the db stuff would be done to populate the list with form beans). I
>  guess I'm confused a bit as what you are saying is the 'sexy'
>  approach in this example. In my other post I mentioned I was thinking
>  of having the following architecture. It looks like you are saying
>  (and I think I agree) that the business object below that converts
>  the EmployeeBean list to the list of EmployeeForm beans could be
>  combined into one business logic bean just using the EmployeeForm
>  beans with the accessor methods you mention (ie-
>  setBirthDateAsDate(), etc).
>
>BusinessDB Object I
>     - database query returns ArrayList of EmployeeBean objects (these
>       EmployeeBean objects have different datatype members other than
>       String).
>
>Business Object II  (thislayer probably could be removed and combined
>          into the one above if in the above form objects are used).
>     - makes call to above Buisness1 Object to get the ArrayList of
>       EmployeeBeans. Now iterates through this List and makes
>       a new ArrayList of EmployeeForm objects that have proper String
>       representations of the EmployeeBean datatypes (ie- birthDate
>       in 08/11/1969 format, double salary in currency format, etc).
>
>EmployeeAction Object (using EmployeeForm object )
>     - typical struts action. Makes call to above Business object to get
>       ArrayList of EmployeeForm objects and puts them into the request or
>       session
>
>JSP
>     use iterate tag and bean tag to display the EmployeeForm properties
>
>
>
>On Friday, March 29, 2002, 6:58:55 PM, Vladimir Levin wrote:
>
>VL> I would argue that it is quite easy to reuse your regular classes
>VL> as struts form  beans. This strategy may involve putting code into
>VL> your so-called 'business' classes who's purpose is to help with
>VL> certain kinds of 'presentation' level logic. The real question is,
>VL> do you want a 2-tier architecture or a 3-tier architecture? In the
>VL> two-tier approach, struts is both the business and presentation
>VL> tier (tier 1) and there is a data tier (tier 2) that handles the
>VL> communication with the database. In the 3-tier approach struts is
>VL> strictly a presentation layer that can be 'plugged into' any kind
>VL> of back-end business tier. So that's really the question. Do you
>VL> need the modularity of a 3-tier architecture(and are you willing
>VL> to pay the price for it)? This architecture is very popular these
>VL> days, but I contend that it is overkill for most real-world
>VL> projects. It is not hard at all to add methods to you so-called
>VL> business beans that support setXXX(String) and getXXX() : String,
>VL> and to modify your 'native' methods as per example
>VL> setXXXAsCalendar(Calendar) and getXXXAsCalendar() : Calendar.
>VL> Having done this sort of thing, your classes can be reused, and
>VL> you don't have to do all the extra shuffling. You may need to put
>VL> some discipline into your design so that the presentation aspects
>VL> and business-logic aspects are not confusing (especially if you
>VL> are re-using the bean classes in some other way that is not at all
>VL> struts-related). All in all, I think it is quite doable, and for
>VL> many projects is a perfectly reasonable approach (although perhaps
>VL> not as 'sexy').
>
>VL> Vlad
>
> >>From: Rick Reumann <[EMAIL PROTECTED]>
> >>Reply-To: Rick Reumann <[EMAIL PROTECTED]>
> >>To: "Maturo, Larry" <[EMAIL PROTECTED]>,   Struts Users 
>Mailing
> >>List <[EMAIL PROTECTED]>
> >>Subject: Does this tag exist & architecture  [was] This hopefully is a
> >>simple question that has been dealt with
> >>Date: Fri, 29 Mar 2002 12:05:14 -0500
> >>MIME-Version: 1.0
> >>Received: from [192.18.49.131] by hotmail.com (3.2) with ESMTP id
> >>MHotMailBE6DEB89002A4136E855C0123183D1B80; Fri, 29 Mar 2002 09:12:41 
>-0800
> >>Received: (qmail 15319 invoked by uid 97); 29 Mar 2002 17:05:26 -0000
> >>Received: (qmail 15308 invoked from network); 29 Mar 2002 17:05:25 -0000
> >>From struts-user-return-30889-aphelionx Fri, 29 Mar 2002 09:13:51 -0800
> >>Mailing-List: contact [EMAIL PROTECTED]; run by ezmlm
> >>Precedence: bulk
> >>List-Unsubscribe: <mailto:[EMAIL PROTECTED]>
> >>List-Subscribe: <mailto:[EMAIL PROTECTED]>
> >>List-Help: <mailto:[EMAIL PROTECTED]>
> >>List-Post: <mailto:[EMAIL PROTECTED]>
> >>List-Id: "Struts Users Mailing List" <struts-user.jakarta.apache.org>
> >>Delivered-To: mailing list [EMAIL PROTECTED]
> >>X-Mailer: The Bat! (v1.60) Personal
> >>X-Priority: 3 (Normal)
> >>Message-ID: <[EMAIL PROTECTED]>
> >>In-Reply-To: <47599681A9BA574FBCA93E884DD9114135C615@ZEUS>
> >>References: <47599681A9BA574FBCA93E884DD9114135C615@ZEUS>
> >>X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N
> >>
> >>On Friday, March 29, 2002, 11:19:25 AM, Maturo, Larry wrote:
> >>
> >>ML> We define a separate bean that mirrors our
> >>ML> EmployeeBean, but has string fields.  We then
> >>ML> get a list of EmployeeBeans and manually convert
> >>ML> them to a list of EmployeeStringBeans. :-)  It's
> >>ML> a pain, but it works.  Note that we only populate
> >>ML> the fields we actually plan on displaying, since
> >>ML> it is pointless to populate the other fields.
> >>
> >>     Thanks for your feedback Larry. (By the way nice job on that
> >>     AthensGroup paper on Struts if you wrote it).
> >>
> >>     Currently I already have an EmployeeForm bean (all String fields)
> >>     and an EmployeeBean (Strings, ints, etc.). The business tier does
> >>     the DB query and returns an ArrayList of EmployeeBeans. Now the
> >>     question becomes what next in order to iterate through this list
> >>     and display the EmployeeBean fields in a nice way (ie. proper date
> >>     format, currency format, etc.) ?...
> >>
> >>     I'm assuming from your reply that you might have extra logic
> >>     somewhere that will take that ArrayList of EmployeeBeans and loop
> >>     through the list and populate a new List of EmployeeForm beans. In
> >>     this step calls will be made to make sure the Strings in each
> >>     EmployeeForm object are correctly formatted. I see how this idea
> >>     will work, although it seems a shame that you have a perfectly
> >>     good ArrayList of Employee objects and now you are iterating
> >>     through it just to populate another ArrayList of Employee objects
> >>     with all String fields.
> >>
> >>     Before I looked into Struts I didn't see the big deal of iterating
> >>     though this list of regular EmployeeBean objects and then where
> >>     formatting was needed just call my helper util class to change the
> >>     format. For example:
> >>     <%= RickUtils.displayDateAsString( bean.getBirthDate() ) %>
> >>
> >>     I know, everyone says the above it bad because you now have
> >>     scriplets in your JSP code. Still, though, this seems to make more
> >>     sense to me than to going through the overhead of looping through
> >>     possibly a large ArrayList of beans in order to just populate a
> >>     similar ArrayList with just String fields. I suppose I will go
> >>     the later route in order to maintain the Struts architecture of
> >>     perfectly clean JSP pages.
> >>
> >>     Being new to struts and new to using tags, would it be that
> >>     difficult to create a tag that when passed a double it new to spit
> >>     out a display in some currency format or if it received a Date it
> >>     would display it in the proper format. I noticed there is a tag
> >>     library out there for display dates, but ideally I would like one
> >>     tag that would just pick up the datatype and "if datatype is
> >>     double" display this way, if Date display this way."
> >>
> >>     Does a tag library like the above already exist?
> >>
> >>     Thanks again for your feedback. I'm posting this to the list as
> >>     well for any other ideas.
> >>
> >>
> >>
> >>ML> There is a utility in Struts to help with this, but
> >>ML> I have never used it, since it always seemed like
> >>ML> learning to use it was more work than doing it
> >>ML> manually.
> >>
> >>ML> -- Larry Maturo
> >>ML>    [EMAIL PROTECTED]
> >>
> >>
> >>ML> -----Original Message-----
> >>ML> From: Rick Reumann [mailto:[EMAIL PROTECTED]]
> >>ML> Sent: Thursday, March 28, 2002 9:09 PM
> >>ML> To: Struts Users Mailing List
> >>ML> Subject: This hopefully is a simple question that has been dealt 
>with
> >>
> >>
> >>ML> Sorry to post this question again, but I'm still curious about this
> >>ML> ...
> >>
> >>ML> I'm sure this question has come up but I'm not having much luck
> >>ML> searching the archives. I'm really new to Struts so I hope this
> >>ML> question isn't too out of place for this list. Lets say we are 
>dealing
> >>ML> with Employee beans. I would my EmployeeBean to be able to have
> >>ML> members that are not all Strings. (In this example say Age would be 
>an
> >>ML> int, birthDate a java.util.Date, etc.). Now in the sample app I'm
> >>ML> developing I have an EmployeeForm class also that currently has just
> >>ML> String datatypes for these fields. Having the information from the
> >>ML> actual form jsp's going to the EmployeeForm in as all Strings 
>without
> >>ML> any conversions is not that big of a deal since wherever I do 
>anything
> >>ML> with this data (jdbc inserts in the business logic I could always
> >>ML> covert them there if I need to ). However, I'm more concerned with
> >>ML> getting this information displayed correctly using the iterate tag.
> >>ML> For example, say I have on an Action class that gets back and
> >>ML> ArrayList of EmployeeBean objects and puts this list into the 
>request
> >>ML> before forwarding. I really can't do:
> >>
> >>ML> <logic:iterate id="row" name="employeeList">
> >>ML>     <bean:write name="row" property="firstName"/><BR>
> >>ML>     <bean:write name="row" property="lastName"/><BR>
> >>ML>     <bean:write name="row" property="age"/><BR>
> >>ML>     <bean:write name="row" property="birthDate"/><BR>
> >>ML>     <BR>
> >>ML> </logic:iterate>
> >>
> >>ML> since I won't have birthDate formatted correctly, or say I was
> >>ML> returning a Double that I needed in a currency format. What is the
> >>ML> best way to deal with this situation? I could of course maybe have 
>my
> >>ML> business logic return me a Collection of EmployeeForm beans instead
> >>ML> and inside the EmployeeForm beans there would be methods like
> >>ML> setBirthDateDate( Date date ) that would take a java.util.Date and
> >>ML> format it into a String and then call the EmployeeForm setBrithDate(
> >>ML> String date ). Although that would work, I'd still rather deal with
> >>ML> the business logic that returns a Collection of EmployeeBeans... as
> >>ML> this seems to make the most reusable sense (maybe the components 
>later
> >>ML> won't just be for the web).
> >>
> >>ML> Thanks for any help.
> >>
> >>
> >>ML> --
> >>
> >>ML> Rick
> >>
> >>ML> mailto:[EMAIL PROTECTED]
> >>
> >>ML> "Why do people in ship mutinies always ask for 'better treatment'? 
>I'd
> >>ML> ask for a pinball machine, because with all that rocking back and
> >>ML> forth you'd probably be able to get a lot of free games."
> >>ML>   -Jack Handey
> >>
> >>
> >>ML> --
> >>ML> To unsubscribe, e-mail:
> >>ML> <mailto:[EMAIL PROTECTED]>
> >>ML> For additional commands, e-mail:
> >>ML> <mailto:[EMAIL PROTECTED]>
> >>
> >>
> >>
> >>
> >>--
> >>
> >>Rick
> >>
> >>mailto:[EMAIL PROTECTED]
> >>
> >>"Sometimes you have to be careful when selecting a new name for
> >>yourself. For instance, let's say you have chosen the nickname 'Fly
> >>Head. Normally you would think that 'fly Head' would mean a person who
> >>has beautiful swept-back features, as if flying through the air. But
> >>think again. Couldn't it also mean 'having a head like a fly'? I'm
> >>afraid some people might actually think that."
> >>   -Jack Handey
> >>
> >>
> >>--
> >>To unsubscribe, e-mail:
> >><mailto:[EMAIL PROTECTED]>
> >>For additional commands, e-mail:
> >><mailto:[EMAIL PROTECTED]>
> >>
>
>
>
>
>VL> _________________________________________________________________
>VL> MSN Photos is the easiest way to share and print your photos:
>VL> http://photos.msn.com/support/worldwide.aspx
>
>
>
>
>--
>
>Rick
>
>mailto:[EMAIL PROTECTED]
>
>"The face of a child can say it all, especially the mouth part of the
>face."
>   -Jack Handey
>




_________________________________________________________________
Join the world’s largest e-mail service with MSN Hotmail. 
http://www.hotmail.com


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

Reply via email to