【问题标题】:Dynamic rendering - unable to find component with clientId动态渲染 - 无法找到带有 clientId 的组件
【发布时间】:2015-06-11 10:25:07
【问题描述】:

我正在将一个 xhtml 渲染到一个对话框,该对话框的组件是使用 Dynamic example 从服务器端动态添加的。

使用 PrimeFaces 5.1、JSF 2.1 Mojarra 和 tomcat 7。

当我单击弹出窗口的关闭按钮时,出现大量无法找到组件的 Eclipse 控制台,因此关闭操作响应缓慢。

尝试将 myForm 上的 prependId 更改为 true。还尝试将关闭按钮的 update 属性中的 @form 替换为 :myForm。 这两种方法都不成功。

我想知道如何防止这个无法找到组件被触发。

无法找到带有 clientId editOwnerForm:tab:j_id16:iq_16_panelGroup2' 的组件,无需删除。

无法找到带有 clientId 的组件 'editOwnerForm:tab:j_id16:j_id235',无需删除。 无法 查找带有 clientId 'editOwnerForm:tab:j_id16:j_id236' 的组件,否 需要删除它。 无法找到带有 clientId 的组件 'editOwnerForm:tab:j_id16:j_id237',无需删除。 无法 查找带有 clientId 'editOwnerForm:tab:j_id16:j_id238' 的组件,否 需要删除它。 无法找到带有 clientId 的组件 'editOwnerForm:tab:j_id16:j_id239',无需删除。 无法 查找带有 clientId 'editOwnerForm:tab:j_id16:j_id240' 的组件,否 需要删除它。 无法找到带有 clientId 的组件 'editOwnerForm:tab:j_id16:j_id241',无需删除。 无法 查找带有 clientId 'editOwnerForm:tab:j_id16:j_id242' 的组件,否 需要删除它。 无法找到带有 clientId 的组件 'editOwnerForm:tab:j_id16:j_id243',无需删除。 无法找到带有 clientId editOwnerForm:tab:j_id16:iq_17_225' 的组件,无需删除它。 无法找到带有 clientId 的组件 'editOwnerForm:tab:j_id16:iq_17_panelGroup2',不需要删除。

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);

【问题讨论】:

    标签: jsf-2 primefaces


    【解决方案1】:

    已解决此问题...要修复“无法找到带有 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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-08-18
      • 1970-01-01
      • 1970-01-01
      • 2014-12-18
      • 1970-01-01
      • 2020-02-28
      • 2019-07-21
      • 1970-01-01
      相关资源
      最近更新 更多