有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java<c:forEach>和<h:commandLink>无法向函数发送参数

我无法让h:command向函数发送param cat1有AR数组的值,但我无法让它以正确的参数发送param

JSP代码

<c:forEach items="${categoryBean.getSubCategoryByID(0)}" var="cat" varStatus="stat">        
<c:set var="cat1" scope="request" value="${cat}"/>
   <li>
     <c:out value="${cat1.id}" />  <c:out value="${cat1.name}" />
     <h:commandLink id="goprime" action="#{categoryBean.gotoPrimecat}" value="#{cat1.name}"> 
     <f:setPropertyActionListener target="#{categoryBean.CatID}" value="#{cat1.id}" />
      </h:commandLink>
    </li>
  </c:forEach>

bean代码

public String getCatID() {
    return CatID;
}
public void setCatID(String CatID) throws SQLException, ClassNotFoundException {
   logger.info("in setter: "+CatID);
    this.CatID = CatID;
        //products = product.searchProductsByCategory(null, null, CatID); 


}

public void GotoPrimecat() throws IOException  {
    logger.info("in primercat , id: "+this.CatID);
    ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
    context.redirect("category.jsp");
    return;
}

共 (1) 个答案

  1. # 1 楼答案

    看起来问题在于你的方法名。在页面中,方法被引用为categoryBean.gotoPrimecat,而在bean中,方法被引用为GotoPrimecat()。确保方法名称(包括大小写)完全相同,并且应该是正确的。在这种情况下,bean方法应该以小写字母开头,这是普遍接受的样式