Link to home
Create AccountLog in
Avatar of chaitu chaitu
chaitu chaituFlag for India

asked on

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

       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>
Avatar of fargo
fargo

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
>>  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
Avatar of chaitu chaitu

ASKER

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...
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;

            }

            
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
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
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
how do i change jstl handling
ASKER CERTIFIED SOLUTION
Avatar of fargo
fargo

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer