Dreamer
Dreamer

Reputation: 7551

Property '0' not found on type java.lang.String

I am working on a SpringMVC 3 and Roo project. Now there is a web tier dead end. Basically it is a type conversion issue, driving me mad

I try to pass the record counter when iterate a list of table rows(here is SystemSettings table, then each row is a system setting). In the jspx file, I made the following looping:

<form:form action="${form_url}" method="post" modelAttribute="formSettings">
        <c:forEach items="${settings}" var="item" varStatus="status">
            <c:set value="${item.actionType}" var="type"/>
            <c:set value="${item.name}" var="name"/>
            <c:set value="${item.setting}" var="value"/>
            <!--  -->
            <field:complex field="setting" id="l_com_transoftinc_vlm_carrierweb_domain_systemsetting_${name}" object="${item}" setting="${value}" type="${type}" cnt="${status.count-1}" formBacking="formSettings" z="user-managed"/>
        </c:forEach>

So that the status count can pass the counter value to the "complex.tagx". Here it is simplified like this:

<jsp:directive.attribute name="cnt" type="java.lang.Integer" required="false" rtexprvalue="true" description="counter variable" /> 
<c:choose>
      <c:when test="${fn:toLowerCase(type) eq 'checkbox'}">
        <input type="checkbox" name="${formBacking[cnt].field}" value="TRUE" checked="${fn:toLowerCase(setting) eq 'true' ? 'checked' : ''}"/>
      </c:when>
      <c:when test="${fn:toLowerCase(type) eq 'inputbox'}">
        <input type="input" name="${formBacking[cnt].field}" value="${setting}"/>
      </c:when>
    </c:choose>

I didn't put all the attributes here to make the code section too verbose. But I get very nasty exception telling me the counter (which of course returns 0 in the first looping) is not a type of String? I thought JSTL can automatically convert it. However, I know I use three variable to compose the component name may be not a good idea, but I am don't understand this exception, here it is, please help, thanks a lot!

May 14, 2012 6:39:59 PM org.apache.catalina.core.StandardWrapperValve invoke SEVERE: Servlet.service() for servlet [OptiVLM-CarrierWeb] in context with path [/OptiVLM-CarrierWeb] threw exception [Request processing failed; nested exception is org.apache.tiles.impl.CannotRenderException: ServletException including path '/WEB-INF/layouts/default.jspx'.] with root cause javax.el.PropertyNotFoundException: Property '0' not found on type java.lang.String at javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:237) at javax.el.BeanELResolver$BeanProperties.access$400(BeanELResolver.java:214) at javax.el.BeanELResolver.property(BeanELResolver.java:325) at javax.el.BeanELResolver.getValue(BeanELResolver.java:85) at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:67)

Upvotes: 1

Views: 9659

Answers (1)

BalusC
BalusC

Reputation: 1109422

This exception indicates that ${formBacking} is actually a java.lang.String, not an array or a List on which the indexed access by brace notation would work.

And indeed, you're specifying it as a plain vanilla string on the tag:

<field:complex ... formBacking="formSettings" />

Likely you meant it to be an EL expression instead:

<field:complex ... formBacking="${formSettings}" />

You only still need to make sure that it's really an array or a List.

Upvotes: 2

Related Questions