检索Facelets的客户端ID [英] Retrieve client id for facelets

查看:111
本文介绍了检索Facelets的客户端ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检索ui:include包含的facelet的clientId?

How do I retrieve clientId for a facelet included with ui:include?

对于可重用组件,我使用以下语法:cc.clientId.

For a reusable component I use this syntax: cc.clientId.

EDIT1

该问题与确定绝对ID 有关.为了包括动态编辑器,我使用了自定义包含.

The question is in the context of Determine absolute id. To include the dynamic editors I use a custom include.

可在以下位置找到DynamicInclude,DynamicIncludeComponent和DynamicIncludeHandler的源代码: http://pastebin.com/5e2dgR15.我必须在DynamicInclude的getSrc方法中删除测试src是否为null的行,并将getFamily更改为返回非null值.这是我可以在我的案例中找到并使用的动态包含的唯一实现.目前,我还没有知识可以做得更好.具有动态包含对于我的项目至关重要,因为它在很多地方都被使用(@BalusC:如果可能的话,我希望看到在OmniFaces中添加这样的组件).

The source code of DynamicInclude, DynamicIncludeComponent and DynamicIncludeHandler can be found at: http://pastebin.com/5e2dgR15. I had to remove the lines that tested the src for null in getSrc method of DynamicInclude and changed getFamily to return a not null value. It is the only implementation of a dynamic include that I could find and use in my case. At this moment, I don't have the knowledge to make a better one. Having a dynamic include is crucial to my project because it is used in lots of places(@BalusC: I would love to see such component being add in OmniFaces if it's possible).

我关于绝对客户端ID的问题与为<custom:include>生成ID的方式有关.在我的情况下是tabs:0:editorsGroup:4:editor3.我已经看到命名容器(例如<p:dataTable><p:tabView>)会向id(tabs:0,editorsGroup:4)添加一个数字.我不确定此自定义包含是否为100%NamingContainer. DynamicIncludeComponent实现NamingContainer,但是我不能将绝对客户端ID用作:tabs:editorsGroup:editor.

My problems with the absolute client id are related with the way the id gets generated for the <custom:include>. In my case is tabs:0:editorsGroup:4:editor3. I have seen that naming containers, such as <p:dataTable> or <p:tabView>, add a number to the id(tabs:0, editorsGroup:4). I am not sure if this custom include is 100 % a NamingContainer. DynamicIncludeComponent implements NamingContainer, but I cannot use an absolute client id as :tabs:editorsGroup:editor.

对于确定绝对ID 中的organizationUnit编辑器,我在更新中使用了一种解决方法对于absolute_id_of_organization_unit.使用#{eval.getAbsoluteId(cc.clientId, 'organizationUnit'),在删除cc.clientId的某些部分后,将计算绝对客户端ID.

For the organizationUnit editor from Determine absolute id, I have used a workaround in the update for absolute_id_of_organization_unit. With #{eval.getAbsoluteId(cc.clientId, 'organizationUnit'), the absolute client id was calculated, after some parts of the cc.clientId have been removed.

我尝试在<p:remoteCommand>的帮助下进行更新,但是没有成功.所以我以为我可以做与organizationUnit编辑器类似的解决方法.为此,我必须获取父ID,即getAbsoluteId方法的第一个参数.

I have tried to do the update with the help of a <p:remoteCommand>, but it didn't worked. So I have thought I could do a similar workaround as for the organizationUnit editor. For this I had to obtain the parent id, the first parameter for the getAbsoluteId method.

这些是我奇怪要求的原因.

These are the reasons from my strange request.

推荐答案

我已经通过创建类似于#{p:component(componentId)}的函数解决了该问题.除了返回客户端ID外,它还从生成的客户端ID中删除行索引信息.

I have solved the issue by creating a function similar to #{p:component(componentId)}. It addition to returning the client id, it also removes the row index information from the generated client id.

函数在WEB-INF/utils中的定义如下:

... doctype ommited
<facelet-taglib xmlns="http://java.sun.com/JSF/Facelet">
    <namespace>geneous.client.jsf/utils</namespace>
    <function>
        <function-name>absolute</function-name>
        <function-class>com.acme.util.ComponentUtils</function-class>
        <function-signature>java.lang.String getAbsoluteClientId(java.lang.String)</function-signature>
    </function>
</facelet-taglib>

内部web.xml

<context-param>
    <param-name>javax.faces.FACELETS_LIBRARIES</param-name>
    <param-value>/WEB-INF/utils/utils.taglib.xml</param-value>
</context-param>

函数中的示例代码:

public static String getAbsoluteClientId(String id) {
    final String clientId = removeRowIndexFromClientId(id);
    FacesContext facesContext = FacesContext.getCurrentInstance();
    final char separator = UINamingContainer.getSeparatorChar(facesContext);        
    StringBuilder idBuilder = new StringBuilder();
    idBuilder.append(separator).append(clientId);
    return idBuilder.toString();        
}

public static String removeRowIndexFromClientId(String id) {
    String clientId = findComponentClientId(id);
    FacesContext facesContext = FacesContext.getCurrentInstance();
    final char separator = UINamingContainer.getSeparatorChar(facesContext);
    final String regex = String.valueOf(separator) + "[0-9]+";
    return clientId.replaceAll(regex, "");
}

该功能用作#{<utils:absolute('componentId')>}.

这篇关于检索Facelets的客户端ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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