【问题标题】:JSF Cannot find component with identifier , template and cieJSF 找不到带有标识符、模板和 cie 的组件
【发布时间】:2013-07-02 16:58:06
【问题描述】:

编辑:另一种解决方案Updating ui:defined form content from Master template (JSF & Primefaces)

首先,对不起我的英语,我是这些该死的单语法语中的一员。

我遇到了这个经典错误:javax.faces.FacesException: 找不到从“formInscription:validerButton”引用的标识符为“:formWaitingList”的组件

我知道为什么会这样,但我不知道如何解决。

我在页脚中有一个连接表单。我想更新页面 rankMe.xhtml 中呈现的命令按钮。此页面定义 template.xhtml 的 ui:composition “内容”。 当我在带有命令按钮的页面上时,我没有错误并且渲染工作完美。但是当我在像 index.xhtml 之类的另一个页面上时(也定义了 template.xhtml 的内容),Glassfish 抛出了这个异常,我想这是完全标准的导致其他内容 (rankMe.xhtml) 未加载到实际视图中。

我怎样才能避免这个异常?如果用户不在实际的 rankMe.xhtml 页面上,我可以在所有页面中复制我的命令按钮并隐藏,但这对我来说也不是一种干净的方式。

谢谢

这里是代码:

template.xhtml:

<h:body>
    <ui:insert name="content" >
    </ui:insert>

    <ui:insert name="footer" >
         <ui:include src="../template/footer.xhtml"></ui:include>
    </ui:insert>
</h:body>

footer.xhtml:

<h:body>
    <h:form id="formInscription">
          <p:commandButton id="validerButton" update=":formWaitingList" ajax="true"/> 
    </h:form>
</h:body>

index.xhtml:

<h:body>
    <ui:composition template="/template/template.xhtml">
        <ui:define  name="content">
            Lorem ipsum ...
        </ui:define>
    </ui:composition>
</h:body>

rankMe.xhtml:

<h:body>
    <ui:composition template="/template/template.xhtml">
        <ui:define id="rankMe" name="content">
             <h:form id="formWaitingList">
                <h:commandButton id="Join"  
                                 rendered="#{connexion.connected}" 
                                 value="Join"/>
            </h:form>
        </ui:define>
    </ui:composition>
</h:body>

【问题讨论】:

标签: templates jsf rendering updates identifier


【解决方案1】:

想到两个非常简单的解决方案:
一种解决方案是将您的内容部分包装在p:outputPanel 中并更新它而不是您的formWaitingList

<p:outputPanel id="globalPanel>
  <ui:define  name="content">
        Lorem ipsum ...
  </ui:define>
</p:outputPanel>

第二种解决方案是在同一 footer.xhtml 中使用不同的 rendered 值复制您的 p:commandButton 两次:

<p:commandButton id="validerButton" update=":formWaitingList" ajax="true" rendered="#{conditionIfYouAreInTheRankMeView}"/>
<p:commandButton id="validerButtonBis" update="otherThingYouWantToUpdateOrEvenNoUpdate" ajax="true" rendered="#{conditionIfYouAreNotInTheRankMeView}"/>

【讨论】:

  • 感谢您的提示,但它仍然有点乱,我正在寻找一个真正的解决方案,但它不存在。另外,如果你在这里添加一个输出面板,它不会改变任何东西,我猜你的意思是用 outputPanel 包装 ?也许我的解释失败了
  • 不,我的意思是,将&lt;ui:define name="content"&gt; 包装在一个输出面板中。现在第二个解决方案呢?我觉得很有用
  • 第二种解决方案似乎是正确的,但似乎不是很严格。我想要一些坚固且适应性强的女巫,遵循带有页脚内容和页眉的严格模板,而不是混合的东西。
  • 当然是。这里唯一不同的是,页脚是可自定义的,它取决于使用的视图
  • stackoverflow.com/questions/9263193/… 听起来是个不错的解决方案
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-01
  • 2014-09-25
  • 1970-01-01
  • 1970-01-01
  • 2013-10-01
  • 2015-10-05
相关资源
最近更新 更多