1

我的 xhtml 页面上有级联下拉菜单,并且工作正常,但是当我从子级或级联下拉菜单的第二个下拉菜单中选择一个值后单击命令按钮时,出现以下错误:

sourceId=frm:sym[severity=(ERROR 2), summary=(frm:sym: Validation Error: Value is not valid), detail=(frm:sym: Validation Error: Value is not valid)]

XHTML 代码:

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

    <p:commandButton label="add to watch" value="add to watch" id="btnAdd" action="#{watchBean.addUserTrack()}" ajax="false"/>              
    <p:dataTable id="dt" var="track" .....>

豆子代码:

@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() {
        //sl=getAllScripByExchange((String)e.getNewValue());
        // setSl(sl);
        //FacesContext.getCurrentInstance().renderResponse();
        sl=getAllScripByExchange(exchange);
    }

    public List<UserTrack> getUt() {
        HttpServletRequest req=(HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
        HttpSession session=req.getSession();
        this.uname=(String)session.getAttribute("uname");
        ut=getAllUserTrack(uname);
        return ut;
    }

    //getter setter
    public void addUserTrack() {
        HttpServletRequest req=(HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
        HttpSession session=req.getSession();
        this.uname=(String)session.getAttribute("uname");
        MasterScrip sm=getScripBySymbol(scripSym);
        scripID=sm.getScripID();
        addUserTrack(uname, scripID);
    }
}

什么可能导致这个问题?我该如何解决?

4

1 回答 1

2

将 bean 从 RequestScoped 更改为 ViewScoped,这样视图上的更改将在视图存在时保留。

编辑:

根据您的评论,您在处理列表后忘记更新数据表。改变这个

<p:commandButton label="add to watch" value="add to watch" id="btnAdd" action="#{watchBean.addUserTrack()}" ajax="false"/>

添加update句子;

<p:commandButton label="add to watch" value="add to watch" id="btnAdd" action="#{watchBean.addUserTrack()}" ajax="false" update="dt"/>
于 2012-05-29T05:39:38.507 回答