You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Joe <fu...@lycos.com> on 2011/04/29 17:02:22 UTC

Struts 2: Does the Indexed List Example Work?

 I've been trying to get the Indexed List example from the Type Conversion documentation (http://struts.apache.org/2.0.14/docs/type-conversion.html#TypeConversion-AnadvancedexampleforindexedListsandMaps) to work without success.  

The action is as follows (note I initialize the List with some TestData instances):

package gmi.action.test;

import java.util.ArrayList;
import java.util.List;
import com.opensymphony.xwork2.Action;

/*This is a test!*/

public class TestAction implements Action {

    private List beanList = new ArrayList();


    public List getBeanList() {
        return beanList;
    }

    public void setBeanList(List beanList) {
        this.beanList = beanList;
    }

    public String execute() throws Exception {
    	beanList.add(new TestData(1l, "one"));
    	beanList.add(new TestData(2l, "two"));
    	beanList.add(new TestData(3l, "three"));
        return SUCCESS;
    }
}

The data class is the same as in the example:

package gmi.action.test;

import java.io.Serializable;

public class TestData implements Serializable {	

	    private Long id;
	    private String name;
	    
	    public TestData(Long i, String n){
	    	id = i;
	    	name = n;
	    }

	    public Long getId() {
	        return id;
	    }

	    public void setId(Long id) {
	        this.id = id;
	    }

	    public String getName() {
	        return name;
	    }

	    public void setName(String name) {
	        this.name = name;
	    }


	    public String toString() {
	        return "TestData{" +
	                "id=" + id +
	                ", name='" + name + '\'' +
	                '}';
	    }
	}

I have a TestAction-conversion.properties file like so:

KeyProperty_beanList=id
Element_beanList=TestData
CreateIfNull_beanList=true

and my struts.xml file contains:

        <action name="prepTest" method="execute" class="gmi.action.test.TestAction">
            <result name="success">/test.jsp</result>
        </action>


If I browse to the prepTest url, I get 3 text boxes, so the iterator is working, but the boxes are empty.  Has anyone else had success with this example or accessing List elements by the List element ID's rather than using something like status.id?
Thanks,
Joe



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


Re: Struts 2: Does the Indexed List Example Work?

Posted by Dave Newton <da...@gmail.com>.
Yep.

Sometimes I don't use enough words :)

Dave

On Fri, Apr 29, 2011 at 1:01 PM, Chris Pratt <th...@gmail.com> wrote:
> Shouldn't that be:
>
> <s:textfield theme="simple" name="beanList[%{bean.id}].name"/>
>
> Is that what you meant Dave?
>  (*Chris*)
>
> On Fri, Apr 29, 2011 at 9:07 AM, Dave Newton <da...@gmail.com> wrote:
>
>> Try with square brackets first; see what happens.
>>
>> Dave
>>
>> On Fri, Apr 29, 2011 at 12:04 PM, Joe <fu...@lycos.com> wrote:
>> >
>> >
>> > On Apr 29, 2011, Dave Newton-6 wrote:
>> >>What does the JSP look like?
>> >>Dave
>> >
>> > Sorry, it is the same as the example with the exception of fixing a minor
>> typo in the textfield tag (the example is missing a colon):
>> >
>> > <%@ taglib prefix="s" uri="/struts-tags"%>
>> > <head>
>> > </head>
>> > <body>
>> > <s:form method="post" theme="xhtml">
>> > <p>Experimenting with indexed values (List Values)
>> > <p>
>> > <s:iterator value="beanList" id="bean">
>> >  <s:textfield theme="simple" name="beanList(%{bean.id}).name" /><br>
>> > </s:iterator>
>> > <p>
>> > <s:submit theme="simple" action="saveTest" key="button.label.save"
>> cssClass="butStnd"/>
>> > </s:form>
>> > </body>
>> > </html>
>> >
>> > ---------------------------------------------------------------------
>> > 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
>>
>>
>

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


Re: Struts 2: Does the Indexed List Example Work?

Posted by Chris Pratt <th...@gmail.com>.
Shouldn't that be:

