We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

The "." operator was supplied with an index value of type "java.lang.String" to be applied to a List or array, but that value cannot be converted to an integer

chaitu chaitu
on
Medium Priority
7,579 Views
Last Modified: 2008-01-09
       javax.servlet.ServletException: The "." operator was supplied with an index value of type "java.lang.String" to be applied to a List or array, but that value cannot be converted to an integer.

          public ModelAndView handleRequest(HttpServletRequest request,
                                      HttpServletResponse response) throws
            Exception {

      return new ModelAndView("ViewAllMyObjects","myObjectModel",empObjectDao.getAllMyObjectVOs(1));

      }

empObjectDao.getAllMyObjectVOs(1) return Object ;in that object myObjectModel.Results returns List ;


javax.servlet.ServletException: The "." operator was supplied with an index value of type "java.lang.String" to be applied to a List or array, but that value cannot be converted to an integer.


<c:forEach items="${myObjectModel.Results}" var="mobj" varStatus="status">
  <tr>
    <td> <a href="MyObjectForm.html?id=${mobj.id}">${mobj.id}</a> </td>
    <td> ${mobj.name}</td>
    <td> ${mobj.address}</td>
    <td> ${mobj.email}</td>
    <td> ${mobj.phone}</td>
   </tr>
</c:forEach>
Comment
Watch Question

Commented:
Hi,

As you yourself said that the return from myObjectModel.Results is a List. Is it a List of Beans??? Or just a plain List.

I believe, the returned List is a plain List and NOT the list of beans. In that case, mobj.id will not be able to identify "id".

fargo

Commented:
>>  In that case, mobj.id will not be able to identify "id".

should be  
>In that case, mobj.id will not be able to identify "id", "name", "address"..etc

fargo
<c:forEach items="${myObjectModel.Results}" var="mobj" varStatus="status">
  <tr>
    <td> <a href='MyObjectForm.html?id=<c:out value="${mobj.id}"/>' ><c:out value="${mobj.id}"/></a> </td>
    <td> <c:out value="${mobj.name}" /></td>
    <td> <c:out value="${mobj.address}"/></td>
    <td> <c:out value="${mobj.email}"/></td>
    <td> <c:out value="${mobj.phone}"/></td>
   </tr>
</c:forEach>

try this out , it will most probably work.

Cheers

Author

Commented:
i already tried its not working
just to check what mobj is returning,
print it on the page..

<c:forEach items="${myObjectModel.Results}" var="mobj" varStatus="status">
<td> <c:out value="${mobj}" /></td>
</c:forEach>

I think Fargo is correct in his assumption that the list being returned is not of beans...

Author

Commented:
dataBaseList is the List of beans;dataBaseList is added into mainList(this is another arraylist) and it is assigned it to searchModel.searchResults;
   
   
    public SearchModel getAllMyObjectVOs(SearchModel searchModel) {


                  while (maxRows > i++) {
                        dataBaseList.add((Employee)scr.get(0));

                        }

                               mainList.add(dataBaseList);
                               searchModel.totalRecords= l.size();
                               searchModel.searchResults = mainList;

return searchModel;

            }

            

Commented:
Hi,

So it means you have list of list. It definitely means you have to change the handling in JSTL tags. OR in the first place why do u need to add it in another list ?

fargo

Author

Commented:
in dataBaseList  i have only Employee objects and also i need totalrecords and pagenumber that is not there in employee object so i have taken another object i.e searchModel

Commented:
Hi,

May be making a copy is better for you and you need not to change the jstl handling

public SearchModel getAllMyObjectVOs(SearchModel searchModel) {


               while (maxRows > i++) {
                    dataBaseList.add((Employee)scr.get(0));

                    }

                      Object[] contents = dataBaseList.toArray();
                      Object[] newArray = new Object[contents.length];
                      System.arraycopy(contents, 0, newArray, 0, contents.length);

                          searchModel.totalRecords= l.size();
                          searchModel.searchResults = Arrays.asList(newArray);

return searchModel;

          }


fargo

Author

Commented:
how do i change jstl handling
Commented:
probably you have to iterate twice...like below.. i personally don't use jstl tags..but the below guess should work..

 <c:forEach items="${myObjectModel.Results}" var="mobj" varStatus="status">
 <c:forEach items="${mobj}" var="mobjtest" varStatus="statustest">
  <tr>
    <td> <a href='MyObjectForm.html?id=<c:out value="${mobjtest.id}"/>' ><c:out value="${mobjtest.id}"/></a> </td>
    <td> <c:out value="${mobjtest.name}" /></td>
    <td> <c:out value="${mobjtest.address}"/></td>
    <td> <c:out value="${mobjtest.email}"/></td>
    <td> <c:out value="${mobjtest.phone}"/></td>
   </tr>
</c:forEach>
</c:forEach>

fargo

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.