Change Dialog is not displaying the data

1

I have a maven project that is using jsf, jpa and primefaces in which there is a dialog that is being used to update the data, except that the inputText is empty when it is called instead of appear the data in it (which is defined in the managedbean) ... How do I get around this?

My dialog     

<h:form>
    <p:dialog widgetVar="dialog" header="Effects" showEffect="explode"
        hideEffect="bounce" height="100" id="dialog">
        <p:panelGrid columns="2">
            <h:outputText value="Message" />
            <p:inputText value="#{growlView.message.message}"></p:inputText>
        </p:panelGrid>
        <p:commandButton
            action="#{growlView.save()}"
            value="Atualizar" onclick="PF('dialog').hide();" update=":listForm:grid, dialog" ></p:commandButton>
    </p:dialog>
</h:form>

My listing where the dialog is called     

    Hello Word

<h:form id="listForm">
<p:growl id="growl" showDetail="true" sticky="true" autoUpdate="true"/>
    <p:dataGrid value="#{growlView.allMessages}" var="bean" id="grid">
        <p:panelGrid columns="4">
            <h:outputText value="Messagem:" />
            <h:outputText value="#{bean.message}" />
            <p:commandButton value="Alterar" onclick="PF('dialog').show();"
                action="#{growlView.preprarUpdate(bean)}"></p:commandButton>
            <p:commandButton value="Excluir"
                action="#{growlView.deleteMessage(bean)}" update="grid"></p:commandButton>
        </p:panelGrid>
    </p:dataGrid>

</h:form>
<ui:include src="/faces/dialogEdit.xhtml" />
<p:commandButton value="Voltar" action="/faces/index.xhtml" process="@this"></p:commandButton>

My managedBean

import java.io.Serializable;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.inject.Inject;
import com.whit.domain.Message;
import com.whit.facade.MessageFacade;
@ManagedBean
@ViewScoped
public class GrowlView extends AbstractMB implements Serializable {
    private static final long serialVersionUID = 1L;    
    @Inject
    private Message message;

    private List<Message> messages;

    private MessageFacade messageFacade;

    public void save() {
        if (message.getId() == (null)) {
            createMessage();
        } else {
            updateMessage(message);
        }
    }

    private void createMessage() {
        try {
            getMessageFacade().createMessage(message);
            addSucess(message.getMessage());
            loadMessages();
            resetMessage();
        } catch (Exception e) {
            addFail(message.getMessage());
            e.printStackTrace();
            resetMessage();
        }
    }

    private void updateMessage(Message message) {
        try {
            getMessageFacade().updateMessage(message);
            addSucess(message.getMessage());
            loadMessages();
            resetMessage();
        } catch (Exception e) {
            addFail(message.getMessage());
            e.printStackTrace();
        }
    }

    public void deleteMessage(Message message) {
        try {
            getMessageFacade().deleteMessage(message);
            loadMessages();
            resetMessage();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public String preprarUpdate(Message message) {
        this.message = messageFacade.findMessage(message.getId());
        return ":dialog";
    }

    public MessageFacade getMessageFacade() {
        if (messageFacade == null) {
            messageFacade = new MessageFacade();
        }

        return messageFacade;
    }

    public Message getMessage() {
        return message;
    }

    public void setMessage(Message message) {
        this.message = message;
    }

    public List<Message> getAllMessages() {
        if (messages == null) {
            loadMessages();
        }

        return messages;
    }

    private void loadMessages() {
        messages = getMessageFacade().listAll();
    }

    public void resetMessage() {
        message = new Message();
    }
}
    
asked by anonymous 01.04.2017 / 18:49

1 answer

0

I recommend you return the object itself instead of String , but look. In your method:

public String preprarUpdate(Message message) {
        this.message = messageFacade.findMessage(message.getId());
        return ":dialog";
    }

You should return the object for editing, so it would look like this:

public String preprarUpdate(Message message) {
        this.message = messageFacade.findMessage(message.getId());
        return message;
    }

And after pressing your button you need to update the dialog, thus:

<p:commandButton value="Alterar" onclick="PF('dialog').show();"
                action="#{growlView.preprarUpdate(bean)}" update=":<idform>:dialog"/>

A tip for you about jsf, you do not need to close your component as you did with </p:commandButton> , it only does so when you have another component inside, in your case as you can not do as in my example.

    
01.04.2017 / 19:44