<s:textfield theme="simple" name="beanList[%{bean.id}].name"/>

Is that what you meant Dave?
  (*Chris*)

On Fri, Apr 29, 2011 at 9:07 AM, Dave Newton <da...@gmail.com> wrote:

> Try with square brackets first; see what happens.
>
> Dave
>
> On Fri, Apr 29, 2011 at 12:04 PM, Joe <fu...@lycos.com> wrote:
> >
> >
> > On Apr 29, 2011, Dave Newton-6 wrote:
> >>What does the JSP look like?
> >>Dave
> >
> > Sorry, it is the same as the example with the exception of fixing a minor
> typo in the textfield tag (the example is missing a colon):
> >
> > <%@ taglib prefix="s" uri="/struts-tags"%>
> > <head>
> > </head>
> > <body>
> > <s:form method="post" theme="xhtml">
> > <p>Experimenting with indexed values (List Values)
> > <p>
> > <s:iterator value="beanList" id="bean">
> >  <s:textfield theme="simple" name="beanList(%{bean.id}).name" /><br>
> > </s:iterator>
> > <p>
> > <s:submit theme="simple" action="saveTest" key="button.label.save"
> cssClass="butStnd"/>
> > </s:form>
> > </body>
> > </html>
> >
> > ---------------------------------------------------------------------
> > 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: Struts 2: Does the Indexed List Example Work?

Posted by Dave Newton <da...@gmail.com>.
Try with square brackets first; see what happens.

Dave

On Fri, Apr 29, 2011 at 12:04 PM, Joe <fu...@lycos.com> wrote:
>
>
> On Apr 29, 2011, Dave Newton-6 wrote:
>>What does the JSP look like?
>>Dave
>
> Sorry, it is the same as the example with the exception of fixing a minor typo in the textfield tag (the example is missing a colon):
>
> <%@ taglib prefix="s" uri="/struts-tags"%>
> <head>
> </head>
> <body>
> <s:form method="post" theme="xhtml">
> <p>Experimenting with indexed values (List Values)
> <p>
> <s:iterator value="beanList" id="bean">
>  <s:textfield theme="simple" name="beanList(%{bean.id}).name" /><br>
> </s:iterator>
> <p>
> <s:submit theme="simple" action="saveTest" key="button.label.save" cssClass="butStnd"/>
> </s:form>
> </body>
> </html>
>
> ---------------------------------------------------------------------
> 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: Struts 2: Does the Indexed List Example Work?

Posted by Dave Newton <da...@gmail.com>.
Ah, older version of S2--yeah.

Dave

