gpt4 book ai didi

java - primefaces 命令按钮操作不适用于级联下拉菜单

转载 作者:行者123 更新时间:2023-11-30 04:46:48 29 4
gpt4 key购买 nike

我的 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);
}
}

什么可能导致此问题?怎么解决?

最佳答案

将您的 bean 从 RequestScoped 更改为 ViewScoped,这样,当 View 存在时, View 上的更改将被保留。

编辑:

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

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

添加更新语句;

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

关于java - primefaces 命令按钮操作不适用于级联下拉菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10793458/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com