2012-04-10 122 views
0

幾天前我已經將mojarra改爲表面來解決this problem,現在我在渲染我的複合組件時出現了一個奇怪的問題,它們只是在我第二次打開一個彈出窗口(彈出窗口也是一個複合組件)。JSF 2.0 - Myfaces在渲染複合組件時遇到問題

第一次,你可以在字段集看,一切都變得確定: first open

然後我點擊我的複合材料部件的「CANCELAR」(取消)按鈕,然後第二次,沒有限制,除該對話框中,呈現: second open

當我看着日誌,我發現這些消息:

[#|2012-04-10T15:22:00.681-0300|SEVERE|glassfish3.1.1|org.apache.myfaces.renderkit.html.HtmlCompositeComponentRenderer|_ThreadID=19;_ThreadName=Thread-2;|facet UIComponent.COMPOSITE_FACET_NAME not found when rendering composite component prevenda:popupPreVenda:j_id_2uz|#] 
[#|2012-04-10T15:22:00.684-0300|SEVERE|glassfish3.1.1|org.apache.myfaces.renderkit.html.HtmlCompositeComponentRenderer|_ThreadID=19;_ThreadName=Thread-2;|facet UIComponent.COMPOSITE_FACET_NAME not found when rendering composite component prevenda:popupPreVenda:inputRazaoSocial|#] 
[#|2012-04-10T15:22:00.685-0300|SEVERE|glassfish3.1.1|org.apache.myfaces.renderkit.html.HtmlCompositeComponentRenderer|_ThreadID=19;_ThreadName=Thread-2;|facet UIComponent.COMPOSITE_FACET_NAME not found when rendering composite component prevenda:popupPreVenda:j_id_2vi|#] 
[#|2012-04-10T15:22:00.685-0300|SEVERE|glassfish3.1.1|org.apache.myfaces.renderkit.html.HtmlCompositeComponentRenderer|_ThreadID=19;_ThreadName=Thread-2;|facet UIComponent.COMPOSITE_FACET_NAME not found when rendering composite component prevenda:popupPreVenda:j_id_2vn|#] 
[#|2012-04-10T15:22:00.686-0300|SEVERE|glassfish3.1.1|org.apache.myfaces.renderkit.html.HtmlCompositeComponentRenderer|_ThreadID=19;_ThreadName=Thread-2;|facet UIComponent.COMPOSITE_FACET_NAME not found when rendering composite component prevenda:popupPreVenda:j_id_2vs|#] 

,你可以看到,問題是,MyFaces的無法找到一個小在複合材料部件... 使用方面唯一的複合材料部件是hrgi:彈出:

<c:interface> 
    <c:attribute name="titulo" default="sem titulo" required="false"/> 
    <c:attribute name="renderizar" default="false" required="false"/> 
    <c:attribute name="modal" default="true" required="false"/> 
    <c:attribute name="bordaConteudo" default="true" required="false"/> 
    <c:facet name="cabecalho" required="false"/> 
    <c:facet name="conteudo" required="true"/> 
    <c:facet name="botoes" required="true"/> 
</c:interface> 

<c:implementation> 
<h:outputStylesheet library="css" name="hrgiPopup.css" target="head"/> 
<h:outputStylesheet library="css" name="clearfix.css" target="head"/> 
<h:outputScript library="js" name="hrgiPopup.js" target="head"/> 
<h:panelGroup layout="block" rendered="#{cc.attrs.renderizar}" 
       class="hrgi-dialog-panel clearfix"> 
    <h:panelGroup layout="block" class="hrgi-dialog-overlay clearfix" rendered="#{cc.attrs.modal}"></h:panelGroup> 
    <h:panelGroup id="popup" layout="block" class="hrgi-dialog-box clearfix"> 
     <h:panelGroup layout="block" class="hrgi-dialog-title clearfix"> 
      <h:outputText style="float:left" value="#{cc.attrs.titulo}"/> 
     </h:panelGroup> 
     <h:panelGroup layout="block" class="hrgi-dialog-content clearfix"> 
      <c:renderFacet name="cabecalho" required="false"/> 
      <h:panelGroup layout="block" class="hrgi-dialog-background clearfix" 
          rendered="#{cc.attrs.bordaConteudo}"> 
       <c:renderFacet name="conteudo" required="true"/> 
      </h:panelGroup> 
      <h:panelGroup layout="block" class="clearfix" rendered="#{not cc.attrs.bordaConteudo}"> 
       <c:renderFacet name="conteudo" required="true"/> 
      </h:panelGroup> 
      <c:renderFacet name="botoes" required="true"/> 
      <script type="text/javascript"> 
       cercarEventoTab("#{cc.clientId}:popup"); 
      </script> 
     </h:panelGroup> 
    </h:panelGroup> 
</h:panelGroup> 
</c:implementation> 

這是MyFaces的一個錯誤?莫哈拉並沒有表現出任何這樣的問題!

修訂

當用戶點擊「CANCELAR」按鈕......動作調用此代碼清除字段並關閉該對話框的問題恰好:

public void cancelar(ActionEvent evento){ 
    fechar(); 
    UIComponent componente=evento.getComponent().getParent().getParent().getParent(); 
    componente.getFacet("conteudo").getChildren().clear(); 
} 

這段代碼被改編從方法你可以看到here。在這種情況下,只會重新創建方面內的組件。工作得很好,除了我的複合組件。

回答

0

我不知道爲什麼,但我已經創造了一些課後處理異常,這個問題消失了......

public class HRGIExceptionHandler extends ExceptionHandlerWrapper { 

    private ExceptionHandler wrapped; 

    public HRGIExceptionHandler(ExceptionHandler wrapped) { 
     this.wrapped = wrapped; 
    } 

    @Override 
    public ExceptionHandler getWrapped() { 
     return wrapped; 
    } 

    @Override 
    public void handle() throws FacesException { 
     Iterator i = getUnhandledExceptionQueuedEvents().iterator(); 
     while (i.hasNext()) { 
      ExceptionQueuedEvent event = (ExceptionQueuedEvent) i.next(); 
      ExceptionQueuedEventContext context = (ExceptionQueuedEventContext)event.getSource(); 
      Throwable t = context.getException(); 
      try{ 
       t.printStackTrace(); 
      }finally{ 
       i.remove(); 
      } 
     } 
     getWrapped().handle(); 
    } 
} 

public class HRGIExceptionHandlerFactory extends ExceptionHandlerFactory { 

    private ExceptionHandlerFactory parent; 

    public HRGIExceptionHandlerFactory(ExceptionHandlerFactory parent) { 
     this.parent = parent; 
    } 

    @Override 
    public ExceptionHandler getExceptionHandler() { 
     ExceptionHandler result = new HRGIExceptionHandler(parent.getExceptionHandler()); 
     return result; 
    } 
} 

最後我把這個添加到faces.config:

<factory> 
    <exception-handler-factory>com.hrgi.web.erp.HRGIExceptionHandlerFactory</exception-handler-factory> 
</factory> 
0

MyFaces中的代碼是可以的。日誌建議org.apache.myfaces.renderkit.html.HtmlCompositeComponentRenderer無法在複合組件文件中找到c:implementation條目,自2.1.6以來,已做了一些更改以防止在庫名稱內使用'/'字符(有關詳細信息,請參見MYFACES-3454 )。添加了web配置參數(org.apache.myfaces.STRICT_JSF_2_ALLOW_SLASH_LIBRARY_NAME)以啓用反向行爲,但請注意新規則在規範中以明確的方式提及。

如果這不起作用,請嘗試創建一個簡單的演示應用程序來重現錯誤並在MyFaces Issue Tracker中創建問題。通過這種方式,它有可能在未來的版本中得到解決。

UPDATE

我試過沒有成功所提供的信息重現它。問題是調用

componente.getFacet("conteudo").getChildren().clear(); 

該代碼去除面內的所有組件,並且MyFaces的是智能足夠多的記憶中刪除的組件。恢復視圖時,MyFaces算法會在第一個請求中構建視圖,然後刪除組件以正確恢復狀態。此行爲是預期的,所以MyFaces代碼中沒有錯誤。相反,我想前面描述的行爲是Mojarra中的一個bug,你應該改變你的代碼,以其他方式重置你的輸入組件,也許清理bean中的值,或者在你的組合組件中創建一個方法表達式屬性,在發生取消操作時調用並清除所需的輸入字段。有很多方法可以做到這一點。

+0

Web配置沒有幫助,也許會導致複合組件標記聲明看起來沒有錯:xmlns:hrgi =「ht TP://java.sun.com/jsf/composite/hrgi」。我添加了新的信息。感謝您的關注 – brevleq 2012-04-10 23:28:41

+0

我調整了「componente.getFacet(」conteudo「)。getChildren()。clear();」從第二種方法你可以在這裏看到:https://cwiki.apache.org/MYFACES/clear-input-components.html。有沒有另外一種方法,我可以清除頁面中的所有組件,而且在我的複合組件中沒有問題? – brevleq 2012-04-16 12:42:35