File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Accessing nested info via html:text Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Accessing nested info via html:text" Watch "Accessing nested info via html:text" New topic

Accessing nested info via html:text

Ryan Kade
Ranch Hand

Joined: Aug 16, 2005
Posts: 69
I've got an ActionForm that contains a "Bean" that contains an object with information I need to iterate on. It looks something like this:

I'm having trouble figuring out how to use <html:text> to get at the information in the Contact class:

Obviuosly this doesn't work since name is not a property of contacts. I tried to get around this using <c:set> like so:

That DOES work to populate the text box, but not when the user changes the value of the textbox and submits. Instead of getting the changes, I get the originally populated value. I'm guessing this is because <c:set> does not have the var point to the actual memory location of value and thus when the text value gets changed, it's not changing the actual bean stored in the session.

Short of redesigning the classes so there aren't 2 nested levels (which would really break my encapsulation), what can I do? Is there a JSTL or Struts tag that I can use instead of <c:set> to govern the scope of the property attribute for <html:text>?

[ February 02, 2007: Message edited by: Ryan Kade ]
Ryan Kade
Ranch Hand

Joined: Aug 16, 2005
Posts: 69
Ok, after searching the docs (imagine that!) I discovered the solution to my problem. For anyone else interested, from the docs for Struts "Package org.apache.struts.taglib.bean":

Bean Properties - Extended syntax to refer to JavaBean properties with simple names (same as the standard JSP tags <jsp:getProperty> and <jsp:setProperty> ) , nested names (a property named returns the value retrieved by the Java expression getAddress().getCity()), and indexed names (a property named address[3] retrieves the fourth address from the indexed "address" property of a bean).

Thus, for my purposes, this should work:

And it does!


Thanks anyway.
[ February 02, 2007: Message edited by: Ryan Kade ]
I agree. Here's the link:
subject: Accessing nested info via html:text
Similar Threads
Input ActionForm has a field containing an array of javabean, will it work?
Questions about jstl tags : useBean forEach set
can't get indexed form property to work.
EL expression not working in jsp:setProperty
Simple Question