[英]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.