2013-02-08 73 views
0

如何检索包含在ui中的facelet的clientId:include?检索facelets的客户端ID

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

EDIT1

的问题是在Determine absolute id的上下文。要包含动态编辑器,我使用了custom include

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

我绝对客户端ID的问题与ID为<custom:include>生成的方式有关。在我的情况是tabs:0:editorsGroup:4:editor3。我已经看到命名容器(如<p:dataTable><p:tabView>)向id(制表符:0,editorsGroup:4)添加一个数字。我不确定这个定制是否包含100%的NamingContainer。 DynamicIncludeComponent实现了NamingContainer,但我无法使用绝对客户端ID作为:tabs:editorsGroup:editor

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

我试图在<p:remoteCommand>的帮助下进行更新,但没有奏效。所以我认为我可以采用类似于organizationUnit编辑器的解决方法。为此,我必须获取父id,getAbsoluteId方法的第一个参数。

这些是我奇怪的请求的原因。

+0

我有更新我的问题与具体的功能要求。 – Seitaridis 2013-02-09 02:40:56

+0

除了具体的问题,我需要首先围绕我的头,这个组件在MyFaces中工作吗? – BalusC 2013-02-11 13:23:08

+0

我可以将需要的ID传递给包含''的自定义包含,如下所示:'”,但是我在更新属性中使用这个值时出现问题,错误是:SEVERE:javax.faces.FacesException:找不到标识符为“:form:tabs:1:editorsGroup:1:editor2:角色“从”form:tabs:1:editorsGroup:1:editor2:databases:0:j_id1533934859_460afa94“中引用。 – Seitaridis 2013-02-11 13:28:40

回答

0

我已经通过创建类似于#{p:component(componentId)}的函数解决了该问题。除了返回客户端ID之外,它还从生成的客户端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')>}