[英]How can I set an id to id h:commandLink from a c:forEach in order to be accesed by JS?
In a project with JSF 1.1 with Apache Trinidad, I need to create several dynamic h:commandLink, and they need to be accessed by JS in order to be clicked on loading. 在具有Apache Trinidad的JSF 1.1的项目中,我需要创建几个动态的h:commandLink,并且它们需要由JS访问,以便在加载时被单击。
What I have is this for js: 我对js有这个功能:
var cardsSize = window.document.getElementById("miForm:cardsSize").value;
for(var i = 0; i <= cardsSize; i++){
setTimeout(function(){
var buttonCard = window.document.getElementById("miForm:buttonCard_"+i);
buttonCard.click();
}, 1000);
}
And what I have in .jsp is: 我在.jsp中拥有的是:
<c:forEach var = "i" begin="0" varStatus="index" end="#{pageFlowScope.cardsSize}">
<h:commandLink id="buttonCard_#{index.index}"
style="display:none"
action="#{confirmBacking.generateDocument}"
onclick="document.forms['miForm'].target='_blank';">
<f:setPropertyActionListener target="#{confirmBacking.indexCard}" value="#{index}" />
</h:commandLink>
</c:forEach>
The problem is that when I create the commandLink with c:forEach, using a dynamic id ends in According to TLD or attribute directive in tag file, attribute "[id]" does not accept any expressions 问题是,当我使用c:forEach创建commandLink时,使用动态ID结束于根据TLD或标记文件中的attribute指令,属性“ [id]”不接受任何表达式
Other solutions for c:forEach or ui:repeat to create several commandLink with different params implies not to have and id, but I need ids since JS does not have other way to access these objects as far as I know. 用于c:forEach或ui:repeat的其他解决方案以不同的参数创建多个commandLink意味着没有和id,但是我需要id,因为据我所知,JS没有其他方法可以访问这些对象。
You can use a css class selector instead: 您可以改用CSS类选择器:
<h:commandLink styleClass="buttonCard_#{index.index}"
and get each button by: 并通过以下方式获取每个按钮:
document.getElementsByClassName("buttonCard_"+i)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.