On Fri, Apr 29, 2011 at 1:57 PM, Chris Pratt <th...@gmail.com> wrote:
> Oh, duh, I'm not sure why I didn't see it before.  You can either just use
> %{id} and then you don't need the id="bean" on the s:iterate tag.  Or, you
> can use %{#bean.id}.
>  (*Chris*)
> On Apr 29, 2011 10:18 AM, "Joe" <fu...@lycos.com> wrote:
>> Chris Pratt wrote:
>>
>> Shouldn't that be:
>> <s:textfield theme="simple" name="beanList[%{bean.id}].name"/>
>>
>>
>> I changed my JSP as indicated and still didn't get values in the text
> boxes. The source of the page looks like this:
>>
>> <input type="text" name="beanList[].name" value=""
> id="prepTest_beanList___name"/><br>
>>
>> which to me indicates that it is having a problem with the "bean.id" part
> of the equation.
>> Wouldn't square brackets indicate an index into the list, rather than
> obtaining an element by the id property?
>>
>> ---------------------------------------------------------------------
>> 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: Struts 2: Does the Indexed List Example Work?

Posted by Chris Pratt <th...@gmail.com>.
Oh, duh, I'm not sure why I didn't see it before.  You can either just use
%{id} and then you don't need the id="bean" on the s:iterate tag.  Or, you
can use %{#bean.id}.
  (*Chris*)
On Apr 29, 2011 10:18 AM, "Joe" <fu...@lycos.com> wrote:
> Chris Pratt wrote:
>
> Shouldn't that be:
> <s:textfield theme="simple" name="beanList[%{bean.id}].name"/>
>
>
> I changed my JSP as indicated and still didn't get values in the text
boxes. The source of the page looks like this:
>
> <input type="text" name="beanList[].name" value=""
id="prepTest_beanList___name"/><br>
>
> which to me indicates that it is having a problem with the "bean.id" part
of the equation.
> Wouldn't square brackets indicate an index into the list, rather than
obtaining an element by the id property?
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>

Re: Re: Struts 2: Does the Indexed List Example Work?

Posted by Dave Newton <da...@gmail.com>.
I didn't think you'd even need to have the type conversion properties
file, but w/o generic accessors I'm not sure.

The above JSP still has parens instead of square brackets.

d.

On Fri, Apr 29, 2011 at 4:07 PM, Joe <fu...@lycos.com> wrote:
> Dave Newton-6 wrote:
> Try the square brackets again.
>
> Chris Pratt wrote:
> Try: value="%{name}"
>
> That gets the value into the textbox, but when I submit the form, I get either nothing in the action (square brackets) or an exception (using curly brackets):
>
> <s:iterator value="beanList" var="bean">
>  <s:textfield theme="simple" name="beanList(%{#bean.id}).name" value="%{name}" /><br>
> </s:iterator>
>
> All my save action does is print out the array.
>
> public class TestAction implements Action {
>        private static Logger log = Logger.getLogger(TestAction.class);
>
> // note: getters/setters/execute method already posted removed
>
>    public String save(){
>        log.debug("save: beanList size: "+beanList.size());
>        for (int i = 0; i < beanList.size(); i++){
>                log.debug(beanList.get(i));
>        }
>        return SUCCESS;
>    }
> }
>
>  The SUCCESS result is mapped to a blank JSP:
>
>        <action name="saveTest" method="save" class="gmi.action.test.TestAction">
>            <result name="success">/test2.jsp</result>
>        </action>
>
> The exception from the curly-brace version is:
>
> [2011-04-29 15:57:29,802] ERROR nsymphony.xwork2.ognl.accessor.XWorkMethodAccessor - An unexpected exception occurred
> java.util.NoSuchElementException
>        at java.util.AbstractList$Itr.next(AbstractList.java:350)
>        at com.opensymphony.xwork2.ognl.accessor.XWorkCollectionPropertyAccessor.getProperty(XWorkCollectionPropertyAcce
> ssor.java:122)
>        at com.opensymphony.xwork2.ognl.accessor.XWorkMethodAccessor.callMethod(XWorkMethodAccessor.java:81)
>        at ognl.OgnlRuntime.callMethod(OgnlRuntime.java:846)
>        at com.opensymphony.xwork2.ognl.accessor.CompoundRootAccessor.callMethod(CompoundRootAccessor.java:232)
>        at ognl.OgnlRuntime.callMethod(OgnlRuntime.java:846)
>        at ognl.ASTMethod.getValueBody(ASTMethod.java:73)
>        at ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:170)
>        at ognl.SimpleNode.getValue(SimpleNode.java:210)
>        at ognl.ASTChain.setValueBody(ASTChain.java:168)
>        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:209)
>        at com.opensymphony.xwork2.ognl.OgnlValueStack.trySetValue(OgnlValueStack.java:173)
>        at com.opensymphony.xwork2.ognl.OgnlValueStack.setValue(OgnlValueStack.java:160)
>        at com.opensymphony.xwork2.ognl.OgnlValueStack.setValue(OgnlValueStack.java:151)
>        at com.opensymphony.xwork2.interceptor.ParametersInterceptor.setParameters(ParametersInterceptor.java:288)
>        at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:199)
>        at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
>        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
>        at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207)
>        at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
>        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
>        at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:19
> 0)
>        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
>        at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)
>        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
>        at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94)
>        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
>        at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:243)
>        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
>        at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
>        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
>        at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:
> 141)
>        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
>        at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267)
>        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
>        at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:142)
>        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
>        at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:166)
>        at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
>        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
>        at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176)
>        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
>        at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
>        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
>        at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:190)
>        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
>        at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:18
> 7)
>        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
>        at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)
>        at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:485)
>        at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:395)
>        at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
>        at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3496)
>        at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
>        at weblogic.security.service.SecurityManager.runAs(Unknown Source)
>        at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2180)
>        at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2086)
>        at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1406)
>        at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
>        at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
> [2011-04-29 15:57:29,802] WARN  com.opensymphony.xwork2.ognl.OgnlValueStack        - Error setting expression 'beanList(
> 1).name' with value '[Ljava.lang.String;@1f848d1'
> ognl.OgnlException: target is null for setProperty(null, "name", [Ljava.lang.String;@1f848d1)
>        at ognl.OgnlRuntime.setProperty(OgnlRuntime.java:1651)
>        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)
> . . .
> repeated several times
> Is this a problem with type conversion?
>
>
> ---------------------------------------------------------------------
> 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: Re: Struts 2: Does the Indexed List Example Work?

Posted by Chris Pratt <th...@gmail.com>.
It appears that exception is occuring when Struts is attempting to set the
value.  I'm betting the list is empty and it's calling .get(5) (or whatever
the first index happens to be), so it can call .setName() on it, and blowing
up because there ain't one.  If youvare trying to update an existing list
make your Action implement Preparable and retrieve the existing list so you
can return it when Struts calls getBeanList.
  (*Chris*)
On Apr 29, 2011 1:08 PM, "Joe" <fu...@lycos.com> wrote:
> Dave Newton-6 wrote:
> Try the square brackets again.
>
> Chris Pratt wrote:
> Try: value="%{name}"
>
> That gets the value into the textbox, but when I submit the form, I get
either nothing in the action (square brackets) or an exception (using curly
brackets):
>
> <s:iterator value="beanList" var="bean">
> <s:textfield theme="simple" name="beanList(%{#bean.id}).name"
value="%{name}" /><br>
> </s:iterator>
>
> All my save action does is print out the array.
>
> public class TestAction implements Action {
> private static Logger log = Logger.getLogger(TestAction.class);
>
> // note: getters/setters/execute method already posted removed
>
> public String save(){
> log.debug("save: beanList size: "+beanList.size());
> for (int i = 0; i < beanList.size(); i++){
> log.debug(beanList.get(i));
> }
> return SUCCESS;
> }
> }
>
> The SUCCESS result is mapped to a blank JSP:
>
> <action name="saveTest" method="save" class="gmi.action.test.TestAction">
> <result name="success">/test2.jsp</result>
> </action>
>
> The exception from the curly-brace version is:
>
> [2011-04-29 15:57:29,802] ERROR
nsymphony.xwork2.ognl.accessor.XWorkMethodAccessor - An unexpected exception
occurred
> java.util.NoSuchElementException
> at java.util.AbstractList$Itr.next(AbstractList.java:350)
> at
com.opensymphony.xwork2.ognl.accessor.XWorkCollectionPropertyAccessor.getProperty(XWorkCollectionPropertyAcce
> ssor.java:122)
> at
com.opensymphony.xwork2.ognl.accessor.XWorkMethodAccessor.callMethod(XWorkMethodAccessor.java:81)
> at ognl.OgnlRuntime.callMethod(OgnlRuntime.java:846)
> at
com.opensymphony.xwork2.ognl.accessor.CompoundRootAccessor.callMethod(CompoundRootAccessor.java:232)
> at ognl.OgnlRuntime.callMethod(OgnlRuntime.java:846)
> at ognl.ASTMethod.getValueBody(ASTMethod.java:73)
> at ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:170)
> at ognl.SimpleNode.getValue(SimpleNode.java:210)
> at ognl.ASTChain.setValueBody(ASTChain.java:168)
> 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:209)
> at
com.opensymphony.xwork2.ognl.OgnlValueStack.trySetValue(OgnlValueStack.java:173)
> at
com.opensymphony.xwork2.ognl.OgnlValueStack.setValue(OgnlValueStack.java:160)
> at
com.opensymphony.xwork2.ognl.OgnlValueStack.setValue(OgnlValueStack.java:151)
> at
com.opensymphony.xwork2.interceptor.ParametersInterceptor.setParameters(ParametersInterceptor.java:288)
> at
com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:199)
> at
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
> at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
> at
com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207)
> at
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
> at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
> at
com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:19
> 0)
> at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
> at
org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)
> at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
> at
org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94)
> at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
> at
org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:243)
> at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
> at
com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
> at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
> at
com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:
> 141)
> at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
> at
org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267)
> at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
> at
com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:142)
> at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
> at
com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:166)
> at
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
> at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
> at
com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176)
> at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
> at
org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
> at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
> at
com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:190)
> at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
> at
com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:18
> 7)
> at
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
> at
org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)
> at
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:485)
> at
org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:395)
> at
weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
> at
weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3496)
> at
weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
> at weblogic.security.service.SecurityManager.runAs(Unknown Source)
> at
weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2180)
> at
weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2086)
> at
weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1406)
> at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
> at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
> [2011-04-29 15:57:29,802] WARN com.opensymphony.xwork2.ognl.OgnlValueStack
- Error setting expression 'beanList(
> 1).name' with value '[Ljava.lang.String;@1f848d1'
> ognl.OgnlException: target is null for setProperty(null, "name",
[Ljava.lang.String;@1f848d1)
> at ognl.OgnlRuntime.setProperty(OgnlRuntime.java:1651)
> 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)
> . . .
> repeated several times
> Is this a problem with type conversion?
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>

Re: Struts 2: Does the Indexed List Example Work?

Posted by Joe <fu...@lycos.com>.
Dave Newton-6 wrote:
> The above JSP still has parens instead of square brackets. 

I tried it both ways, parens last, so I only posted the one JSP.

Chris Pratt:
> If youvare trying to update an existing list make your Action implement Preparable 
> and retrieve the existing list so you can return it when Struts calls getBeanList. 

I got more exceptions, probably because the type conversion didn't know what to do with the beans.
I think we've proven that the functionality doesn't work as documented (if it works at all).  I'm going to work around it by using the list index rather than the bean id value.  That appears to work fine.
Thanks again for the help.

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


Re: Re: Struts 2: Does the Indexed List Example Work?

Posted by Joe <fu...@lycos.com>.
Dave Newton-6 wrote:
Try the square brackets again. 

Chris Pratt wrote:
Try: value="%{name}" 

That gets the value into the textbox, but when I submit the form, I get either nothing in the action (square brackets) or an exception (using curly brackets):

<s:iterator value="beanList" var="bean">
  <s:textfield theme="simple" name="beanList(%{#bean.id}).name" value="%{name}" /><br>
</s:iterator>

All my save action does is print out the array. 

public class TestAction implements Action {
	private static Logger log = Logger.getLogger(TestAction.class);

// note: getters/setters/execute method already posted removed
    
    public String save(){
    	log.debug("save: beanList size: "+beanList.size());
    	for (int i = 0; i < beanList.size(); i++){
    		log.debug(beanList.get(i));
    	}
    	return SUCCESS;
    }
}

 The SUCCESS result is mapped to a blank JSP:

        <action name="saveTest" method="save" class="gmi.action.test.TestAction">
            <result name="success">/test2.jsp</result>
        </action>

The exception from the curly-brace version is:

[2011-04-29 15:57:29,802] ERROR nsymphony.xwork2.ognl.accessor.XWorkMethodAccessor - An unexpected exception occurred
java.util.NoSuchElementException
        at java.util.AbstractList$Itr.next(AbstractList.java:350)
        at com.opensymphony.xwork2.ognl.accessor.XWorkCollectionPropertyAccessor.getProperty(XWorkCollectionPropertyAcce
ssor.java:122)
        at com.opensymphony.xwork2.ognl.accessor.XWorkMethodAccessor.callMethod(XWorkMethodAccessor.java:81)
        at ognl.OgnlRuntime.callMethod(OgnlRuntime.java:846)
        at com.opensymphony.xwork2.ognl.accessor.CompoundRootAccessor.callMethod(CompoundRootAccessor.java:232)
        at ognl.OgnlRuntime.callMethod(OgnlRuntime.java:846)
        at ognl.ASTMethod.getValueBody(ASTMethod.java:73)
        at ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:170)
        at ognl.SimpleNode.getValue(SimpleNode.java:210)
        at ognl.ASTChain.setValueBody(ASTChain.java:168)
        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:209)
        at com.opensymphony.xwork2.ognl.OgnlValueStack.trySetValue(OgnlValueStack.java:173)
        at com.opensymphony.xwork2.ognl.OgnlValueStack.setValue(OgnlValueStack.java:160)
        at com.opensymphony.xwork2.ognl.OgnlValueStack.setValue(OgnlValueStack.java:151)
        at com.opensymphony.xwork2.interceptor.ParametersInterceptor.setParameters(ParametersInterceptor.java:288)
        at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:199)
        at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
        at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207)
        at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
        at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:19
