You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Brian Kremmin <Br...@toro.com> on 2005/08/02 17:02:02 UTC

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


Re: logic:iterate tag and form beans

Posted by Laurie Harper <la...@holoweb.net>.
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: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: RequestProcessor.process() method

Posted by Dave Newton <ne...@pingsite.com>.
Carl Smith wrote:

>in this RequestProcessor.process() method, there are some methods are place holders for our specific application to over ride. Say in our application we have a logic to be checked to see if user has access to the certain page. Which method (processPreprocess();processRoles();processPopulate();processValidate();processForward();) is a good place for us to place this logic in. Please note that our request can be multipart request.
>  
>
Well, processRoles is suppoed to be used for processing user roles. That 
might be a good place to start.

Dave



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: RequestProcessor.process() method

Posted by Dave Newton <ne...@pingsite.com>.
Carl Smith wrote:

>in this RequestProcessor.process() method, there are some methods are place holders for our specific application to over ride. Say in our application we have a logic to be checked to see if user has access to the certain page. Which method (processPreprocess();processRoles();processPopulate();processValidate();processForward();) is a good place for us to place this logic in. Please note that our request can be multipart request.
>  
>
PS, generally considered bad form (and you're less likely to get an 
answer) if you hijack a different thread for a new question--if I'm not 
paying attention to a particular thread I wouldn't notice that the topic 
has completely changed.

Dave



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RequestProcessor.process() method

Posted by Carl Smith <cc...@yahoo.com>.
in this RequestProcessor.process() method, there are some methods are place holders for our specific application to over ride. Say in our application we have a logic to be checked to see if user has access to the certain page. Which method (processPreprocess();processRoles();processPopulate();processValidate();processForward();) is a good place for us to place this logic in. Please note that our request can be multipart request.

Thanks.


		
---------------------------------
 Start your day with Yahoo! - make it your home page 

Re: logic:iterate tag and form beans

Posted by Dave Newton <ne...@pingsite.com>.
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):

<table>
  <c:forEach items="${users}" var="user">
    <tr>
      <td><c:out value="${user.firstname}"/> <c:out 
value="${user.lastname}"/></td>
      <td><c:out value="${user.ssn}"/></td>
    </tr>
  </c:forEach>
</table>

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: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org