1
Trying to list items in a ui:repeat that is inside another, and need to use as parameter the id of the ui:repeat item more external. But I can’t do it because the following error is occurring:
java.lang.ClassCastException: java.lang.String cannot be cast to [Ljava.lang.Object;
UI:REPEAT
<ui:repeat var="itemRelato" value="#{livroOrdemController.relatos}"
varStatus="status">
<p:panel id="panelRelatos">
<h:outputLabel value="Data do Relato: "/>
<h:outputText value="#{itemRelato.dataOcorrencia}">
<f:convertDateTime pattern="dd/MM/yyyy" />
</h:outputText>
<br />
<h:outputLabel value="Tipo do Relato: "/>
<h:outputText value="#{itemRelato.tipoRelato.descricao}"/>
<br />
<h:outputLabel value="Fase da Obra: "/>
<h:outputText value="#{itemRelato.faseObraServico.descricao}"/>
<br />
<h:outputLabel value="Inicio da Fase: "/>
<h:outputText value="#{itemRelato.dataIncioFase}">
<f:convertDateTime pattern="dd/MM/yyyy" />
</h:outputText>
<br />
<h:outputLabel value="Términio da Fase: "/>
<h:outputText value="#{itemRelato.dataTerminioFase}">
<f:convertDateTime pattern="dd/MM/yyyy" />
</h:outputText>
<br />
<h:outputLabel value="Descrição: "/><br />
<h:outputText value="#{itemRelato.descricao}"/>
<br />
<b>
<h:outputLabel value="Retificações/Complementos: "/>
</b>
<ui:repeat var="itemRetificacao" value="#{livroOrdemController.recuperarRetificacoes(itemRelato.idRelato)}"
varStatus="statusRetificacao">
<li>
<h:outputText value="#{itemRetificacao.descricao}"/>
</li>
</ui:repeat>
<br />
<p:commandButton value="Retificar Relato"
update="#{livroOrdemController.componentes}"
onclick="dialogRetificacao.show();"
process="@this">
<f:setPropertyActionListener value="#{itemRelato}" target="#{livroOrdemController.relatoASerRetificado}"/>
</p:commandButton>
Controller Listing Method
public List<RetificacaoRelato> recuperarRetificacoes(Long idRelato) {
List<RetificacaoRelato> retificacoes = new ArrayList<RetificacaoRelato>();
Map<String, Object> params = new HashMap<String, Object>();
String queryRetificacoes = "SELECT rr.descricao FROM RetificacaoRelato rr "
+ "WHERE rr.relato_idrelato = :idrelato";
params.put("idrelato", idRelato);
List<Object[]> objects = objectDao.listPesqQuery(queryRetificacoes, params);
for (Object[] o : objects) {
RetificacaoRelato retificacaoRelatoTemp = new RetificacaoRelato();
retificacaoRelatoTemp.setDescricao((String) o[0]);
retificacoes.add(retificacaoRelatoTemp);
}
return retificacoes;
ListPesqQuery method
@Override
public List<T> listPesqQuery(String query, Map<String, Object> params) {
Query q = getEntityManager().createNativeQuery(query);
for (String chave : params.keySet()) {
q.setParameter(chave, params.get(chave));
}
return q.getResultList();
}
[Ljava.lang.Object;
is the class nameObject[]
. I suspect the functionobjectDao.listPesqQuery
is returning a list ofString
s and not a list ofObject[]
. Could post the codeobjectDao.listPesqQuery
to confirm?– Luís Gabriel de Andrade
I edited the question with the method
– user70765
The method
Query.getResultList
returns aList
faceless. I don’t know how this method works internally, however, as it is a query that returns only one value per record, I believe it can do type casting forString
automatically; If you wanted to force a return type, you can use the classTypedQuery
implementing the interfaceQuery
.– Luís Gabriel de Andrade