简体   繁体   English

如何从#{cc.clientId}中提取第一个组件ID?

[英]How to extract first component ID from #{cc.clientId}?

I neet to get a specific parent component ID in a composite component. 我没有在复合组件中获取特定的父组件ID。 I've only found out how to get the entire chain of IDs, namely as I wrote in the title: #{cc.clientId} . 我只发现了如何获取整个ID链,即我在标题中写的: #{cc.clientId} It delivers (I don't know how they're called) Id1:Id2:Id3 , but I need only Id1 , how can I get it? 它提供了(我不知道如何称呼它们) Id1:Id2:Id3 ,但是我只需要Id1 ,我怎么能得到它?

You could use the fn:split() function for this: 您可以为此使用fn:split()函数

xmlns:fn="http://java.sun.com/jsp/jstl/functions"
...

#{fn:split(cc.clientId, ':')[0]}

Another way is to use UIComponent#getNamingContainer() on the UIComponent#getParent() : 另一种方法是在UIComponent#getParent()上使用UIComponent#getNamingContainer() UIComponent#getParent()

#{cc.parent.namingContainer.parent.namingContainer.clientId}

There may be better ways depending on the concrete functional requirement and the code you have so far, both which are missing in your question. 可能有更好的方法,具体取决于您目前的具体功能要求和代码,而这两个问题都遗漏了。 For example, if Id1 actually refers a <h:form> , then you could use render="@form" instead in the <f:ajax> . 例如,如果Id1实际上引用了<h:form> ,则可以在<f:ajax>使用render="@form"代替。

The Id1:Id2:Id3 is by the way just called the client ID (as you see in generated HTML output). Id1:Id2:Id3只是称为客户端ID(如您在生成的HTML输出中看到的)。 The Id1 part is actually the component ID (as you see in JSF source code). Id1部分实际上是组件ID(如您在JSF源代码中所见)。 The prepending of NamingContainer IDs in client ID as in Id1:Id2:Id3 is also sometimes called woodstocking. 客户端ID中的NamingContainer ID的前缀(例如Id1:Id2:Id3 )有时也被称为伍德斯托克。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在ajax update / process / render / execute中引用#{cc.clientId}? - How to reference #{cc.clientId} in ajax update/process/render/execute? 如何从表中捕获第一个td值(id)? - How to capture first td value (id) from table? ID与UniqueID对比ClientID与UniqueClientID对比StaticClientID? - ID vs UniqueID vs ClientID vs UniqueClientID vs StaticClientID? 如何找出用于 ajax 更新/渲染的组件的客户端 ID? 找不到从“bar”引用的表达式“foo”的组件 - How to find out client ID of component for ajax update/render? Cannot find component with expression "foo" referenced from "bar" 如何根据PHP中自动完成的名字和姓氏返回ID? - How can I return the ID based from its first name and last name in autocomplete in PHP? 如何从Jquery Datables中选择一行并获取第一列的ID? - How do I select a row from Jquery Datables and grab the id of the first column? DataTables:如何将第一列(ID)显示为超链接? - DataTables: How to display first column (ID) as hyperlink? 如何从HTML提取TD - How to extract a td from html Ajax仅在提交的第一个ID上起作用(使用来自数据库的php) - Ajax works only on first id submitted (with php from db) 是否可以从responsetext获取id的元素而不先打印出来? - Is it possible to get element by id from responsetext without printing it out first?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM