• 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

Using Form Beans (from Struts) for Display in JSP

 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm starting work on a new project that has well into construction. As I'm looking through the code base, I'm trying to take in the existing design so that I can more thoroughly understand the application. I've run across a practice that I'm not so sure I agree with and I wanted to bounce it off some other folks that may have had more experience with Struts and JSP's. (By the way, if this is more of a Struts question than a JSP question, feel free to move this post.)

When using Struts, all of the form parameters are encapsulated in a Form Bean (an object that extends ActionForm). In general, my concept of a Form Bean was to encapsulate the form data and do validation on that data. In addition, the Form Bean serves a wonderful purpose when the user enters an error. In that case, it's common that execution will be sent back to the same screen the user was just on but it will display an error message so that the user can correct what was wrong and resubmit the form. You can then use the Form Bean to repopulate the form (with the data the user had previously submitted), like this:



However, in this new application, I'm finding that the Form Bean is also being used to encapsulate model information.

For example, a call is made to a database to retrieve a list of locations. Then, in order to get that information to the view, the list is put into the Form Bean. Then, from the JSP, you can do something like this (note that the locations are put into the Form Bean under the member name "siteNames"):



This works, but it feels wrong to me. Am I just naive to the way Struts is supposed to work (this is my first full-fledged Struts app I've worked with)? I would have thought the model information would have been put into some other Java object (probably a Java Bean) and that object would have been explicity put into the request for JSP access.

I guess I'm just not sure if I'm comfortable with Form Beans being used in this way. Any comments?

Edited by Corey McGlone: Turned off smilies to keep them from interfering with my jsp tags.
[ October 28, 2004: Message edited by: Corey McGlone ]
 
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with you. This seems to be placing responsibilities on an ActionForm that it really shouldn't have. I would have just set the list of site names to the request, or as an attribute of some JavaBean which I made available in the request. I don't see how it belongs in any way in the ActionForm.
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Corey,
I agree with Jason. But from what I've read about JSF, it looks like they encourage everything to be thrown in one bean/form type class. And I have coworkers who feel the same way as yours do. So I think both ways are valid.
 
Ranch Hand
Posts: 995
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I should start by saying: I am not experienced in Struts ... and than continue. Starting with the name ActionForm I would say that everything that exists inside a class extending ActionForm would be according to it (meaning it would manipulate/validate the form data and perform the corresponding action => submitting). But for the submitting/retrieving data I would rather use something like Transaction Script pattern

my max 2c
./pope
 
reply
    Bookmark Topic Watch Topic
  • New Topic