2016-01-14 111 views
0

我不能得到h:command發送param給函數 的CAT1具有值AR數組,但我不能讓它發送param在正確PARAM<c:forEach>和<h:commandLink>時無法發送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; 
} 

回答

0

看起來問題是您的方法的名稱。在你的頁面中,方法被引用爲categoryBean.gotoPrimecat,而在你的bean中,方法是GotoPrimecat()。確保方法名稱完全相同,包括案例,並且應該沒問題。在這種情況下,你的bean方法應該以一個小寫字母開頭,無論如何這是一般可接受的風格。

+0

感謝您的答案,但仍然無法正常工作,f:setPropertyActionListener爲CatID設置空值 –

+0

您的bean中的CatID屬性是否正確命名了getters和setters? – ewanc

+0

下面的seeter和getter看起來似乎cat1並不是passet到JAVABEAN \t public String getCatID(){ return CatID; } \t public void setCatID(String CatID)throws SQLException,ClassNotFoundException {「in setter:」+ CatID); this.CatID = CatID; // products = product.searchProductsByCategory(null,null,CatID); } –

相關問題