2016-07-22 135 views
0

在以下示例中,我使用p:ajax修改數據表,然後使用remoteCommand更新表。這樣可行。不過,我還想在發生錯誤或成功時更新咆哮信息。這是行不通的。Primefaces p:ajax和remoteCommand不更新咆哮消息

我從例子中看到,如果一個按鈕調用一個動作,然後調用remoteCommand,growl消息更新。但是,這不會給我我需要從數據表中的ajax cellEdit。

如何從p:ajax命令更新growl消息。

<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; 
    } 

} 
+0

您的'onCellEditRemote'遠程命令不會調用任何東西,因此最有可能不會更新任何內容。檢查網絡流量 – Kukeltje

回答

-2

其將工作P中添加partialsubmit:AJAX

+0

+1

錯誤的純空白(無逗號)被允許並以普通的jsf連唯一有效的值 – Kukeltje

+0

抱歉,因爲不正確的答案 –

0

我工作圍繞這個問題從remoteCommand在modifyWordOnCellEdit創建和保存信息然後調用displayMessageAction來顯示它。不完全是我所希望的,但它的工作原理。

<p:remoteCommand name="onCellEditRemote" update="wordsId" action="#{gameBean.displayMessageAction}"/> 


    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); 
    }