我如何在JSF的Controller中单击CommandLink id? [英] how i get clicked CommandLink id in Controller in JSF?

查看:93
本文介绍了我如何在JSF的Controller中单击CommandLink id?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<ui:repeat value="#{prodCtr.paginator.model}" var="o">                     
                <h:form> 
                    <h:commandLink  id="#{o.id}" action="ModelInfo.xhtml" actionListener="#{prodCtr.listener}">                         
                        <h:panelGrid columns="1" style="border: #ffffff">
                            <img  src="resources/images/#{o.id}.jpg"  style="width: 100px;height: 100px"/>                            
                            <h:outputLabel value="#{o.price} YTL" style="font-size: 12px;font-family: Georgia, Serif;color: #ff3300" />  
                            <h:commandButton   value="Sifaris et" class="button"/>
                        </h:panelGrid>  
                    </h:commandLink>                                
                </h:form>

        </ui:repeat>

在处理RENDER_RESPONSE 6期间捕获的java.lang.IllegalArgumentException:此处不允许使用UIComponent-ClientId =,Message = Empty id属性

我如何才能从命令行获取CommandLink ID?还有其他方法吗?

How can i CommandLink id dinamically?Is there an other way?

推荐答案

  1. 使用<ui:repeat/>标记时,您不需要 指定子组件的id属性.它会自动执行此操作.

  1. You don't need to specify the id attribute for the child components when using the <ui:repeat/> tag. It automatically does this.

如果您想控制id属性,则<ui:repeat/>是错误的用法.原因是在将组件放置在中的时间点上(基本上是在首次构建页面时),<ui:repeat/>组件未处于活动状态,即未在处理中.因此var="o"对运行时不可用,因此没有任何内容可用作id.

If you do want to be in control of the id attribute, <ui:repeat/> is the wrong one to use for that. The reason is that at point in time that the components are being placed in the UIViewroot (essentially when the page is being constructed for the first time), the <ui:repeat/> component is not active, i.e. it's not being processed. So the var="o" is not available to the runtime and so nothing is available to be used as id.

要控制id,您应该改用<c:forEach/>标记.您的代码应如下所示:

To be in control of the id, you should be using the <c:forEach/> tag instead. Your code should look like this:

 <c:forEach items="#{prodCtr.paginator.model}" var="o"> 
      <h:form> 
            <h:commandLink  id="#{o.id}" action="ModelInfo.xhtml" actionListener="#{prodCtr.listener}">                         
                <h:panelGrid columns="1" style="border: #ffffff">
                    <img  src="resources/images/#{o.id}.jpg"  style="width: 100px;height: 100px"/>                            
                    <h:outputLabel value="#{o.price} YTL" style="font-size: 12px;font-family: Georgia, Serif;color: #ff3300" />  
                    <h:commandButton   value="Sifaris et" class="button"/>
                </h:panelGrid>  
            </h:commandLink>                                
        </h:form>

</c:forEach>

这篇关于我如何在JSF的Controller中单击CommandLink id?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