Pessoal, boa noite.
Vejam se conseguem me ajudar, pois estou tentando várias alterações sem sucesso…
Ao realizar a minha pesquisa, está aparecendo o seguinte erro:
Caused by: java.lang.IllegalArgumentException: You have attempted to set a value of type class java.lang.Integer for parameter codigo with expected type of class java.lang.String from query string
Vlw de qualquer forma.
Segue abaixo os códigos:
index.xhtml
<h:body>
<f:view>
<h:form>
<p:growl autoUpdate="true" showDetail="true" showSummary="true"/>
<h:form id="pesquisaForm">
<p:panel header="Pesquisa Cliente" style="width:600px">
<br></br>
<h:panelGrid columns="2">
<h:outputLabel value="Código Cliente:" for="codigo"/>
<p:inputText id="codigo" value="#{clienteController.codigo}" size="8" required="true"/>
</h:panelGrid>
<br></br>
<p:commandButton value="Consultar" action="#{clienteController.pesquisar()}" update=":msgs lista" ajax="false"/>
</p:panel>
</h:form>
</h:form>
</f:view>
</h:body>
</html>
classe cliente
@Entity
@Table(name = "CLI")
public class Cliente implements Serializable {
@Id
@Column(name = "CDCLI")
String codigo;
@Column(name = "RASCL")
private String razaoSocial1;
public String getCodigo() {
return codigo;
}
public void setCodigo(String codigo) {
this.codigo = codigo;
}
public String getRazaoSocial1() {
return razaoSocial1;
}
public void setRazaoSocial1(String razaoSocial1) {
this.razaoSocial1 = razaoSocial1;
}
public String getRazaoSocial() {
return razaoSocial1.trim() + razaoSocial2.trim();
}
public String getRazaoCodigo() {
return getRazaoSocial() + " " + codigo;
}
@Override
public int hashCode() {
int hash = 3;
hash = 97 * hash + (this.codigo != null ? this.codigo.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Cliente other = (Cliente) obj;
if ((this.codigo == null) ? (other.codigo != null) : !this.codigo.equals(other.codigo)) {
return false;
}
return true;
}
@Override
public String toString() {
return codigo;
}
}
clienteFacade
@Stateless
public class ClienteFacade {
protected EntityManager getEntityManager() {
return em;
}
public void edit(Cliente c) {
getEntityManager().merge(c);
}
public List<Cliente> findAll() {
return getEntityManager()
.createQuery("SELECT c FROM Cliente c", Cliente.class
)
.getResultList();
}
public List<Cliente> findByNome(String codigo) {
Query q = getEntityManager().createQuery("SELECT c FROM Cliente c WHERE c.codigo = :codigo", Cliente.class);
q.setParameter("codigo", Integer.parseInt(codigo));
return q.getResultList();
}
}