Object comes pro bean with all fields blank JSF

0

I have a list of object objects that is being iterated in my xthml There, for each iteration, I create a panel and in each panel I display the name of each of the properties in the list and a button that calls a method loadPredio in the Bean. This method only loads the bean's farm attribute with the received argument. After that, a dialog is opened and the information of the property clicked is displayed. Item names are rendered perfectly on the screen. However, when the dialog opens, the fields are blank. Can anyone imagine what it is? Here is the code:

<c:forEach items="#{predioBean.listaPredios}" var="entry">
    <h:panelGroup>
        <h:outputText value="#{entry.nome}" />
        <p:commandButton actionListener="#{predioBean.carregaPredio(entry)}"  oncomplete="PF('DetalhesPredioDialog').show();"/>
    </h:panelGroup> 
</c:forEach>

 <!-- ********** DIALOG DETALHES PREDIO ********** --> 
            <p:dialog header="#{predioBean.predio.nome}"  widgetVar="DetalhesPredioDialog" modal="false" resizable="false" width="400" height="150" >
                <h:panelGrid id="pnlDetalhesPredioDialog" style="margin-bottom:10px;" columns="2">
                    <h:outputLabel value="#{msg['nome']}"  />
                    <p:inputText size="30" id="nomePredio" value ="#{predioBean.predio.nome}" />

                    <h:outputLabel value="#{msg['descricao']}"  />
                    <p:inputText size="30" id="descricaoPredio" value ="#{predioBean.predio.descricao}"/>

                    <h:outputLabel value="#{msg['endereco']}"  />
                    <p:inputText size="30" id="enderecoBanco" value ="#{predioBean.predio.endereco}" />

                </h:panelGrid>
                <h:panelGrid>
                    <p:commandButton value="#{msg['edita']}" icon="ui-icon-pencil" action="#{predioBean.editaPredio}"/>
                </h:panelGrid>
            </p:dialog>

Now the Bean:

@ManagedBean
@SessionScoped
public class PredioBean {

private Predio predio;
private List<Predio> listaPredios;
private PredioDAO predioDao;

@PostConstruct
public void initialize() {
    this.predio = new Predio();
    this.predioDao = new PredioDAO();
    this.listaPredios = contaErrosDoPredio();
}

public void carregaPredio(Predio predio) {
    this.predio = predio;
}

}

Thank you

    
asked by anonymous 30.11.2017 / 17:40

1 answer

1

Tathiana,

Your example contains several likely problems:

  • Is your dialog within a form ?
  • Is the editaPredio method not in your ManagedBean or did you not?
  • Your commandButton should process and update the required information
  • If you want to use ajax, which makes more sense, your button should look something like this:

    <p:commandButton value="#{msg['edita']}" icon="ui-icon-pencil" 
                     action="#{predioBean.editaPredio}" 
                     process="@this pnlDetalhesPredioDialog" update="@form"/>
    

    If you do not want to use ajax, simply add ajax="false" :

    <p:commandButton value="#{msg['edita']}" icon="ui-icon-pencil" 
                     action="#{predioBean.editaPredio}" ajax="false"/>
    

    Try to use function names with the action it does, preferably using verbs in the infinitive, just a question of good practice and better visualization of your code:

    • carregaPredio to carregarPredio
    • editaPredio to editarPredio

    Reference:

    26.01.2018 / 14:49