f:ajax渲染引用了迭代的组件 [英] f:ajax render referencing iterated component

查看:69
本文介绍了f:ajax渲染引用了迭代的组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的xhtml具有以下结构:

I have xhtml with following structure:

<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所困扰.

This is running in Websphere Portlet via portlet bridge which means I am stuck with Myfaces 2.0.

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

The problem I am facing is that I am getting following error:

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

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

Notice that I am trying to reference first iteration of panel inside f:ajax render (:frmMain2:sub1:rep1:0:panel).

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

If I referenced something else (outside iterated part), e.g. :frmMain2:sub1:rep1, component is found and portlet works.

我无法找到如何在render属性中引用某些迭代组件.

I am unable to find how do I reference some iterated component in render attribute.

找到以下帖子,其中在Mojarra较新版本中描述了此问题,但Myfaces 2.2.7不能解决该问题:

Found following post where this problem is described as resolved in Mojarra newer version, but Myfaces 2.2.7 does not solve the problem: How to find out client ID of component for ajax update/render? Cannot find component with expression "foo" referenced from "bar"

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

So, Is there a way to reference the component I want to render in f:ajax?

推荐答案

由于您只想呈现第一个迭代,因此您可以创建一个自定义组件,标签或模板来封装要迭代的组件:

Since you only want to render the first iteration, you could create a custom component, tag, or template that encapsulates the components that you are iterating over as a workaround:

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

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

Then you could hard code the first option. Here's some example code (you'll definitely need to adapt this since I don't have all the info about your model data):

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

这篇关于f:ajax渲染引用了迭代的组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