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�
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.
posted 16 years ago
... 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�
posted 16 years ago
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