前几天我已经将mojarra改为myfaces来解决this problem,现在我在渲染我的复合组件时出现了一个奇怪的问题,它们只是在我第二次打开一个弹出窗口时才会渲染(弹出窗口)也是一个复合组件。)
第一次,正如您在fieldset中看到的那样,所有内容都呈现正常:
然后我点击“CANCELAR”(取消)按钮,第二次,除了对话框之外,我的复合组件都没有呈现:
当我查看日志时,我发现了这些消息:
[#|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无法在复合组件中找到一个方面... 使用facet的唯一复合组件是hrgi:popup:
<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的错误吗? Mojarra没有表现出这样的问题!
已更新
问题恰好发生在用户点击“CANCELAR”按钮时......操作调用此代码清除字段并关闭对话框:
public void cancelar(ActionEvent evento){
fechar();
UIComponent componente=evento.getComponent().getParent().getParent().getParent();
componente.getFacet("conteudo").getChildren().clear();
}
此代码是根据您可以看到here的方法改编的。在这种情况下,只重新创建facet conteudo中的组件。工作正常,除了我的复合组件。
答案 0 :(得分:0)
MyFaces中的代码没问题。日志建议org.apache.myfaces.renderkit.html.HtmlCompositeComponentRenderer在复合组件文件中找不到c:implementation条目,从2.1.6开始,我们进行了一些更改以防止在libraryName中使用'/'字符(参见{{3详情)。添加了Web配置参数(org.apache.myfaces.STRICT_JSF_2_ALLOW_SLASH_LIBRARY_NAME)以启用向后行为,但请注意,在规范中以明确的方式提及了新行为。
如果这不起作用,请尝试创建一个简单的演示应用程序来重现该错误并在MYFACES-3454中创建一个问题。通过这种方式,它有可能在未来的版本中得到解决。
<强>更新强>
我尝试使用提供的信息重现它但没有成功。问题是对
的调用componente.getFacet("conteudo").getChildren().clear();
该代码删除了facet中的所有组件,并且MyFaces很聪明,应该记住已删除的组件。恢复视图后,MyFaces算法会像在第一个请求中一样构建视图,然后删除组件以正确恢复状态。这种行为是预期的,因此MyFaces代码中没有错误。相反,我认为之前描述的行为是Mojarra中的一个错误,您应该更改代码以其他方式重置输入组件,可能清除bean内部的值,或者在复合组件中创建一个方法表达式属性,在取消操作发生时调用并清除所需的输入字段。有很多方法可以做到。
答案 1 :(得分: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>