jsf客户端ID

本文详细解析了JavaServer Faces (JSF) 中客户端ID的生成过程。重点介绍了如何通过组件的ID与父容器ID组合来形成完整的客户端ID,并讨论了在ID未设置时的处理方式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

public  String getClientId(FacesContext context)  {
        
if (context == null)
            
throw new NullPointerException("context");

        
if (_clientId != null)
            
return _clientId;

        
boolean idWasNull = false;
        String id 
= getId();
        
if (id == null{
            
// Although this is an error prone side effect, we automatically
            
// create a new id
            
// just to be compatible to the RI
            UIViewRoot viewRoot = context.getViewRoot();
            
if (viewRoot != null{
                id 
= viewRoot.createUniqueId();
            }
 else {
                context.getExternalContext().log(
                    
"ERROR: Cannot automatically create an id for component of type "
                            
+ getClass().getName()
                            
+ " because there is no viewRoot in the current facesContext!");
                id 
= "ERROR";
            }

            setId(id);
            
// We remember that the id was null and log a warning down below
            idWasNull = true;
        }


        UIComponent namingContainer 
= _ComponentUtils
                .findParentNamingContainer(
thisfalse);
        
if (namingContainer != null{
                 //在此处要添加form的前缀
            _clientId 
= namingContainer.getClientId(context)
                    
+ NamingContainer.SEPARATOR_CHAR + id;
        }
 else {
            _clientId 
= id;
        }


        Renderer renderer 
= getRenderer(context);
        
if (renderer != null{
            _clientId 
= renderer.convertClientId(context, _clientId);
        }


        
if (idWasNull) {
            context.getExternalContext().log(
                
"WARNING: Component "
                        
+ _clientId
                        
+ " just got an automatic id, because there was no id assigned yet. "
                        
+ "If this component was created dynamically (i.e. not by a JSP tag) you should assign it an "
                        
+ "explicit static id or assign it the id you get from the createUniqueId from the current UIViewRoot "
                        
+ "component right after creation!");
        }

        
 return _clientId;
    }

 

jsf的客户端的id生成,_clientId = namingContainer.getClientId(context) + NamingContainer.SEPARATOR_CHAR + id;

在此处要添加前缀,所以生成的客户端表示都是这样的form:id

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值