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
– Wagner Santos
No need to add SOLVED in title. Just mark an answer as accepted already flags q has been fixed.
– user28595