2012-04-10 113 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