• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)
     
    Sheriff
    Posts: 67746
    173
    Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    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 ]
     
    JD Glanville
    Greenhorn
    Posts: 22
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    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
    Sheriff
    Posts: 67746
    173
    Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
     
    Don't get me started about those stupid light bulbs.
    reply
      Bookmark Topic Watch Topic
    • New Topic