how i get clicked CommandLink id in Controller in JSF?

时光总嘲笑我的痴心妄想 提交于 2019-12-25 06:28:35

问题


<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>

java.lang.IllegalArgumentException caught during processing of RENDER_RESPONSE 6 : UIComponent-ClientId=, Message=Empty id attribute is not allowed here

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


回答1:


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

  2. 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.

    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>
    


来源:https://stackoverflow.com/questions/19338107/how-i-get-clicked-commandlink-id-in-controller-in-jsf

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!