• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Alternatives to Struts tags ???

 
Leandro Melo
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<% 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.
 
Leandro Melo
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic