You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by vi...@cc.tut.fi on 2003/06/05 23:46:33 UTC

Is it better to return list of formbeans or list of objects created by torque?

Hi,

I am using Torque with Struts.

I need to display some data from database in .jsp file.

I retrieve my data in action class as:

Criteria criteria = new Criteria;
List customerList = CustomerPeer.doSelect(criteria)

Now I have a list populated with objects made by Torque..?

I would like to return a list of formbeans presenting the customer
instead of these objects.

Something like:

List customerList = (myCustomerFormBean)CustomerPeer.doSelect(criteria);

Is it possible to cast a CustomerPeer object to formbean? If not
how should I do this?

Should I even try to return formbeans or is ok to use objects?
Formbeans should be lighter as least???


Thanks in advance,


Ville Kaseva









 



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


Re: Is it better to return list of formbeans or list of objects created by torque?

Posted by Rick Reumann <r...@reumann.net>.
On Thu, Jun 05,'03 (05:59 PM GMT-0400), Vic wrote: 

> What I do is my BaseFormBean implements a collection.
> 
> So it's both!
> It has getters/setters.
> When iterator or next() is called it goes to the next item in list. 
> Because it simplifies, it makes more complex designs possible.

I should point out that Vic's beans designed this way still DO NOT tie
the Struts beans to the business layer. At first I simply assumed that
they would, but they really do not at all. That's an important point
to make because you don't want to really be passing your Struts beans
around to business objects. The Form beans do have a DAO which is a link
to the business layer, but this DAO is independent of Struts. It's a
very cool design(IMO:). 

Most seem to insist that your Struts FormBeans be converted to something
like a DTO first and then that beans gets passed to the business layer
and going the other direction you return DTOs from the business layer.
Actually that's the pattern my lessons show at
http://www.reumann.net/struts/index.jsp. I actually now think that step
of converting your form beans to a DTO is pretty much a waste of time
(and processing). I'm sure someone will come up with some complex EJB
distributed scenario where you need a DTO, but I haven't run across this
situation. 

-- 
Rick


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


Re: Is it better to return list of formbeans or list of objects created by torque?

Posted by Vic Cekvenich <vi...@baseBeans.com>.
What I do is my BaseFormBean implements a collection.

So it's both!
It has getters/setters.
When iterator or next() is called it goes to the next item in list. 
Because it simplifies, it makes more complex designs possible.

Others make each getter and Array[].

hth,

vilho@cc.tut.fi wrote:

>Hi,
>
>I am using Torque with Struts.
>
>I need to display some data from database in .jsp file.
>
>I retrieve my data in action class as:
>
>Criteria criteria = new Criteria;
>List customerList = CustomerPeer.doSelect(criteria)
>
>Now I have a list populated with objects made by Torque..?
>
>I would like to return a list of formbeans presenting the customer
>instead of these objects.
>
>Something like:
>
>List customerList = (myCustomerFormBean)CustomerPeer.doSelect(criteria);
>
>Is it possible to cast a CustomerPeer object to formbean? If not
>how should I do this?
>
>Should I even try to return formbeans or is ok to use objects?
>Formbeans should be lighter as least???
>
>
>Thanks in advance,
>
>
>Ville Kaseva
>  
>

-- 
Vic Cekvenich,
Struts Instructor,
1-800-917-JAVA

Advanced <a href ="baseBeans.com">Struts Training</a> and project recovery in North East.
Open Source <a href ="baseBeans.com">Content Management</a>  basicPortal sofware
Best practice<a href ="baseBeans.com">Struts Support</a> v.1.1 helper ScafflodingXPress




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


Re: Is it better to return list of formbeans or list of objects created by torque?

Posted by Mark Lowe <ma...@talk21.com>.
You want to populate forms from actions..

So in an action servlet you use the objects generated by torque and 
populate the form form there.

e.g.

Iterator it = customerList.iterator();

while(it.hasNext()) {
	Customer cust = (Customer) it.next();
	String fieldName = cust.getFieldName();
	theForm.get("fieldName", fieldName);
}

Or to display in a jsp just feed it to an available context ..

eg

pageContext.setAttribute("myObj",customerList.toArray());
or
request.setAttribute ("myObj",customerList.toArray());
or
session.setAttribute ("myObj",customerList.toArray());

cheers mark

On Thursday, Jun 5, 2003, at 22:46 Europe/London, "" <vi...@cc.tut.fi> 
wrote:

> Hi,
>
> I am using Torque with Struts.
>
> I need to display some data from database in .jsp file.
>
> I retrieve my data in action class as:
>
> Criteria criteria = new Criteria;
> List customerList = CustomerPeer.doSelect(criteria)
>
> Now I have a list populated with objects made by Torque..?
>
> I would like to return a list of formbeans presenting the customer
> instead of these objects.
>
> Something like:
>
> List customerList = 
> (myCustomerFormBean)CustomerPeer.doSelect(criteria);
>
> Is it possible to cast a CustomerPeer object to formbean? If not
> how should I do this?
>
> Should I even try to return formbeans or is ok to use objects?
> Formbeans should be lighter as least???
>
>
> Thanks in advance,
>
>
> Ville Kaseva
>
>
>
>
>
>
>
>
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>


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