Values to picklist

UI Components for JSF
Post Reply
Andre Froes
Posts: 155
Joined: 16 Mar 2011, 17:24
Location: Brazil - Curitiba

19 Apr 2011, 14:21

Hi everyone, do I need nessessarely to pass a dualist to picklist or can I assign any other object?? i.e.: list, set or map

I'm having problem when trying to pass a value to a picklist. The query works fine, but when i set it to the picklist, it doesn't work at all.
here it is:

Code: Select all

 private DualListModel<FunFuncionario> dualFunci;

    public DualListModel<FunFuncionario> getDualFunci() {
        return dualFunci;
    }

    public void setDualFunci(DualListModel<FunFuncionario> dualFunci) {
        this.dualFunci = dualFunci;
    }

    public Controle() {
        log = new Logging("Demandas");
    }

    public DualListModel<FunFuncionario> getCarregaGerentes(){
        ArrayList lst = new ArrayList();
        lst.add(8598);
        lst.add(4345);
        lst.add(4636);
        List<FunFuncionario> listaFunci = new ArrayList<FunFuncionario>();
        List<FunFuncionario> listaFunciDestino = new ArrayList<FunFuncionario>();
        listaFunci = cdao.getFromNamedQueryParametrosOrdenados("FunFuncionario.findGerDepe", lst);
        //at this point, listaFunci does have the values, i've tested it
        dualFunci = new DualListModel<FunFuncionario>(listaFunci, listaFunciDestino);
        return dualFunci;
    }

this is the xhtml:

Code: Select all

        <h:form>
            <p:pickList value="#{controle.dualFunci}" var="item" itemLabel="#{item.source.nome}" itemValue="#{item.source.matricula}">
                <f:facet name="sourceCaption">Gerentes Disponíveis</f:facet>
                <f:facet name="targetCaption">Responsáveis</f:facet>
            </p:pickList>
        </h:form>
at itemLabel and itemValue, when I type in #{item. } it doesn't brings any value of my FunFuncionario bean


the FunFuncionario bean:

Code: Select all

@Entity
@Table(name = "fun_funcionario", catalog = "intranet", schema = "")
@NamedQueries({
    @NamedQuery(name = "FunFuncionario.findGerDepe", query = "SELECT f FROM FunFuncionario f where f.codDependencia = ?1 and (f.funCargo.codCargo = ?2 or f.funCargo.codCargo = ?3)")
    })
public class FunFuncionario implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "matricula")
    private String matricula;
    @Basic(optional = false)
    @Column(name = "cod_dependencia")
    private int codDependencia;
    @Basic(optional = false)
    @Column(name = "nome")
    private String nome;
    @Column(name = "nome_guerra")
    private String nomeGuerra;
    @Basic(optional = false)
    @Column(name = "dt_nascimento")
    @Temporal(TemporalType.DATE)
    private Date dtNascimento;
    @Basic(optional = false)
    @Column(name = "tipo_funcionario")
    private String tipoFuncionario;
    @Basic(optional = false)
    @Column(name = "excluido")
    private String excluido;
    @Column(name = "tel_trabalho")
    private String telTrabalho;
    @Column(name = "tel_residencia")
    private String telResidencia;
    @Column(name = "tel_celular")
    private String telCelular;
    @Column(name = "tel_fax")
    private String telFax;
    @Column(name = "emailbb")
    private String emailbb;
    @Column(name = "email")
    private String email;
    @Column(name = "endereco")
    private String endereco;
    @Column(name = "endereco_alt")
    private String enderecoAlt;
    @JoinColumn(name = "cod_divisao", referencedColumnName = "cod_divisao")
    @ManyToOne
    private FunDivisao funDivisao;
    @JoinColumn(name = "cod_cargo", referencedColumnName = "cod_cargo")
    @ManyToOne(optional = false)
    private FunCargo funCargo;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "funFuncionario")
    private Set<DemResponsaveis> demResponsaveisSet;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "funFuncionario")
    private Set<DemHistorico> demHistoricoSet;

    public FunFuncionario() {
    }

    public FunFuncionario(String matricula) {
        this.matricula = matricula;
    }

    public FunFuncionario(String matricula, int codDependencia, String nome, Date dtNascimento, String tipoFuncionario, String excluido) {
        this.matricula = matricula;
        this.codDependencia = codDependencia;
        this.nome = nome;
        this.dtNascimento = dtNascimento;
        this.tipoFuncionario = tipoFuncionario;
        this.excluido = excluido;
    }

/* getters and setters */
PrimeFaces 3.5 | Glassfish 3.1 | Mojarra 2.1.5 (JSF 2.1)
Netbeans 7.2.1 | JDK1.7 | Java EE 6 | SQL Server 2008
Win7 64 bits | Firefox 10 - Chrome - IE (all unfortunately)

Clemiou
Posts: 10
Joined: 06 Apr 2011, 10:37

21 Apr 2011, 10:32

Hi,

In the following primefaces showcase example, they use a converter for Pojo support.

http://www.primefaces.org/showcase/ui/picklist.jsf

Did you try that?

healeyb
Posts: 365
Joined: 07 Apr 2010, 16:05

21 Apr 2011, 11:18

You're specifying itemLabel and itemValue as item.source.nome, just
have item.nome & item.matricula. That should do it.

[edit] set the itemLabel to #{item.nome} and the value to #{item}.
You will need a converter as mentioned.

Regards,
Brendan.

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 54 guests