I wonder about the <p:pickList/>. I did everything perfect and runs the site but does not pass the object, just a string. If I put in a ITEMVALUE a STRING, he correctly returns the values ??that were on the other side of the list, the selected values. If the ITEMVALUE I try to pass an object the following error appears: [entidades.CategoriaProduto can not be cast to java.lang.String].
Anyone know how I can pass the object and not a string? INT is not going well, just a string.
My codes...
bean:
Code: Select all
public class ControleProduto {
Produto Produto = new Produto();
public List<Produto> lista = new ArrayList<Produto>();
RepositorioJPA<Produto> jpa = new RepositorioJPA<Produto>();
private UIData objDataTableProduto;
private ControleCategoriaProduto dao = new ControleCategoriaProduto();
private List<CategoriaProduto> source = new ArrayList<CategoriaProduto>();
private List<CategoriaProduto> target = new ArrayList<CategoriaProduto>();
private DualListModel<CategoriaProduto> categorias;
public ControleProduto(){
source = dao.listaCategoriaProdutos();
categorias = new DualListModel<CategoriaProduto>(source, target);
}
public String teste() {
System.out.println("source:" + getCategorias().getSource());
System.out.println("target:" + getCategorias().getTarget());
return "List";
}
public Produto getProduto() {
return Produto;
}
public void setProduto(Produto Produto) {
this.Produto = Produto;
}
public UIData getObjDataTableProduto() {
return objDataTableProduto;
}
public void setObjDataTableProduto(UIData objDataTableProduto) {
this.objDataTableProduto = objDataTableProduto;
}
public DualListModel<CategoriaProduto> getCategorias() {
return categorias;
}
public void setCategorias(DualListModel<CategoriaProduto> categorias) {
this.categorias = categorias;
}
public List<CategoriaProduto> getTarget() {
return target;
}
public void setTarget(List<CategoriaProduto> target) {
this.target = target;
}
public List<CategoriaProduto> getSource() {
return source;
}
public void setSource(List<CategoriaProduto> source) {
this.source = source;
}
}
my xhtml:
Code: Select all
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.prime.com.tr/ui"
xmlns:f="http://java.sun.com/jsf/core">
<h:form>
<p:tabView effect="opacity" effectDuration="normal"
style="border:0px">
<p:tab title="Cadastrar">
<p:pickList value="#{controleProduto.categorias}"
var="cat" itemLabel="#{cat.catNome}" itemValue="#{cat.catNome}" effect="bounce">
<f:facet name="sourceCaption">Categorias Disponíveis</f:facet>
<f:facet name="targetCaption">Categorias Pertencentes</f:facet>
</p:pickList>
<p:commandButton value="Testes" onclick="teste.show()"
type="button" image="ui-icon ui-icon-trash" />
<p:confirmDialog widgetVar="teste" header="Confirmação"
message="teste?" showEffect="explode"
hideEffect="explode" severity="alert" modal="false">
<p:commandButton value="Sim" update="mensagens"
onclick="teste.hide()"
actionListener="#{controleProduto.teste}" />
<p:commandButton value="Não" onclick="teste.hide()"
type="button" />
</p:confirmDialog>
</p:tab>
</p:tabView>
</h:form>
</html>
the way up is working, but returns a list with the names of the categories, I would return a list of category objects.
If I change the following line:
Code: Select all
<p:pickList value="#{controleProduto.categorias}"
var="cat" itemLabel="#{cat.catNome}" itemValue="#{cat.catNome}" effect="bounce">
to:
<p:pickList value="#{controleProduto.categorias}"
var="cat" itemLabel="#{cat.catNome}" itemValue="#{cat}" effect="bounce">
I appreciate the help.