Erro ao tentar utilizar "el" em loop

3 respostas
E

Pessoal, tenho um objeto do tipo Pessoal, que representa os funcionários (que são motoristas) de uma empresa. Coloco alguns objetos desse tipo numa List, e depois seto um atributo:

List motoristas = importacaoService.findMotoristas();
request.setAttribute("motoristas", motoristas);

Seto um atributo para poder apresentar os dados:

<td nowrap="nowrap">
       &lt;bean:message key="importacao.motorista" /&gt;:<br>
	&lt;html:select property="pesMat" onchange="clearContainer('datatables');"&gt;
	&lt;html:option value="0"&gt;(Selecione um motorista)&lt;/html:option&gt;
	   &lt;c:forEach items="${motoristas}" var="motorista"&gt;
	       &lt;html:option value="${motorista.pesMat}"&gt;${motorista.pesNom}&lt;/html:option&gt;
	   &lt;/c:forEach&gt;
	&lt;/html:select&gt;
&lt;/td&gt;

até ae tudo bem, mas quando tento acessar o JSP para apresentar os dados, recebo o seguinte erro referente a linha <html:option value="${motorista.pesMat}">${motorista.pesNom}</html:option>:

javax.servlet.ServletException: javax.servlet.jsp.JspException: 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.

oq estou fazendo de errado?

3 Respostas

Tomassoni

Cara pq não usa a displaytag http://displaytag.homeip.net/displaytag-examples-1.1/example-styles.jsp

Seria parecido com isso:

<!-- Montagem da displaytag, colunas e seus conteudos -->
                    <display:table  name="motoristas" sort="list" defaultsort="1" pagesize="10"
                                    requestURI="SUA_ACAO" export="false" >            
                        <display:column property="pesMat" title="Matricula"   sortable="true" style="width: 580px" />            
                        <display:column property="pesNom" title="Nome"  sortable="true" style="width: 580px"/>          
                    </display:table>
E

or enquanto utilizar displaytag aqui nessa parte do sistema não daria certo, estou preso a esse modelo…

adriano.ferranti

Se o que estiver à esquerda dos colchetes for um array ou um List - e se o índice for uma string literal, o indice é forçado para int.

O que está retornando o método:

importacaoService.findMotoristas();

???

Criado 15 de maio de 2007
Ultima resposta 15 de mai. de 2007
Respostas 3
Participantes 3