Re: logic:iterate tag and form beans

2005-08-02 Thread Laurie Harper

Brian Kremmin wrote:

I want to get some table data from a database and output it in table
form on a webpage.

I'm planning to use an ArrayList to store the data and use the
logic:iterate tag to expose the elements of the list... however, I'm
unsure of the proper structure of all these data objects.  I think I'm
using struts 1.1 if that makes a difference.

I'm assuming I'll create a form bean with an ArrayList as a property..
is this correct?  However, I'm unsure of what sort of objects to put
into the array list.  Do I create another form bean with properties for
each table column, populate a new bean for each row of table data, and
put each into the ArrayList?  Or should the objects in the Arraylist be
something other than a form bean?


If you just need to display the data, you don't need FormBeans or anything 
else Struts-specific. Use whatever data structures make sense to your 
application and pass them to your view (JSP), as others have posted here.


If you need to let the user edit and re-submit the data, validate it, 
re-display it, etc. then you will want to start using FormBeans and the 
rest of the Struts machinery to manage that.


For output-only data, you just need to expose the model (whatever form you 
choose for that). Struts is model-agnostic.



I'm looking for the 'best' and 'proper" practice as our standards group
is very picky.  Any ideas?


If you need to satisfy a picky standards group maybe you should ask what 
*they* consider to be the 'correct' way to do this in your organization :-)


L.
--
Laurie, Open Source advocate, Java geek and novice blogger:
http://www.holoweb.net/laurie


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: logic:iterate tag and form beans

2005-08-02 Thread Dave Newton

Brian Kremmin wrote:


I'm planning to use an ArrayList to store the data and use the
logic:iterate tag to expose the elements of the list... however, I'm
unsure of the proper structure of all these data objects.  I think I'm
using struts 1.1 if that makes a difference.
 

1) I'd tend towards using JSTL rather than the Struts tags when the 
functionality is identical.


2) Put an ArrayList of JavaBeans into the "appropriate" scope (probably 
request?)


IOW, your ArrayList will contain a collection of JavaBeans with getters 
for each column you want exposed. Say you have a user represented by 
firstname, lastname, and ssn. So your bean would have getFirstname, 
getLastname, and getSsn methods.


In your Action you'd do something like:

request.setAttribute("users", userArrayList);

In your JSP you'd do something like (in JSTL; struts beans are quite 
similar):



 
   
  value="${user.lastname}"/>

 
   
 


or whatever.

Again, the hour or two of investment in "learning" JSTL is worth it for 
tags that don't explicitly need Struts functionality, but on a practical 
level that may not make any difference to you.


Dave



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: logic:iterate tag and form beans

2005-08-02 Thread BHansard
Example:

DataBean:
public class EmployeeBean(){
private String name = null;
Private String dept = null;

... Getters and setters
}

FormBean:
public class EmployeeForm extends ActionForm{
private Collection employees = new ArrayList();
... Getters and Setters
}

ActionClass:

public ActionForward execute(final ActionMapping mapping,
 final ActionForm form,
 final HttpServletRequest request,
 final HttpServletResponse response) {
EmployeeForm empForm = (EmployeeForm) form;

//getEmployeesFromDatabase should return a collection of EmployeeBeans
empForm.setEmployees(getEmployeesFromDatabase());
return mapping.findForward("display");
}


JSP:

Name
   Dept



   








People are conversing... without posting their email or filling 
up their mail box. roomity.com http://roomity.com/launch.jsp No sign up to read 
or search this Rich Internet App
 ~~1122996240050~~



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: logic:iterate tag and form beans

2005-08-02 Thread Brian Kremmin
Okay.  So this object which will hold a row of table data... does it
have a name or type according to Struts? i.e. Action, Form, Service,
DTO, DAO, Value Object, etc.

Or is it merely a general object like "Employee" which doesn't have a
special type?

Should this object have a naming scheme within the data structure of
struts or can I call it whatever?

Thanks much for your help, btw.



-Original Message-
From: Johnson, Kaerstin [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, August 02, 2005 10:07 AM
To: Struts Users Mailing List
Subject: RE: logic:iterate tag and form beans


Ok, If I am understanding the question correctly, you should be
populating your array list in your bean with a objects of whatever
represents a table row (such as an employee object), this object should
have the attributes (name, id, address) you would like to render in the
columns. 

Each object in the array will wind up being a table row. 



-Original Message-
From: Brian Kremmin [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, August 02, 2005 11:02 AM
To: user@struts.apache.org
Subject: logic:iterate tag and form beans

Hello Everyone,

 

This is my first post.  I've been watching the list for a while now and
I've hit a dead end.  This is probably quite simple so any help would be
greatly appreciated.

 

I want to get some table data from a database and output it in table
form on a webpage.

 

I'm planning to use an ArrayList to store the data and use the
logic:iterate tag to expose the elements of the list... however, I'm
unsure of the proper structure of all these data objects.  I think I'm
using struts 1.1 if that makes a difference.

 

I'm assuming I'll create a form bean with an ArrayList as a property..
is this correct?  However, I'm unsure of what sort of objects to put
into the array list.  Do I create another form bean with properties for
each table column, populate a new bean for each row of table data, and
put each into the ArrayList?  Or should the objects in the Arraylist be
something other than a form bean?

 

I'm looking for the 'best' and 'proper" practice as our standards group
is very picky.  Any ideas?

 

Thanks




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: logic:iterate tag and form beans

2005-08-02 Thread Johnson, Kaerstin

Ok, If I am understanding the question correctly, you should be
populating your array list in your bean with a objects of whatever
represents a table row (such as an employee object), this object should
have the attributes (name, id, address) you would like to render in the
columns. 

Each object in the array will wind up being a table row. 



-Original Message-
From: Brian Kremmin [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, August 02, 2005 11:02 AM
To: user@struts.apache.org
Subject: logic:iterate tag and form beans

Hello Everyone,

 

This is my first post.  I've been watching the list for a while now and
I've hit a dead end.  This is probably quite simple so any help would be
greatly appreciated.

 

I want to get some table data from a database and output it in table
form on a webpage.

 

I'm planning to use an ArrayList to store the data and use the
logic:iterate tag to expose the elements of the list... however, I'm
unsure of the proper structure of all these data objects.  I think I'm
using struts 1.1 if that makes a difference.

 

I'm assuming I'll create a form bean with an ArrayList as a property..
is this correct?  However, I'm unsure of what sort of objects to put
into the array list.  Do I create another form bean with properties for
each table column, populate a new bean for each row of table data, and
put each into the ArrayList?  Or should the objects in the Arraylist be
something other than a form bean?

 

I'm looking for the 'best' and 'proper" practice as our standards group
is very picky.  Any ideas?

 

Thanks




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]