我的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" .....>
Bean代码:
@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);
}
}
可能导致此问题的原因是什么?我该如何解决?
答案 0 :(得分: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"/>