Object comes pro bean with all blank JSF fields

Asked

Viewed 162 times

0

I have a list of Predio objects that is being iterated in my xthml Then, for each iteration, I create a panel and in each panel I display the name of each of the predicates in the list and a button that calls a method that loads the Procedio(Predio predio) in the Bean. This method only loads the bean’s predicate attribute with the received argument. After that, a dialog is opened and the information of the clicked predicate is displayed. The item names are being rendered perfectly on the screen. However, when the dialog opens, the fields see blank. Can anyone imagine what it is? Follows 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

  • 1

    Ever tried to update the dialog panelGrid by clicking the? update="pnlDetailsPredicDialog"

1 answer

1

Tathian,

Your example contains several likely problems:

  1. Your dialog is inside a form?
  2. The method editaPredio is not in your ManagedBean or you didn’t put?
  3. Your commandButton shall process and update the necessary 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 don’t 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 matter of good practice and better visualization of your code:

  • carregaPredio for carregarPredio
  • editaPredio for editarPredio

Reference:

Browser other questions tagged

You are not signed in. Login or sign up in order to post.