2013-02-08 77 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')>}