Change Dialog is not displaying data

Asked

Viewed 179 times

1

I have a Maven project that is using jsf, jpa and primefaces in which there is a dialog that is being used to do the altualization(update) of the data, only, inputText is empty when it is called instead of appearing the data in it (which are the ones defined in managedbean)... How do I get around it?

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();
    }
}
  • Hello everyone. After making the changes that Douglas suggested and not succeeding I researched and decided to try to replace onclick with oncomplete ai it worked... Thank you for your attention. I hope this solution is useful for more people

  • No need to add SOLVED in title. Just mark an answer as accepted already flags q has been fixed.

1 answer

0


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

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

you must return the object for editing, then it would look like this:

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

And after you press your button you need to update the dialog, getting like this:

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

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

  • I did as you said then and now the dialog is appearing with the content in the input and soon after it is gone. Then I tried to take the update, and the dialog usually appears only without the content. Any other suggestion

  • Puts a process=@this on the Change button

  • nor needed. I made the changes you suggested and subtituir the onclick by oncomplete and it worked.

Browser other questions tagged

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