How to set a Spinner value on an object

1

I have the following table:

<p:dataTable id="tabelaDisciplinasSelelecionadas" var="disciplina" value="#{disciplinaBean.droppedDisciplinas}"
                                        rendered="#{not empty disciplinaBean.droppedDisciplinas}">

    <p:column headerText="Id">
        <h:outputText value="#{disciplina.idDisciplina}" />
    </p:column>

    <p:column headerText="Nome">
        <h:outputText value="#{disciplina.nomeDisciplina}"/>
    </p:column>

    <p:column headerText="Código">
        <h:outputText value="#{disciplina.codigoDisciplina}" />
    </p:column>

    <p:column headerText="Vagas">
        <h:outputLabel for="vagas" value="Vagas: " />
            <p:spinner id="vagas" value="#{editalDisciplinaBean.editalDisciplina.vagas}"  />
    </p:column>


    <p:column style="width:32px">
        <p:commandButton update=":formDisciplina:display" oncomplete="PF('disciplinaDialog').show()" icon="ui-icon-search">
            <f:setPropertyActionListener value="#{disciplina}"  target="#{disciplinaBean.disciplinaSelecionada}" />
                </p:commandButton>
            </p:column>

</p:dataTable>

EditalDisciplinaBean.java

ManagedBean(name="editalDisciplinaBean")
@SessionScoped

public class EditalDisciplinaBean {

    private EditalDisciplina editalDisciplina;
    private EditalDisciplinaDAO editalDisciplinaDAO = new EditalDisciplinaDAO();
    private List<EditalDisciplina> lista;
    private List<EditalDisciplina> listaFiltro;

    private Edital edital;
    private Disciplina disciplina;

    public EditalDisciplina getEditalDisciplina() {
        if (editalDisciplina == null)
            editalDisciplina = new EditalDisciplina();
        return editalDisciplina;
    }

    public void setEditalDisciplina(EditalDisciplina editalDisciplina) {
        this.editalDisciplina = editalDisciplina;
    }

    public EditalDisciplinaDAO getDisciplinaDAO() {
        return editalDisciplinaDAO;
    }

    public void setDisciplinaDAO(EditalDisciplinaDAO disciplinaDAO) {
        this.editalDisciplinaDAO = disciplinaDAO;
    }

    public List<EditalDisciplina> getLista() {
        if (lista == null)
            lista = editalDisciplinaDAO.getListaEditalDisciplina();
        return lista;
    }

    public void setLista(List<EditalDisciplina> lista) {
        this.lista = lista;
    }

    public List<EditalDisciplina> getListaFiltro() {
        return listaFiltro;
    }

    public void setListaFiltro(List<EditalDisciplina> listaFiltro) {
        this.listaFiltro = listaFiltro;
    }

    public Edital getEdital() {
        return edital;
    }

    public void setEdital(Edital edital) {
        this.edital = edital;
    }

    public EditalDisciplinaDAO getEditalDisciplinaDAO() {
        return editalDisciplinaDAO;
    }

    public void setEditalDisciplinaDAO(EditalDisciplinaDAO editalDisciplinaDAO) {
        this.editalDisciplinaDAO = editalDisciplinaDAO;
    }

    public Disciplina getDisciplina() {
        return disciplina;
    }

    public void setDisciplina(Disciplina disciplina) {
        this.disciplina = disciplina;
    }

}

Jobs is an attribute of my Entity EditalDiscipline (which is a many relationship table for many Edict and Discipline). So for each row of the table there appears a Spinner for me to insert as many vacancies for that discipline, but it happens that the vacancies do not stay in the discipline, so I can not use the variable of dataTable, so when I give Submit all the EditalDisciplina objects are with the same number of vacancies. How do I make each EditalDiscipline have its number of vacancies?

    
asked by anonymous 29.01.2015 / 05:43

1 answer

1

You can have a method that takes parameters in your bean instead of using property as you are doing.

Then the method would look up the number according to the displine passed by parameter.

The code would look something like this:

<p:column headerText="Vagas">
    <h:outputLabel for="vagas" value="Vagas: " />
        <p:spinner id="vagas" value="#{editalDisciplinaBean.vagasPorDisciplina(idDisciplina)}"  />
</p:column>

The method can also receive the displine itself as a parameter:

<p:column headerText="Vagas">
    <h:outputLabel for="vagas" value="Vagas: " />
        <p:spinner id="vagas" value="#{editalDisciplinaBean.vagasPorDisciplina(disciplina)}"  />
</p:column>

I estimate that currently editalDisciplinaBean contains an instance of a EditalDisciplina . Instead, it would not have any instance of an editableDiscipline but rather would look for this instance as the passed parameter.

If the id of the displine was passed, it would look something like this:

public int vagasPorDisciplina(int idDisciplina) {
    return entityManager.find(EditalDisciplina.class, idDisciplina).getSingleResult().getVagas();
}    
    
29.01.2015 / 14:35