jsf - 如何在数据表中获取组件的jsf clientid?

标签 jsf datatable components clientid

我正在尝试获取数据表中组件的客户端 ID。问题是 jsf 自动将行索引放在组件 id 之前,即

   <a id="mappedidentifier_table:1:mappedidentifier_Update" href="#">Update</a>

对于第二行中的链接(索引 = 1)。

我正在使用以下方法来获取 clientId
   public static String findClientId(String id) {
        FacesContext context = FacesContext.getCurrentInstance();
        UIViewRoot view = context.getViewRoot();
        if (view == null) {
            throw new IllegalStateException("view == null");
        }
        UIComponent component = findComponent(view, id);
        if (component == null) {
            throw new IllegalStateException("no component has id='" + id + "'");
        }
        return component.getClientId(context);
    }

    private static UIComponent findComponent(UIComponent component, String id) {
        if (id.equals(component.getId())) {
            return component;
        }

        Iterator<UIComponent> kids = component.getFacetsAndChildren();
        while (kids.hasNext()) {
            UIComponent kid = kids.next();
            UIComponent found = findComponent(kid, id);
            if (found != null) {
                return found;
            }
        }

        return null;
    }

但是这会返回
mappedidentifier_table:mappedidentifier_Update ,

代替
mappedidentifier_table:1:mappedidentifier_Update ,

因此它不匹配任何元素,导致 id 中的行索引丢失。

我已阅读 http://illegalargumentexception.blogspot.com/2009/05/jsf-using-component-ids-in-data-table.html

但是我打算有一个更简单的实现,而不是像作者那样的 TLD 函数或 facelets。

有人有想法吗 ?

谢谢,

最佳答案

however this returns mappedidentifier_table:mappedidentifier_Update instead of mappedidentifier_table:1:mappedidentifier_Update



如果您解决了 clientId,就会发生这种情况。在一行的上下文之外。行上下文由 UIData 在生命周期的每个阶段设置。控制。

如果您在 EL 表达式中使用立即评估而不是延迟评估,也可能会发生这种情况 - ${}而不是 #{} .

顺便说一句,正如文章中所述,该查找算法仅在组件标识符对于 View 是唯一的情况下才有效;规范说它只需要唯一的 NamingContainer ;如果您小心谨慎地在页面上使用唯一的组件 ID,这应该不是问题。

关于jsf - 如何在数据表中获取组件的jsf clientid?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1493217/

相关文章:

java - 如何在Java中修改两个类的对象?

ios - Cocos2D/iOS : usage of "@class Component" tag

java - 如何集成 Spring 和 JSF

java - 用户界面 :include using FaceletsContext

jsf - 格式化 JSF 电话号码

c#数据表批处理

javascript - 以编程方式实例化 vuetify-components

jsf - tr 的默认排序 :table?

c# - 更改 DataGrid 的列宽

javascript - 带有 requirejs $(...).DataTable 的数据表不是函数