获取JSF2复合组件的父组件的clientId [英] Obtaining the clientId of the parent of a JSF2 composite component

查看:148
本文介绍了获取JSF2复合组件的父组件的clientId的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

<h:dataTable id="dt" value="#{somelist}" var="entry">
    <h:column>
        #{entry.title}
    </h:column>
    <h:column>
        <h:commandLink id="lnk">
           <mycomp:doSomething id="dummy" />
        </h:commandLink>
    </h:column>
</h:dataTable>

我的复合组件(mycomp:doSomething)看起来像这样:

My composite component (mycomp:doSomething) looks like this:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:composite="http://java.sun.com/jsf/composite">

    <composite:interface>
    </composite:interface>

    <composite:implementation >     
        <script type="text/javascript">
            // #{component.parent.clientId}
        </script>        
    </composite:implementation>
</html>

我希望输出(#{component.parent.clientId})类似于以下内容:dt:0:lnk,但是它返回dt:0:dummy,即复合组件的客户端ID.

I would expect the output (#{component.parent.clientId}) to be something similar to this: dt:0:lnk but instead it returns dt:0:dummy i.e. the client ID of the composite component.

如何获取真正的父标签的ID?

How do I get the ID of the real parent tag?

推荐答案

请改用#{cc.parent.clientId}. Composite:implementation内部的所有内容都在UIPanel内部,该UIPanel在复合组件基本实例内部的facelet上,通常是NamingContainer.

Use #{cc.parent.clientId} instead. All content inside composite:implementation is inside a UIPanel that is on a facelet inside the composite component base instance, which usually is a NamingContainer.

更新:检查代码cc.parent可以解析父组合组件,而不是直接父组件.这似乎是一个旧的实现细节,但在规范中未提及.此答案中提出的解决方案不起作用:(.

UPDATE: Checking the code, cc.parent resolves the parent composite component instead of the immediate parent. It seems to be an old implementation detail, but it is not mentioned in the spec. The solution proposed in this answer does not work :(.

请参见 http://lists.jboss .org/pipermail/jsr-314-open-mirror/2010-February/002474.html

您可以绕过cc.parent的分辨率,提供扩展UINamingContainer的自定义组件类并添加以下内容:

You can bypass the resolution of cc.parent, providing a custom component class extending UINamingContainer and adding this:

<composite:interface componentType="my.custom.ComponentBaseClass">

然后添加一个类似的吸气剂

then add a getter like

public UIComponent getImmediateParent()
{
     return getParent();
}

,最后使用#{cc.immediateParent.clientId}.它应该以这种方式工作.

and finally use #{cc.immediateParent.clientId}. It should work in this way.

这篇关于获取JSF2复合组件的父组件的clientId的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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