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>
LVL 20
chaitu chaituAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.