You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by cwalet <cw...@gmail.com> on 2011/12/06 14:46:46 UTC

struts2 string to map conversion

any body knows how to use Struts2 TypeConversion(in xwork libs) to
convert a parameter string to a hashmap object?
I tried this:

@TypeConversion(key = "phone", rule = ConversionRule.MAP, converter =
"java.lang.String")
public void setHmss(HashMap<String, Object> hmso) {
		this.hmso = hmso;
}

but no convert had it done.how?any suggestion?

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: struts2 string to map conversion

Posted by Li Ying <li...@gmail.com>.
What is your client side code (JSP)?

In OGNL expression, a value assignment is something like:
"aMap[aKey] = aValue"

So, you need create HTML code like:
<input name="aMap[aKey]" value="aValue" />

On the server side, the OGNL expression will be converted into Java
method invoking like:
yourAction.getAMap().put("aKey", "aValue")

Unfortunately, the Java generic system don't know the element data
type of your Map,
so, the data type for [aKey] and [aValue] may be a problem.

I suggest you just declare the map as Map<String, String>, and do the
conversion by yourself.

All I talked above are not tested, just suggestion.
You need do the test and check if it is correct.


2011/12/6 cwalet <cw...@gmail.com>:
> any body knows how to use Struts2 TypeConversion(in xwork libs) to
> convert a parameter string to a hashmap object?
> I tried this:
>
> @TypeConversion(key = "phone", rule = ConversionRule.MAP, converter =
> "java.lang.String")
> public void setHmss(HashMap<String, Object> hmso) {
>                this.hmso = hmso;
> }
>
> but no convert had it done.how?any suggestion?
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: struts2 string to map conversion

Posted by Wes Wannemacher <we...@wantii.com>.
Have you read through this -

http://struts.apache.org/2.x/docs/ognl-basics.html

The type conversion is generally called automagically.

-W

On Tue, Dec 6, 2011 at 8:46 AM, cwalet <cw...@gmail.com> wrote:
> any body knows how to use Struts2 TypeConversion(in xwork libs) to
> convert a parameter string to a hashmap object?
> I tried this:
>
> @TypeConversion(key = "phone", rule = ConversionRule.MAP, converter =
> "java.lang.String")
> public void setHmss(HashMap<String, Object> hmso) {
>                this.hmso = hmso;
> }
>
> but no convert had it done.how?any suggestion?
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>



-- 
Wes Wannemacher

Head Engineer, WanTii, Inc.
Need Training? Struts, Spring, Maven, Tomcat...
Ask me for a quote!

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: struts2 string to map conversion

Posted by mohan rao <mo...@gmail.com>.
Parameters will returns String[] but not string check out that might be
causing the problem.

--
View this message in context: http://struts.1045723.n5.nabble.com/struts2-string-to-map-conversion-tp5052114p5060791.html
Sent from the Struts - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org