0)
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
        at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
        at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94)
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
        at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:243)
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
        at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
        at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:
141)
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
        at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267)
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
        at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:142)
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
        at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:166)
        at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
        at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176)
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
        at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
        at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:190)
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
        at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:18
7)
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
        at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)
        at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:485)
        at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:395)
        at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
        at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3496)
        at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
        at weblogic.security.service.SecurityManager.runAs(Unknown Source)
        at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2180)
        at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2086)
        at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1406)
        at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
        at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
[2011-04-29 15:57:29,802] WARN  com.opensymphony.xwork2.ognl.OgnlValueStack        - Error setting expression 'beanList(
1).name' with value '[Ljava.lang.String;@1f848d1'
ognl.OgnlException: target is null for setProperty(null, "name", [Ljava.lang.String;@1f848d1)
        at ognl.OgnlRuntime.setProperty(OgnlRuntime.java:1651)
        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)
. . . 
repeated several times
Is this a problem with type conversion?


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


Re: Struts 2: Does the Indexed List Example Work?

Posted by Chris Pratt <th...@gmail.com>.
Try: value="%{name}"
  (*Chris*)
On Apr 29, 2011 12:14 PM, "Dave Newton" <da...@gmail.com> wrote:
> Try the square brackets again.
>
> On Fri, Apr 29, 2011 at 2:52 PM, Joe <fu...@lycos.com> wrote:
>> Chris Pratt wrote:
>>
>> Oh, duh, I'm not sure why I didn't see it before.  You can either just
use
>> %{id} and then you don't need the id="bean" on the s:iterate tag.  Or,
you
>> can use %{#bean.id}.
>>
>> No joy.  If I use the tags like so:
>> <s:iterator value="beanList">
>>  <s:textfield theme="simple" name="beanList(%{id}).name" /><br>
>> </s:iterator>
>>
>> the page source looks like what I'd expect, but no values in the text
fields:
>> <input type="text" name="beanList(1).name" value=""
id="prepTest_beanList(1)_name"/><br>
>>
>>
>> If I use the tags like so:
>> <s:iterator value="beanList" var="bean">
>>  <s:textfield theme="simple" name="beanList(%{#bean.id}).name" /><br>
>> </s:iterator>
>>
>> The page source is the same:
>> <input type="text" name="beanList(1).name" value=""
id="prepTest_beanList(1)_name"/><br>
>>
>>
>> Dave Newton-6 wrote:
>> Ah, older version of S2--yeah.
>>
>> Not that old.  I'm using 2.2.1.
>>
>> I really appreciate your time looking at this, guys!
>>
>> ---------------------------------------------------------------------
>> 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: Struts 2: Does the Indexed List Example Work?

Posted by Dave Newton <da...@gmail.com>.
Try the square brackets again.

On Fri, Apr 29, 2011 at 2:52 PM, Joe <fu...@lycos.com> wrote:
> Chris Pratt wrote:
>
> Oh, duh, I'm not sure why I didn't see it before.  You can either just use
> %{id} and then you don't need the id="bean" on the s:iterate tag.  Or, you
> can use %{#bean.id}.
>
> No joy.  If I use the tags like so:
> <s:iterator value="beanList">
>  <s:textfield theme="simple" name="beanList(%{id}).name" /><br>
> </s:iterator>
>
> the page source looks like what I'd expect, but no values in the text fields:
> <input type="text" name="beanList(1).name" value="" id="prepTest_beanList(1)_name"/><br>
>
>
> If I use the tags like so:
> <s:iterator value="beanList" var="bean">
>  <s:textfield theme="simple" name="beanList(%{#bean.id}).name" /><br>
> </s:iterator>
>
> The page source is the same:
> <input type="text" name="beanList(1).name" value="" id="prepTest_beanList(1)_name"/><br>
>
>
> Dave Newton-6 wrote:
> Ah, older version of S2--yeah.
>
> Not that old.  I'm using 2.2.1.
>
> I really appreciate your time looking at this, guys!
>
> ---------------------------------------------------------------------
> 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: Struts 2: Does the Indexed List Example Work?

Posted by Joe <fu...@lycos.com>.
Chris Pratt wrote:

Oh, duh, I'm not sure why I didn't see it before.  You can either just use
%{id} and then you don't need the id="bean" on the s:iterate tag.  Or, you
can use %{#bean.id}. 

No joy.  If I use the tags like so:
<s:iterator value="beanList">
  <s:textfield theme="simple" name="beanList(%{id}).name" /><br>
</s:iterator>

the page source looks like what I'd expect, but no values in the text fields:
<input type="text" name="beanList(1).name" value="" id="prepTest_beanList(1)_name"/><br>


If I use the tags like so:
<s:iterator value="beanList" var="bean">
  <s:textfield theme="simple" name="beanList(%{#bean.id}).name" /><br>
</s:iterator>

The page source is the same:
<input type="text" name="beanList(1).name" value="" id="prepTest_beanList(1)_name"/><br>


Dave Newton-6 wrote:
Ah, older version of S2--yeah.

Not that old.  I'm using 2.2.1.

I really appreciate your time looking at this, guys!

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


Re: Struts 2: Does the Indexed List Example Work?

Posted by Joe <fu...@lycos.com>.
Chris Pratt wrote:

Shouldn't that be:
<s:textfield theme="simple" name="beanList[%{bean.id}].name"/> 


I changed my JSP as indicated and still didn't get values in the text boxes.  The source of the page looks like this:

<input type="text" name="beanList[].name" value="" id="prepTest_beanList___name"/><br>

which to me indicates that it is having a problem with the "bean.id" part of the equation.
Wouldn't square brackets indicate an index into the list, rather than obtaining an element by the id property?

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


Re: Struts 2: Does the Indexed List Example Work?

Posted by Joe <fu...@lycos.com>.

On Apr 29, 2011, Dave Newton-6 wrote: 
>What does the JSP look like?
>Dave 

Sorry, it is the same as the example with the exception of fixing a minor typo in the textfield tag (the example is missing a colon):

<%@ taglib prefix="s" uri="/struts-tags"%>
<head>    
</head>  
<body> 
<s:form method="post" theme="xhtml">   
<p>Experimenting with indexed values (List Values)
<p> 
<s:iterator value="beanList" id="bean">
  <s:textfield theme="simple" name="beanList(%{bean.id}).name" /><br>
</s:iterator>
<p>
<s:submit theme="simple" action="saveTest" key="button.label.save" cssClass="butStnd"/>
</s:form>
</body>
</html>

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


Re: Struts 2: Does the Indexed List Example Work?

Posted by Dave Newton <da...@gmail.com>.
What does the JSP look like?

Dave

On Fri, Apr 29, 2011 at 11:02 AM, Joe <fu...@lycos.com> wrote:
> private List beanList = new ArrayList();

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