问题描述
如何检索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中添加这样的组件).
对于确定绝对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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!