aspose file tools*
The moose likes Struts and the fly likes Struts2 bean value not able to retrieve and set Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts2 bean value not able to retrieve and set" Watch "Struts2 bean value not able to retrieve and set" New topic
Author

Struts2 bean value not able to retrieve and set

Arun Kumar
Ranch Hand

Joined: May 22, 2006
Posts: 62
Action class:

public class RoutingMaintenanceAction extends ActionSupport {

private Routing routing ;

}

#####################################################

Routing Class:

public class Routing {

private Set routingSteps ;

}

#######################################################

RoutingStep class:


public class RoutingStep {

private Long operStep;


}


#####################################################

Assume all the getters and setters.


When I try to retrieve it in the jsp I am not able to, I am using this syntax.


<s:iterator status="stat1" value="routing.routingSteps">

<%-- below one does not work --%>
<s:textfield name="routing.routingSteps[%{#stat1.index}].operStep" />

<%-- this one works --%>
<s:textfield name="top.operStep" />


<%-- I used a round about way like this --%>
<%-- But this does not set the value in the respecitve bean when i submit the action --%>

<s:textfield name="routing.routingSteps[%{#stat1.index}].operStep" value="%{top.operStep}" />

</s:iterator>



What could be the problem.

I am able to access other fields which are member of the Routing bean properly and on actin submit it is also getting set properly.



Any help will be appreciated.

[ December 06, 2008: Message edited by: Arun Kumar ]
[ December 06, 2008: Message edited by: Arun Kumar ]
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Please use the UBB "code" tag when posting source.

My first guess would be that you're using map/list/array notation and attempting to access a Set, which isn't a map, list, or array. I don't know how (or even if) OGNL would know what to do under those circumstances.
Arun Kumar
Ranch Hand

Joined: May 22, 2006
Posts: 62
Thanks David, that was sure an important pointer, but the litrature of Struts 2 says that.

Iterator will iterate over a value. An iterable value can be either of: java.util.Collection, java.util.Iterator, java.util.Enumeration, java.util.Map, array.

Since set is also of collection type and could be resolved to an Iterator type, so I was expecting this to work.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

The <s:iterate...> tag *does* iterate over it, as you imply in your code.

Submitting it, however, or attempting to access it via list/array/map notation as you do in the <s:text...> tag, will not, because it's a Set.

The two things are not equivalent.
Arun Kumar
Ranch Hand

Joined: May 22, 2006
Posts: 62
I got it thanks a lot, I was thinking that the <s:iterator tag inteprets the [] syntax automatically and and handles it appropriately whether it is list or set or any other collection but I was wrong. The tag is transparent in this regard and does it the standard java way.

I converted the set to list and it is working fine now.


Thanks again for your help David.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts2 bean value not able to retrieve and set