Primefaces p:ajax和remoteCommand不更新咆哮消息
在下面的示例中,我使用p:ajax修改了一个数据表,然后使用remoteCommand更新该表。这很有效。但是,我也希望在出现错误或成功的情况下更新growl msgs。那不行 我从示例中看到,如果一个按钮调用一个动作,然后调用remoteCommand,即咆哮msgs更新。然而,这并不能满足我对数据表中ajax cellEdit的需求 如何从p:ajax命令更新咆哮消息Primefaces p:ajax和remoteCommand不更新咆哮消息,primefaces,growl,Primefaces,Growl,在下面的示例中,我使用p:ajax修改了一个数据表,然后使用remoteCommand更新该表。这很有效。但是,我也希望在出现错误或成功的情况下更新growl msgs。那不行 我从示例中看到,如果一个按钮调用一个动作,然后调用remoteCommand,即咆哮msgs更新。然而,这并不能满足我对数据表中ajax cellEdit的需求 如何从p:ajax命令更新咆哮消息 <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="h
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
>
<h:head/>
<h:form id="formId">
<p:growl id="msgs" showDetail="true" />
<h:body>
<h:panelGrid>
<!-- Updates wordsId table but not msgs -->
<p:remoteCommand name="onCellEditRemote" update="wordsId msgs"/>
<p:dataTable id="wordsId" var="word" value="#{remoteMessageBean.words}" editable="true" editMode="cell">
<!-- does not update msgs -->
<p:ajax event="cellEdit" listener="#{remoteMessageBean.modifyWordOnCellEdit}" oncomplete="onCellEditRemote()" update="formId:msgs"/>
<p:column headerText="Modify" >
<p:outputLabel value="#{word}" />
</p:column>
<p:column headerText="Modify" >
<p:cellEditor>
<f:facet name="output"><h:outputText value=""/></f:facet>
<f:facet name="input">
<p:inputText id="modelInput" value="#{remoteMessageBean.modifyWord}"/>
</f:facet>
</p:cellEditor>
</p:column>
</p:dataTable>
</h:panelGrid>
<p:remoteCommand name="rc" update="msgs" />
<p:commandButton type="button" action="#{remoteMessageBean.buttonAction}" value="Doesnt Work" icon="ui-icon-refresh" update="msgs" />
<p:remoteCommand name="rc2" update="msgs" action="#{remoteMessageBean.buttonAction}" />
<p:commandButton type="button" onclick="rc2()" value="Works" icon="ui-icon-refresh" />
</h:body>
</h:form>
</html>
@ManagedBean
@SessionScoped
public class RemoteMessageBean {
private static Logger logger = Logger.getLogger(RemoteMessageBean.class);
private String modifyWord;
private List<String> words;
public RemoteMessageBean() {
words = new ArrayList<>();
words.add("word1");
words.add("word2");
words.add("word3");
}
public void modifyWordOnCellEdit(CellEditEvent event) {
logger.debug(event);
getWords().add(getModifyWord());
logger.debug("");
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "adding " + getModifyWord(), null);
FacesContext.getCurrentInstance().addMessage(null, msg);
setModifyWord(null);
}
public void buttonAction() {
logger.debug("");
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "buttonAction", null);
FacesContext.getCurrentInstance().addMessage(null, msg);
}
public String getModifyWord() {
return modifyWord;
}
public void setModifyWord(String modifyWord) {
this.modifyWord = modifyWord;
}
public List<String> getWords() {
return words;
}
}
@ManagedBean
@会议范围
公共类RemoteMessageBean{
私有静态记录器=Logger.getLogger(RemoteMessageBean.class);
私有字符串修改字;
私人列表词;
公共RemoteMessageBean(){
words=newarraylist();
词语。添加(“词语1”);
词语。添加(“词语2”);
词语。添加(“词语3”);
}
公共void modifyWordOnCellEdit(CellEditEvent事件){
调试(事件);
getWords().add(getModifyWord());
logger.debug(“”);
FacesMessage msg=新的FacesMessage(FacesMessage.SEVERITY_错误,添加“+getModifyWord(),null);
FacesContext.getCurrentInstance().addMessage(null,msg);
setModifyWord(空);
}
公共无效按钮(){
logger.debug(“”);
FacesMessage msg=新的FacesMessage(FacesMessage.SEVERITY_错误,“按钮操作”,null);
FacesContext.getCurrentInstance().addMessage(null,msg);
}
公共字符串getModifyWord(){
返回修改词;
}
public void setModifyWord(字符串modifyWord){
this.modifyWord=modifyWord;
}
公共列表getWords(){
返回单词;
}
}
它的工作将在p:ajax中添加partialsubmit我通过在modifyWordOnCellEdit中创建并保存消息,然后从remoteCommand调用displayMessageAction来显示消息,从而解决了这个问题。这不完全是我所希望的,但它起作用了
Jsf页面
<p:remoteCommand name="onCellEditRemote" update="wordsId" action="#{gameBean.displayMessageAction}"/>
错误,纯空白(没有逗号)是允许的,在纯jsf中,甚至是唯一有效的值。请尝试以下操作:partialSubmit是布尔值true/false,而不是js函数再次出错。。。请不要从根本上改变你原来的答案。所有的评论都是断章取义的。然后创建一个新的答案。请学习创建应答器的技术您的
oncelletitremote
remote命令不调用任何内容,因此很可能不会更新任何内容。检查网络流量
public void displayMessageAction() {
if (getMessage() != null) {
FacesContext.getCurrentInstance().addMessage("growl", getMessage());
setMessage(null);
}
}
public void modifyWordOnCellEdit(CellEditEvent event) {
...
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, exception.getMessage(), null);
setMessage(msg);
}