struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oleg V Alexeev <go...@penza.net>
Subject Re[2]: Nested/Indexed Properties Now Supported
Date Sat, 06 Jan 2001 21:42:04 GMT
Hello Michael,

I try to use test form with 'prop' and 'index' properties -

public class TestForm extends ActionForm {
        protected String[] prop = new String[10];

        public void setProp(int index, String value) {
                prop[index] = value;
        }
        
        public String getProp(int index) {
                return prop[index];
        }

        public String[] getIndex() {
                return prop;
        }

        public void setIndex(String[] prop) {
                this.prop = prop;
        }
}

but for 'prop' indexed property I have exception on phase of
form-values populating

javax.servlet.jsp.JspException: Getter for property prop[4] threw exception: java.lang.ArrayIndexOutOfBoundsException
at org.apache.struts.taglib.form.BaseFieldTag.doStartTag(BaseFieldTag.java:186)
at _jsp._rusbiz__debug._test__jsp._jspService(/rusbiz.debug/test.jsp:28)
at com.caucho.jsp.JavaPage.service(JavaPage.java:89)
at com.caucho.jsp.JavaPage.subservice(JavaPage.java:83)
at com.caucho.jsp.Page.service(Page.java:409)
at com.caucho.server.http.Invocation.service(Invocation.java:257)
at com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:201)
at com.caucho.server.http.QRequestDispatcher.forward(QRequestDispatcher.java:159)
at com.caucho.server.http.QRequestDispatcher.forward(QRequestDispatcher.java:78)
at org.apache.struts.action.ActionServlet.processActionPerform(ActionServlet.java:1587)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1427)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:480)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:115)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:83)
at com.caucho.server.http.Invocation.service(Invocation.java:263)
at com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:201)
at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:235)
at com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java:154)
at com.caucho.server.TcpConnection.run(TcpConnection.java:142)
at java.lang.Thread.run(Thread.java:484)

and for 'index' indexed property I have exception on phase of
form loading too -

java.lang.ArrayIndexOutOfBoundsException
at java.lang.reflect.Array.get(Native Method)
at org.apache.struts.util.PropertyUtils.getIndexedProperty(PropertyUtils.java:297)
at org.apache.struts.util.PropertyUtils.getIndexedProperty(PropertyUtils.java:243)
at org.apache.struts.util.PropertyUtils.getNestedProperty(PropertyUtils.java:339)
at org.apache.struts.util.PropertyUtils.getProperty(PropertyUtils.java:366)
at org.apache.struts.util.BeanUtils.getScalarProperty(BeanUtils.java:555)
at org.apache.struts.taglib.form.BaseFieldTag.doStartTag(BaseFieldTag.java:177)
at _jsp._rusbiz__debug._test__jsp._jspService(/rusbiz.debug/test.jsp:28)
at com.caucho.jsp.JavaPage.service(JavaPage.java:89)
at com.caucho.jsp.JavaPage.subservice(JavaPage.java:83)
at com.caucho.jsp.Page.service(Page.java:409)
at com.caucho.server.http.Invocation.service(Invocation.java:257)
at com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:201)
at com.caucho.server.http.QRequestDispatcher.forward(QRequestDispatcher.java:159)
at com.caucho.server.http.QRequestDispatcher.forward(QRequestDispatcher.java:78)
at org.apache.struts.action.ActionServlet.processActionPerform(ActionServlet.java:1587)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1427)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:480)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:115)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:83)
at com.caucho.server.http.Invocation.service(Invocation.java:263)
at com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:201)
at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:235)
at com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java:154)
at com.caucho.server.TcpConnection.run(TcpConnection.java:142)
at java.lang.Thread.run(Thread.java:484)

Sunday, January 07, 2001, 12:24:55 AM, you wrote:

SM>  I'd suggest you follow the javabean naming conventions in your FormBean,
SM> which should look like this:

SM> public class TestForm extends ActionForm {
SM>         protected String[] prop = new String[10];

SM>         public void setProp(int index, String value) {
SM>                 prop[index] = value;
SM>         }
        
SM>         public String getProp(int index) {
SM>                 return prop[index];
SM>         }

SM>         public String[] getProp() {
SM>                 return prop;
SM>         }

SM>         public void setProp(String[] prop) {
SM>                 this.prop = prop;
SM>         }
SM> }

SM> Give that a try and tell me if it works

SM> -----Original Message-----
SM> From: Oleg V Alexeev
SM> To: Schachter, Michael
SM> Sent: 1/6/01 4:09 PM
SM> Subject: Re: Nested/Indexed Properties Now Supported

SM> Hello Michael,

SM> Sorry, but some questions.. I try to write test Form  with listed
SM> below indexed properties and this is not work...  What part of code is
SM> wrong?

SM> public class TestForm extends ActionForm {
SM>     protected HashMap test = new HashMap();
SM>     protected String[] ind = new String[10];

SM>     public void setProp( int index, String value ) {
SM>      test.put( new Integer( index ), value );
SM>     }

SM>     public String getProp( int index ) {
SM>      return (String)test.get( new Integer( index ) );
SM>     }

SM>     public String[] getIndex() {
SM>      return ind;
SM>     }
SM> }

SM> and test jsp page to use this form -

SM> <html><head>
SM> <%@ page contentType="text/html;charset=windows-1251" %>
SM> <%@ taglib uri="/WEB-INF/struts-form.tld" prefix="form" %>
SM> <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
SM> <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
SM> <%@ taglib uri="/WEB-INF/struts-template.tld" prefix="template" %>
SM> <%@ taglib uri="/WEB-INF/bcom.tld" prefix="bcom" %>
SM> </head>

SM> <body bgcolor="#F7E7CE" text="#510000" link="#800000" vlink="#800000"
SM> alink="#800000" topmargin="0" leftmargin="0">

SM> prop[4] = <%= request.getParameter("prop[4]") %><br>
SM> prop[2] = <%= request.getParameter("prop[2]") %><br>
SM> index[1] = <%= request.getParameter("index[1]") %><br>
SM> index[4] = <%= request.getParameter("index[4]") %><br>

SM> <form:form name="testForm" type="bcom.actions.TestForm" method="post"
action="test.do">>
SM>  <form:text property="prop[4]"/><br>
SM>  <form:text property="prop[2]"/><br>
SM>  <form:text property="index[1]"/><br>
SM>  <form:text property="index[4]"/><br>
SM>  <form:submit/>
SM> </form:form>

SM> </body>

SM> </html>


SM> Saturday, January 06, 2001, 10:24:20 PM, you wrote:

SM>> Although strangely there was no commit email, last night I committed
SM> changes
SM>> to BeanUtils, PropertyUtils, and BaseFieldTag that enable form
SM> elements to
SM>> have nested and indexed properties.  If you check CVS the latest
SM> code is
SM>> there.  Just letting everyone know.






-- 
Best regards,
 Oleg                            mailto:gonza@penza.net



Mime
View raw message