how i get clicked CommandLink id in Controller in

2019-09-16 10:49发布

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

标签: jsf-2.2
1条回答
女痞
2楼-- · 2019-09-16 11:43
  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>
    
查看更多
登录 后发表回答