我正在将 xhtml 渲染到一个对话框,该对话框的组件是使用 Dynamic example 从服务器端动态添加的。 .
使用 PrimeFaces 5.1、JSF 2.1 Mojarra 和 tomcat 7。
当我单击弹出窗口的关闭按钮时,在 Eclipse 控制台中会看到大量无法找到该组件的情况,因此关闭操作响应缓慢。
尝试将 myForm 上的 prependId 更改为 true。还尝试将关闭按钮的 update 属性中的 @form 替换为 :myForm。 这两种方法都没有成功。
我想知道如何防止触发此无法找到组件。
Unable to find component with clientId editOwnerForm:tab:j_id16:iq_16_panelGroup2', no need to remove it.
Unable to find component with clientId 'editOwnerForm:tab:j_id16:j_id235', no need to remove it. Unable to find component with clientId 'editOwnerForm:tab:j_id16:j_id236', no need to remove it. Unable to find component with clientId 'editOwnerForm:tab:j_id16:j_id237', no need to remove it. Unable to find component with clientId 'editOwnerForm:tab:j_id16:j_id238', no need to remove it. Unable to find component with clientId 'editOwnerForm:tab:j_id16:j_id239', no need to remove it. Unable to find component with clientId 'editOwnerForm:tab:j_id16:j_id240', no need to remove it. Unable to find component with clientId 'editOwnerForm:tab:j_id16:j_id241', no need to remove it. Unable to find component with clientId 'editOwnerForm:tab:j_id16:j_id242', no need to remove it. Unable to find component with clientId 'editOwnerForm:tab:j_id16:j_id243', no need to remove it. Unable to find component with clientId editOwnerForm:tab:j_id16:iq_17_225', no need to remove it. Unable to find component with clientId 'editOwnerForm:tab:j_id16:iq_17_panelGroup2', no need to remove it.
myForm.xhtml
<h:form prependId="false" id="form">
<p:commandButton id="editOwnerButtonId" oncomplete="PF('editOwnerDlgVar').show();"
actionListener="#{myViewBean.editOwner}"
update=":editOwnerForm" icon="ui-icon-pencil"
iconPos="right">
<f:param name="ownerId"
value="#{myViewBean.id}" />
</p:commandButton>
</h:form>
<p:dialog id="editOwnerDlgId" widgetVar="editOwnerDlgVar"
modal="true" closable="true" width="1200px" height="600" >
<ui:include src="ownerEdit.xhtml" />
</p:dialog>
ownerEdit.xhtml
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
lang="en" xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:shiro="http://shiro.apache.org/tags">
<h:form prependId="true" id="editOwnerForm">
<p:tabView id="tab" style="border-width:0px;"
activeIndex="#{myViewBean.tanIndex}">
<p:tab >
</p:tab >
<p:tab id="dynamicResponse" title="Dynamic Response">
<h:panelGroup id="sections"
binding="#{myViewBean.panelGroup}">
</h:panelGroup>
</p:tab>
</p:tabView>
<p:commandButton value="Close" update=":form" id="cancelButton"
immediate="true"
actionListener="#{myViewBean.cancelOwner}"
icon="ui-icon ui-icon-arrowreturn-1-w" iconPos="right">
<p:ajax listener="#{myViewBean.setTabIndex}" />
</p:commandButton>
</h:form>
</ui:composition>
MyViewBean 动态渲染代码 - 单击编辑按钮时触发
HtmlPanelGroup panelGroup = new HtmlPanelGroup();
panelGroup.getChildren().clear();
TabView tabView = new TabView();
Tab sectionTab = (Tab) tabView.findComponent("sec_" + question.getSectionId());
sectionTab.setId("sec_" + question.getSectionId());
sectionTab.setTitle(question.getSectionName());
HtmlPanelGrid pg = new HtmlPanelGrid();
pg.setColumns(3);
OutputLabel questionText = new OutputLabel();
questionText.setValue(question.getTitle());
pg.getChildren().add(questionText);
OutputLabel coln1 = new OutputLabel();
coln1.setValue(":");
pg.getChildren().add(coln1);
final String respBind = "#{myViewBean.questionResponse[\""+ question.getId()+ "_"+ pet.getId()+ "_"+ question.getMultiPet() + "\"]}";
final ValueExpression resp = FacesContext.getCurrentInstance().getApplication()
.getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), respBind, String.class);
InputText value = new InputText();
value.setId("iq_"+ String.valueOf(question.getId()) + "_"+ String.valueOf(pet.getId()));
value.setSize(20);
value.setValueExpression("value", resp);
pg.getChildren().add(value);
sectionTab.getChildren().clear();
sectionTab.getChildren().add(pg);
tabView.getChildren().add(sectionTab);
panelGroup.getChildren().add(tabView);
最佳答案
找到了这个问题的解决方案...要修复“无法找到带有 clientId 'tab:j_id16:sec_4' 的组件,无需删除它。”,我们必须将 jsf jar 从 2.1.7 更新到2.1.9 或至 2.1.29。 在下面的链接中,这被报告为 Mojarra 的问题。
查看链接
http://forum.primefaces.org/viewtopic.php?f=3&t=22880
https://java.net/jira/browse/JAVASERVERFACES-2383
https://java.net/jira/secure/ReleaseNote.jspa?projectId=10204&version=15535
关于jsf-2 - 动态渲染 - 无法找到具有 clientId 的组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30778214/