Win a copy of Serverless Applications with Node.js this week in the NodeJS forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

Bean versus Form  RSS feed

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all
Is there any reason why I should use a bean to display a value in my JSP instead of getting the data from a form.
One of the reason could be
iterating through a collection of beans to display them in a table
is there any other reason
Thanx
Andr�
 
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the data is for diaplay only I don't see any reason not to use a bean. ActionForm objects map up to HTML forms, so if you're not using an html form you probably wouldn't need an ActionForm object.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
... but if I use a HTML form for modifying some data, is there a reason to bind this input fields to a bean.
Thanx
Andr�
 
Jason Menard
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are using an HTML form, then ideally you will also use an ActionForm bean in order to maintain the separation between the different MVC layers.
The ActionForm is a component of the View layer, whereas your data bean is the model. You generally don't want the View modifying the Model.
What I do, and I'm not sure if this is relevant to what you are trying to get at, is write convenience methods to move data back and forth between an ActionForm and a data bean.
As an example, let's say I am writing some kind of invoice application. I will write an Action class InvoiceAction, and add methods for maybe invoiceToForm and formToInvoice. I will use InvoiceAction as the super class for the rest of the actions which deal with the Invoice in the application. Maybe I have action classes ViewInvoiceAction extends InvoiceAction and UpdateInvoiceAction extends InvoiceAction. These Actions will call the methods to move your data back and forth.
On the other hand maybe I have a java bean called InvoiceReport which holds some basically static information pulled from the database, in this case some kind of report summarizing various invoices. If all the view is doing is displaying the info contained in the InvoiceReport, I would see no reason not to have it operate on the bean directly, displaying the beans contents directly to the jsp.
 
If I had asked people what they wanted, they would have said faster horses - Ford. Tiny ad:
global solutions you can do at home or in your backyard
https://www.kickstarter.com/projects/paulwheaton/better-world-boo
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!