2016-05-24 39 views
0

フォームにボタンがあり、このボタンをクリックするとエラーメッセージが表示されます。それは私が似たようなものをコーディングする前に完了したいステップです。ボタンをクリックするとエラーメッセージが表示されないため、コードが機能しません。primefaces p:メッセージが表示されない

私の形式は次のとおりです。私の豆の

<h:form id="myForm"> 
    <p:messages id="errorMessage" for="myForm" autoUpdate="true" /> 
    <p:fieldset id="myFieldSet" 
       style="margin-left:auto ; margin-right:auto ; width:98% ; height:90px;"> 
     <p:outputLabel for="numSi" 
         value="Value :" 
         style="margin-left:31px;margin-top:25px;" /> 
     <p:inputText id="numSi" 
        value="#{suppSiBean.researchValue}" 
        maxlength="9" required="true"> 
     </p:inputText> 
     <p:commandButton id="suppSignaButton" type="submit" ajax="true" 
         value="Launch" 
         style="text-align: center ; height:45px; width:150px ; margin-top:20px;" 
         action="#{suppSiBean.lancerRequete()}" /> 
    </p:fieldset> 
</h:form> 

抜粋:

public void lancerRequete() {} 
    FacesContext context = FacesContext.getCurrentInstance(); 
    //I'm intentionally hide the values of the three following variables because it's confidential 
    ResourceBundle bundle = ... 
    String message = ... 
    String messageFormat = ... 
    FacesMessage facesMessage = new FacesMessage(FacesMessage.SEVERITY_ERROR, messageFormat.toString(), ""); 
    FacesContext.getCurrentInstance().addMessage(getClientId("myForm"), facesMessage); 
} 

public String getClientId(String id) { 
    FacesContext context = FacesContext.getCurrentInstance(); 
    UIViewRoot root = context.getViewRoot(); 
    UIComponent c = findComponent(root, id); 
    LOGGER.info("c.getClientId(context) vaut :" + c.getClientId(context)); 
    return c.getClientId(context); 
} 

private UIComponent findComponent(UIComponent c, String id) { 
    if (id.equals(c.getId())) { 
     return c; 
    } 
    Iterator<UIComponent> kids = c.getFacetsAndChildren(); 
    while (kids.hasNext()) { 
     UIComponent found = findComponent(kids.next(), id); 
     if (found != null) { 
      return found; 
     } 
    } 
    return null; 
} 

答えて

-1

addMessage方法で直接コンポーネントのIDをターゲットにないのはなぜ?

public void lancerRequete() {} 
    ... 
    FacesContext.getCurrentInstance().addMessage("errorMessage", facesMessage); 
} 

最後に、update属性を追加することで、このコンポーネントを更新するときに教えてください:

<p:commandButton ... update="errorMessage" /> 
+0

それはしなかった理由を説明していない '自動アップデート、' =「真」がすでにあります作業。間違いは他の場所であり、提供されたコードを自分で実行してデバッグすることで、間違いを理解することができます。 – BalusC

+0

私は提供されたコードをテストし、それは非常にうまくいった。 – Omar

+0

もちろん、質問のコード。あなたのコードは正常に動作しますが、OPの問題を説明したり、答えたりすることはできません。 – BalusC

関連する問題