struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeromy Evans <jeromy.ev...@blueskyminds.com.au>
Subject Re: Unable to make Type Conversion work in Struts2
Date Tue, 19 Feb 2008 01:14:17 GMT
Did you ever resolve this?

I always use a Map rather than a List because historically there was a 
problem accessing Lists via the OGNL implementation.
I don't know whether it was fixed

ie. Substitute the List with a Map and address the items by the 
appropriate key instead of the index

<s:property value="testList['0']" 

Moving to Map of course loses order but the Indexed Map conversion does 
work as stated in the docs.

Maxx wrote:
> Hello,
>
> Refering to http://struts.apache.org/2.x/docs/type-conversion.html ,
> I'm currently trying to make Type Conversion working on a really
> simple example. And unfortunately, nothing's working. Below are the
> sources.
>
> Could someone please tell what I'm doing wrong (I suspect something
> with the OGNL expressions but could not found what...)
>
> Greets,
> Maxx
>
> PS: the <s:iterator> doesn't display anything, but if you move the
> testList under a JavaBean (e.g. TestBean) and you change testList to
> testBean.testList as OGNL value everywhere it's used (esp. for the
> iterator), it displays the values in the list... BUT the textfields
> still do not work, as while submitting the form, there are some
> Exceptions in the log which say:
> ParametersInterceptor - [setParameters]: Unexpected Exception caught
> setting 'testBean.testList(0)' on 'class
> com.mycompany.somepacakge.action.TestAction: Error setting expression
> 'testBean.testList(0)' with value '[Ljava.lang.String;@102011a'
>
> ---
>
> // TestAction.java
> public class TestAction {
>
>     public String execute() {
>
>         List<String> testList = new ArrayList<String>(2);
>         testList.add("LIST 1st VALUE");
>         testList.add("LIST 2nd VALUE");
>         setTestList(testList);
>
>         return INPUT;
>
>     }
>
>     public List<String> getTestList() {
>         return (List<String>) session.get("list");
>     }
>
>     public void setTestList(List<String> list) {
>         session.put(list, "list");
>     }
>
>
> }
>
>
> // TestAction-conversion.properties
> Element_testList=java.lang.String
>
>
> // test.jsp
> <%@page language="java" contentType="text/html; charset=ISO-8859-1"%>
> <%@taglib prefix="s" uri="/struts-tags"%>
>
> <s:form id="testForm" action="Test" method="post">
> <pre>
> 	Direct access: = does not work
> 	testList(0) = <s:property value="testList(0)" />
> 	testList(1) = <s:property value="testList(1)" />
>
> 	Regular iterator: = does not work
> <s:iterator value="testList" status="stat">
> 	testList(<s:property value="#stat.index"/>) = <s:property value="top"
> /> // <s:textfield name="testList(%{#stat.index})" />
> </s:iterator>
> </pre>
> 	<s:submit id="submitBtn" value="Submit Test" action="Test" />
> </s:form>
>
> ---------------------------------------------------------------------
> 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


Mime
View raw message