wood burning stoves 2.0*
The moose likes Struts and the fly likes Alternatives to Struts tags ??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Alternatives to Struts tags ???" Watch "Alternatives to Struts tags ???" New topic
Author

Alternatives to Struts tags ???

Leandro Melo
Ranch Hand

Joined: Mar 27, 2004
Posts: 401
Hi,
usually i transder data from my Action to the JSPs with DTOs, like the following.

And i usually get this data back in my JSP with something like the following.
[code]
<logic resent name="addressVO" scope="request">
City is: <bean:write name="addressVO" property="city" scope="request"/>
Street is: <bean:write name="addressVO" property="street" scope="request"/>
</logic resent>
Are there alternatives to this or are we always stuck with struts tags?
Thanks,
ltcmelo
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

<% AddressVO addressVO = (AddressVO)request.getAttribute("addressVO");
if( addressVO != null){ %>
City is: <%= addressVO.getCity() %>
Street is: <%= addressVO.getStreet() %>
<%}%>

You're never STUCK with Struts. If something can be done WITH Struts, there is some workaround WITHOUT it.


A good workman is known by his tools.
Leandro Melo
Ranch Hand

Joined: Mar 27, 2004
Posts: 401
Thanks Marc,
this was exactly what i wanted to know.
After all, the dto is now part of the request object... i need some more studying on jsps.
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

There's a nice trick you might like to know. If you hand the DTO or VO off to the ActionForm, you can EASILY call the getters/setters of the DTO in Struts tags.
For instance, property="person.address.zipcode" would effectively call to your ActionForm:
getPerson().getAddress().getZipcode()
and
getPerson().getAddress().setZipcode()
Where the ActionForm would have a "person" bean(our DTO/VO inside the ActionForm) that has an "address" bean that has a "zipcode" bean.
Leandro Melo
Ranch Hand

Joined: Mar 27, 2004
Posts: 401
You're saying the case i handle a DTO to ActionForm or to Action (because, doesn't the ActionForm comes from a html form - from a page?).
Then you said

Where the ActionForm would have a "person" bean(our DTO/VO inside the ActionForm) that has an "address" bean that has a "zipcode" bean.

The ActionForm (or Action?) will have a person bean... OK!
And a has a Address bean... OK!
That has a ZipCode bean...??? Isn't the zipcode just o property of address bean?
Thanks,
ltcmelo
Leandro Melo
Ranch Hand

Joined: Mar 27, 2004
Posts: 401
continuing...
I'm just trying to understand it well.
The sample code you exposed would be placed in the ActionForm or inside the Action for example???
Thanks,
ltcmelo
Leandro Melo
Ranch Hand

Joined: Mar 27, 2004
Posts: 401
Sorry,
think i got it now.
You're telling options of how to get data from the bean in the JSP returned by Action rigth!?
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

Um... the only "code" that you would write was the property attribute which goes in the jsps.
The VO/DTO would be in the ActionForm. My point is that Struts can convert a dotted notation in a property attribute (found in Struts tags of a jsp) into the corresponding getter/setter.
 
Don't get me started about those stupid light bulbs.
 
subject: Alternatives to Struts tags ???