• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Struts2 <s:select multiple=true> -> Eventbean.setMap(Map map_from_multile_struts2)

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am having problems with the OGNL syntax and possibly action setup of my web-application.

Scenerio, I want to create a struts2 <struts2:select name="event.dj_map" list="event.dj_map" size="5" multiple="true"> that will submit a map<string,string> to my custom javabean that my action places on the stack (Event.java). After I get this working I'll change to map<long, string> (my id's are stored as longs), I don't think that change will incur any problems.

Also, I don't think this matters but, my .jsp has javascript code that can add elements (options with value & bodytext elements) if the user should want to.

JSP: manage-event.jsp called from /secure/ManageEvents_create.action?subdomain=yadayadayada (accessible only by logged in users via authenticationInterceptor)

XML: struts.xml snippet

ACTION: ManageEvents.java

JAVA: Event.java (relevant parts)

ERROR: ognlNoSuchMethodException
WARNING: Error setting value
ognl.MethodFailedException: Method "setDj_map" failed for object com.mycityonline.events.Event@e2fa0e [java.lang.NoSuchMethodException: setDj_map([Ljava.lang.String;)]
at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:823)
at ognl.OgnlRuntime.setMethodValue(OgnlRuntime.java:964)
at ognl.ObjectPropertyAccessor.setPossibleProperty(ObjectPropertyAccessor.java:75)
at ognl.ObjectPropertyAccessor.setProperty(ObjectPropertyAccessor.java:131)
at com.opensymphony.xwork2.ognl.accessor.ObjectAccessor.setProperty(ObjectAccessor.java:28)
at ognl.OgnlRuntime.setProperty(OgnlRuntime.java:1656)
at ognl.ASTProperty.setValueBody(ASTProperty.java:101)
at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:177)
at ognl.SimpleNode.setValue(SimpleNode.java:246)
at ognl.ASTChain.setValueBody(ASTChain.java:172)
at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:177)
at ognl.SimpleNode.setValue(SimpleNode.java:246)
at ognl.Ognl.setValue(Ognl.java:476)
at com.opensymphony.xwork2.ognl.OgnlUtil.setValue(OgnlUtil.java:192)
at com.opensymphony.xwork2.ognl.OgnlValueStack.setValue(OgnlValueStack.java:155)
at com.opensymphony.xwork2.ognl.OgnlValueStack.setValue(OgnlValueStack.java:143)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.setParameters(ParametersInterceptor.java:273)
.....
at java.lang.Thread.run(Thread.java:619)
/-- Encapsulated exception ------------\
java.lang.NoSuchMethodException: setDj_map([Ljava.lang.String;)
at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:810)
at ognl.OgnlRuntime.setMethodValue(OgnlRuntime.java:964)
at ognl.ObjectPropertyAccessor.setPossibleProperty(ObjectPropertyAccessor.java:75)
at ognl.ObjectPropertyAccessor.setProperty(ObjectPropertyAccessor.java:131)
at com.opensymphony.xwork2.ognl.accessor.ObjectAccessor.setProperty(ObjectAccessor.java:28)
at ognl.OgnlRuntime.setProperty(OgnlRuntime.java:1656)
at ognl.ASTProperty.setValueBody(ASTProperty.java:101)
at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:177)
at ognl.SimpleNode.setValue(SimpleNode.java:246)
at ognl.ASTChain.setValueBody(ASTChain.java:172)
at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:177)
at ognl.SimpleNode.setValue(SimpleNode.java:246)
at ognl.Ognl.setValue(Ognl.java:476)
at com.opensymphony.xwork2.ognl.OgnlUtil.setValue(OgnlUtil.java:192)
...
at java.lang.Thread.run(Thread.java:619)

Can anyone shed any light or links on how to get a mapped multiple select into your pojo with OGNL and STRUTS2? The examples I've seen are ALL of multiple struts2:textfields going into a map, I have YET to see any code of a multiple select being mapped to a map in a pojo. Seems like it should be extremely common. I even tried to "trick" java by implementing a dummy setDj_map(String str_map) just to see if I could kill the error to no avail :-/

research thus far:
http://www.zorched.net/2009/07/02/struts2-map-form-to-collection-of-objects/
http://struts.apache.org/2.0.14/docs/select.html
http://www.roseindia.net/struts/struts2/struts2uitags/select-tag.shtml

Thanks for any assistance/guidance/direction you can provide :-)!
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How is the select tag rendering? I don't recall having had any problems using map-backed selects, but I can look in to it further if you're still stuck.

A few mildly unrelated comments:

- Consider coding to the Map interface rather than having the property hard-coded to an implementation.

- If you're using 1.5+ then it's better to genericize the map.

- The create() method seems unnecessarily obfuscated: deep nesting makes code difficult to read, because you're not always sure where you need to stop reading. Consider create() written like this:- I'm also not a big fan of not following Java naming conventions (like Event_Registry or dj_map etc.)

- Your validate method won't work--empty fields are sent back by the browser as empty strings--not nulls. You should check for empty or null; possibly using Apache Commons Lang's StringUtils.isBlank().
 
J Owens
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Still not working yet ,

The form renders as:



the above value/content text is with the test map that I whipped up in the actions prepare() method as an attempt to get any kind of action / form object communication working.
- I'm using the latest Java, I think its JDK 6 u14
- as for the validate, I threw that in at the last minute, but its good to know it was not going to work if I needed it lol, I usually test for string length < 1 in addition to null (guess I can drop the null test)

- I DEFINITELY like your create method more, I'll have to bone up on that syntax and add it to my "toolbox"
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you see the error, it is looking for a setDj_map which takes a String[] not a String. Try that once...
 
J Owens
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ankit Garg wrote:If you see the error, it is looking for a setDj_map which takes a String[] not a String. Try that once...



I tried also, same error produced
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic