GeeCON Prague 2014*
The moose likes JSP and the fly likes java bean vs. taglib: who should do the work? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Bookmark "java bean vs. taglib: who should do the work?" Watch "java bean vs. taglib: who should do the work?" New topic
Author

java bean vs. taglib: who should do the work?

JD Glanville
Greenhorn

Joined: Sep 16, 2002
Posts: 22
I’m using a three-page process in my web application to deal with data input:
  • first page is the form
  • second page is the processing of the form and performing the associated actions
  • third page is the success/fail feedback page
  • My question is concerning the second page of this process: form processing and action.
    What is the best way to process a form and act on its information? There are several ways that I can do this work: through java beans, EJB, taglib, etc, but what’s the best way?
    Java Bean:
    For example, I could do it through a java bean. If I had a form with two text entry fields, something like this:

    and a java bean that looked something like this:

    then my form processing page could look something like this:

    TagLib using property names:
    I could also do the work through a tag library, passing the names of the form’s fields to the tag’s attributes. Thus, my second page would look something like this:

    In this example, the tag library would retrieve the values of the named properties from the request object and perform the required actions.
    TagLib using property values:
    Another possibility is to use a tag library, passing the values of the form’s fields to the tag’s attributes. Thus, my second page would look something like this:

    Here, the tag processPerson would then use the values passed directly to it and perform the required actions.
    TagLib in conjunction with a java bean:
    One final possibility is to use a java bean to get the form’s values, and to use a tag lib to process the work. Here, I’d be separating the two tasks of form processing and work to two separate objects. Thus, my second page would look something like this:

    Here, the "person" bean would populate itself based on the form, and then the "processPerson" would get that bean from the request object and perform the work using that bean as data.

    So what’s the best way to perform this very common action? I’m slightly preferential to a java bean as it’s reusable in a non-web situation whereas tag libraries are designed for web use only.
    What are your thoughts and why?
    (ps: please excuse my formatting, I'm playing around with the UBB code)
    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 61315
        
      66

    So what�s the best way to perform this very common action?

    In a servlet.
    What are your thoughts and why?

    JSP is intended for serving as a page template. Taglibs, JSP bean tags, and the like are meant as "display helpers", not processing engines. The type of processing you are trying to accomplish needs none of this mechanism or overhead, and a simple servlet (a la Model 2 architecture) is best suited for the purpose.
    hth,
    bear
    [ May 06, 2003: Message edited by: Bear Bibeault ]

    [Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
    JD Glanville
    Greenhorn

    Joined: Sep 16, 2002
    Posts: 22
    Originally posted by Bear Bibeault:

    JSP is intended for serving as a page template. Taglibs, JSP bean tags, and the like are meant as "display helpers", not processing engines. The type of processing you are trying to accomplish needs none of this mechanism or overhead, and a simple servlet (a la Model 2 architecture) is best suited for the purpose.
    hth,
    bear
    [ May 06, 2003: Message edited by: Bear Bibeault ]

    Would you also do the data-retrieval from the form using a servlet, or would you use some of the convenience methods of Java Beans to harvest the data first?
    JDG
    PS: Thanks for the suggestion. Appreciated!
    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 61315
        
      66

    You could probably get a lot of differing opinions, but for me, I use servlets for all "active" processing, beans as "value objects" only (data holding -- perhaps "smart" data, but no processing other than to represent the data appropriately), and JSP as views (again, no processing except that needed to support the display -- and making heavy use of taglibs as appropriate).
    To me, this utilizes the features of each of these mechanisms to their best advantage.
    hth,
    bear
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: java bean vs. taglib: who should do the work?