Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 7106
  • Last Modified:

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>
0
chaitu chaitu
Asked:
chaitu chaitu
1 Solution
 
fargoCommented:
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
0
 
fargoCommented:
>>  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
0
 
javaoptimizerCommented:
<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
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
chaitu chaituAuthor Commented:
i already tried its not working
0
 
KuldeepchaturvediCommented:
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...
0
 
chaitu chaituAuthor 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;

            }

            
0
 
fargoCommented:
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
0
 
chaitu chaituAuthor 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
0
 
fargoCommented:
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
0
 
chaitu chaituAuthor Commented:
how do i change jstl handling
0
 
fargoCommented:
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
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now