在primefaces中级联下拉3.2不工作

时间:2012-05-28 12:56:00

标签: java java-ee primefaces

我希望在primefaces 3.2中使用级联下拉列表,但它不起作用。下面是我的xhtml代码:

<p:selectOneMenu style="width: 150px" value="#{watchBean.exchange}">
                    <f:selectItem itemLabel="NSE" itemValue="nse"/>
                    <f:selectItem itemLabel="BSE" itemValue="bse"/> 
                    <p:ajax event="change" update="sym" listener="#{watchBean.wow}" />
                </p:selectOneMenu> 
            <p:selectOneMenu style="width: 150px" id="sym" value="#{watchBean.sl}" var="scrip">
                <f:selectItems  itemLabel="#{scrip.scripSymbol}" itemValue="#{scrip.scripSymbol}"/>
            </p:selectOneMenu> 

bean代码:

import java.util.List;
import javax.annotation.ManagedBean;
import javax.inject.Named;
import javax.enterprise.context.RequestScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ValueChangeEvent;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.xml.ws.WebServiceRef;
import service.MasterScrip;
import service.StatelessWebService_Service;

/**
 *
 * @author root
 */
@javax.faces.bean.ManagedBean
@javax.faces.bean.RequestScoped
public class watchBean {
    @WebServiceRef(wsdlLocation = "WEB-INF/wsdl/localhost_8080/StatelessWebService/StatelessWebService.wsdl")
    private StatelessWebService_Service service;

    /** Creates a new instance of watchBean */
    public watchBean() {
    }
    String uname,scripSym,exchange;
    Integer scripID;
    List<UserTrack> ut;
List<MasterScrip> sl;
    public List<MasterScrip> getSl() {
        return sl;
    }

    public void setSl(List<MasterScrip> sl) {
        this.sl = sl;
    }


    public String getExchange() {

        return exchange;
    }

    public void setExchange(String exchange) {
        sl=getAllScripByExchange(exchange);
        setSl(sl);
        this.exchange = exchange;
    }
public void wow(ValueChangeEvent e)
{    
    sl=getAllScripByExchange((String)e.getNewValue());
   // setSl(sl);
    //FacesContext.getCurrentInstance().renderResponse();

    // sl=getAllScripByExchange(exchange);
} ....

我收到以下错误:

javax.el.MethodNotFoundException: Method not found: beans.watchBean@2e1b13.wow(javax.faces.event.AjaxBehaviorEvent)

我提到了How do I get PrimeFaces <p:selectOneMenu> to call valueChangeListener?并从我的代码中删除了监听器,只保留了第一个下拉列表的值属性,但它仍然不起作用,然后它没有给出错误,第二个下拉列表没有动态填充。 我陷入困境,这个错误的原因是什么,怎么解决?

1 个答案:

答案 0 :(得分:0)

1)从方法wow()中删除参数。 ajax监听器不带参数;执行该方法时,属性“exchange”包含新值 2)selectOneMenus应该被h:form
包围 3)第二个selectOneMenu是错误的。 selectOneMenu的value属性应该引用所选择的组合项;不是物品清单。 var属性位于f:selectItems标记中。 f:selectItems标记缺少value属性,该属性引用了项列表。它应该是这样的:

<p:selectOneMenu style="width: 150px" id="sym" value="#{watchBean.selectedItem}" >
          <f:selectItems value="#{watchBean.sl}" var="scrip"
                         itemLabel="#{scrip.scripSymbol}"
                         itemValue="#{scrip.scripSymbol}"/>
</p:selectOneMenu>