【问题标题】:f:ajax render referencing iterated componentf:ajax 渲染引用迭代组件
【发布时间】:2019-01-14 11:04:48
【问题描述】:

我有以下结构的 xhtml:

<h:form id="frmMain2">
        <f:subview id="sub1">
            <ui:repeat var="vatId" value="#{someBean.suppliesKeys()}" id="rep1">
                <fieldset>
                    <legend>vatId</legend>
                    <h:panelGroup id="panel">
                        <ui:repeat var="item" value="#{someBean.supplies[vatId]}" id="rep2">
                            <f:subview id="sub2">
                                <h:commandLink id="command">
                                    ${item}
                                    <f:ajax
                                        event="click"
                                        render=":frmMain2:sub1:rep1:0:panel">
                                    </f:ajax>
                                </h:commandLink>
                            </f:subview>
                        </ui:repeat>
                    </h:panelGroup>
                </fieldset>
            </ui:repeat>
        </f:subview>
    </h:form>

这是通过 Portlet 桥在 Websphere Portlet 中运行的,这意味着我被 Myfaces 2.0 卡住了。

我面临的问题是我收到以下错误:

javax.portlet.PortletException: Component with id::frmMain2:sub1:rep1:0:panel not found

请注意,我试图在 f:ajax 渲染 (:frmMain2:sub1:rep1:0:panel) 中引用面板的第一次迭代。

如果我引用了其他内容(迭代部分之外),例如:frmMain2:sub1:rep1,组件被找到,portlet 工作。

我找不到如何在渲染属性中引用一些迭代组件。

发现以下帖子描述了此问题在 Mojarra 较新版本中已解决,但 Myfaces 2.2.7 并未解决该问题:How to find out client ID of component for ajax update/render? Cannot find component with expression "foo" referenced from "bar"

那么,有没有办法在 f:ajax 中引用我要渲染的组件?

【问题讨论】:

  • 有比2.2.7(2.2.12)更新的版本,试过了吗?

标签: jsf myfaces websphere-portal


【解决方案1】:

由于您只想渲染第一次迭代,您可以创建一个自定义组件、标签或模板来封装您正在迭代的组件作为一种解决方法:

<fieldset>
    <legend>vatId</legend>
    <h:panelGroup id="panel">
        <ui:repeat var="item" value="#{someBean.supplies[vatId]}" id="rep2">
            <f:subview id="sub2">
                <h:commandLink id="command">
                    ${item}
                    <f:ajax
                        event="click"
                        render=":frmMain2:sub1:rep1:0:panel">
                    </f:ajax>
                </h:commandLink>
            </f:subview>
        </ui:repeat>
    </h:panelGroup>
</fieldset>

然后您可以对第一个选项进行硬编码。这是一些示例代码(你肯定需要调整它,因为我没有关于你的模型数据的所有信息)

<h:form id="frmMain2">
    <f:subview id="sub1">
        <custom:component id="first" items="#{someBean.supplies[hardcodedFirstKey]}">
            <f:ajax event="click" render="@this" />
        </custom:component>
        <ui:repeat var="vatId" value="#{someBean.suppliesKeys()}" id="rep1">
            <custom:component items="#{someBean.supplies[vatId]}" rendered="#{!key eq hardcodedFirstKey}">
                <f:ajax event="click" render=":frmMain:sub1:first" />
            </custom:component>
        </ui:repeat>
    </f:subview>
</h:form>

【讨论】:

  • 我喜欢你的思维方式以及你如何隔离第一个选项。但是,我不需要硬编码的第一个选项。我只是在示例中这样做以证明语法无效。实际呈现的应该是单击的 commandLink 的祖父面板,但它是 ui:repeat 的子面板。我想过使用 varStatus 中的索引,而不是我将添加到 ui:repeat 的零(但如果零不起作用,我就不会打扰正确的索引)
猜你喜欢
  • 2012-10-30
  • 1970-01-01
  • 2013-05-11
  • 1970-01-01
  • 1970-01-01
  • 2014-01-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多