在添加页面中有三个下拉列表,刚添加时候是正常的,当我修改的时候只允许修改一个下拉列表,修改后显示的时候,其他的下拉列表都变成初始值了!
关于下拉列表的初始值我是在po中写的,还有就是自己写了一个类 来放下拉列表的值!
po中的内容是:public String getCustTypeDesc( ) {
try {
switch (Integer.parseInt(this.custType.trim())) {
case 0:
return new String("非签约用户");
case 1:
return new String("签约用户");
default:
return new String("非签约用户");
}
} catch (Exception exp) {
return new String("非签约用户");
}
}
public String getCertTypeDesc( ) {
try {
switch (Integer.parseInt(this.certType.trim())) {
case 0:
return new String("身份证");
case 1:
return new String("军官证");
case 2:
return new String("护照");
case 3:
return new String("其他");
default:
return new String("身份证");
}
} catch (Exception exp) {
return new String("身份证");
}
}
public String getStateDesc( ) {
try {
switch (Integer.parseInt(this.state.trim())) {
case 0:
return new String("正常");
case 1:
return new String("冻结");
case 2:
return new String("其他");
default:
return new String("正常");
}
} catch (Exception exp) {
return new String("正常");
}
}
public String getSexDesc( ) {
try {
switch (Integer.parseInt(this.sex.trim())) {
case 0:
return new String("男");
case 1:
return new String("女");
default:
return new String("男");
}
} catch (Exception exp) {
return new String("男");
}
}
14 个解决方案
#1
这是自己的写的类:
public int doStartTag() throws JspException {
HttpServletRequest request = (HttpServletRequest)pageContext.getRequest();
JspWriter out = pageContext.getOut();
if (id.compareToIgnoreCase("pcustomercusttype") == 0)
listCustType(out);
else if (id.compareToIgnoreCase("pcustomercerttype") == 0)
listCertType(out);
else if (id.compareToIgnoreCase("pcustomersex") == 0)
listSex(out);
else if (id.compareToIgnoreCase("pcustomerstate") == 0)
listState(out);
//这是其中的一个方法
private void listCustType(JspWriter out) throws JspException {
try {
if ( enable == false )
out.println("<select class='text' name='custType' disabled >");
else
out.println("<select class='text' name='custType'>");
if ( value == 0 )
out.println("<option value='0' selected >非签约用户</option>");
else
out.println("<option value='0'>非签约用户</option>");
if ( value == 1 )
out.println("<option value='1' selected >签约用户</option>");
else
out.println("<option value='1'>签约用户</option>");
if ( value != 1 && value != 0)
out.println("<option value='2' selected >所有用户</option>");
else
out.println("<option value='2'>所有用户</option>");
out.println("</select>");
} catch (java.io.IOException e) {
throw new JspTagException(e.getMessage());
}
}
public int doStartTag() throws JspException {
HttpServletRequest request = (HttpServletRequest)pageContext.getRequest();
JspWriter out = pageContext.getOut();
if (id.compareToIgnoreCase("pcustomercusttype") == 0)
listCustType(out);
else if (id.compareToIgnoreCase("pcustomercerttype") == 0)
listCertType(out);
else if (id.compareToIgnoreCase("pcustomersex") == 0)
listSex(out);
else if (id.compareToIgnoreCase("pcustomerstate") == 0)
listState(out);
//这是其中的一个方法
private void listCustType(JspWriter out) throws JspException {
try {
if ( enable == false )
out.println("<select class='text' name='custType' disabled >");
else
out.println("<select class='text' name='custType'>");
if ( value == 0 )
out.println("<option value='0' selected >非签约用户</option>");
else
out.println("<option value='0'>非签约用户</option>");
if ( value == 1 )
out.println("<option value='1' selected >签约用户</option>");
else
out.println("<option value='1'>签约用户</option>");
if ( value != 1 && value != 0)
out.println("<option value='2' selected >所有用户</option>");
else
out.println("<option value='2'>所有用户</option>");
out.println("</select>");
} catch (java.io.IOException e) {
throw new JspTagException(e.getMessage());
}
}
#2
这个是修改页面:
<TD width="100%" height=40 vAlign=bottom>
<TABLE width=100% border=0 cellPadding=3 cellSpacing=0>
<TR>
<TD width="10%" height=25 nowrap><div align="center">客户号码</div></TD>
<TD width="23%"><input style="border-style:none" type="text" value="<%=pc.getCustCode() %>" name="custCode"
style="background-color: #eaeaea" readonly/>
</TD>
<TD width="7%" height=25 nowrap><div align="center">客户密码</div></TD>
<TD width="23%"><input style="border-style:none" type="password" name=custPwd value="<%=pc.getCustPwd() %>"
style="background-color: #eaeaea" readonly></TD>
</TR>
<TR>
<TD width="10%" nowrap><div align="center">客户姓名</TD>
<TD width="27%"><input style="border-style:none" type="text" name="custName" value="<%=pc.getCustName() %>"
style="background-color: #eaeaea" readonly></TD>
<TD width="10%" nowrap><div align="center">客户类型</TD>
<TD width="27%"><input style="border-style:none" type="text" name=custType value="<%=pc.getCustTypeDesc()%>"
style="background-color: #eaeaea" readonly></TD>
</TR>
<tr>
<TD width="10%" nowrap><div align="center">证件类型</TD>
<TD width="27%"><input style="border-style:none" type="text" name="certType" value="<%=pc.getCertTypeDesc()%>"
style="background-color: #eaeaea" readonly></TD>
<TD width="7%" height=25 nowrap><div align="center">证件号码</div></TD>
<TD width="23%"><input style="border-style:none" type="text" name="certNo" value="<%=pc.getCertNo() %>"
style="background-color: #eaeaea" readonly></TD>
</tr>
<TR>
<TD width="10%" nowrap><div align="center">性别</TD>
<TD width="23%"><input style="border-style:none" type="text" name="sex" value="<%=pc.getSexDesc()%>"
style="background-color:#eaeaea" readonly></TD>
<TD width="10%" nowrap><div align="center">年龄</TD>
<TD width="23%"><input style="border-style:none" type="text" name="age" value="<%=pc.getAge() %>"
style="background-color:#eaeaea" readonly></TD>
</TR>
<TR>
<TD width="7%" height=25 nowrap><div align="center">手机号码</div></TD>
<TD width="23%"><input style="border-style:none" type="text" name="teleNo" value="<%=pc.getTeleNo() %>"
style="background-color:#eaeaea" readonly></TD>
<TD width="10%" nowrap><div align="center">Email</TD>
<TD width="23%"><input style="border-style:none" type="text" name="email" value="<%=pc.getEmail() %>"
style="background-color:#eaeaea" readonly></TD>
</TR>
<tr>
<TD width="10%" nowrap><div align="center">地址</TD>
<TD width="23%"><input style="border-style:none" type="text" name="address" value="<%=pc.getAddress() %>"
style="background-color:#eaeaea" readonly></TD>
<TD width="7%" height=25 nowrap><div align="center">创建日期</div></TD>
<TD width="23%">
<input style="border-style:none" type="text" name="createTimeStamp" value="<%=pc.getCreateTimestamp() %>"
style="background-color:#eaeaea" readonly />
</TD>
</tr>
<tr>
<TD width="10%" nowrap><div align="center">状态</TD>
<TD width="23%"><pmgt:status id="pcustomerstate" value="0" enable="true" /></TD>
</tr>
修改的时候值允许修改状态,其他的下拉列表都不允许修改。
请各位帮帮忙!
<TD width="100%" height=40 vAlign=bottom>
<TABLE width=100% border=0 cellPadding=3 cellSpacing=0>
<TR>
<TD width="10%" height=25 nowrap><div align="center">客户号码</div></TD>
<TD width="23%"><input style="border-style:none" type="text" value="<%=pc.getCustCode() %>" name="custCode"
style="background-color: #eaeaea" readonly/>
</TD>
<TD width="7%" height=25 nowrap><div align="center">客户密码</div></TD>
<TD width="23%"><input style="border-style:none" type="password" name=custPwd value="<%=pc.getCustPwd() %>"
style="background-color: #eaeaea" readonly></TD>
</TR>
<TR>
<TD width="10%" nowrap><div align="center">客户姓名</TD>
<TD width="27%"><input style="border-style:none" type="text" name="custName" value="<%=pc.getCustName() %>"
style="background-color: #eaeaea" readonly></TD>
<TD width="10%" nowrap><div align="center">客户类型</TD>
<TD width="27%"><input style="border-style:none" type="text" name=custType value="<%=pc.getCustTypeDesc()%>"
style="background-color: #eaeaea" readonly></TD>
</TR>
<tr>
<TD width="10%" nowrap><div align="center">证件类型</TD>
<TD width="27%"><input style="border-style:none" type="text" name="certType" value="<%=pc.getCertTypeDesc()%>"
style="background-color: #eaeaea" readonly></TD>
<TD width="7%" height=25 nowrap><div align="center">证件号码</div></TD>
<TD width="23%"><input style="border-style:none" type="text" name="certNo" value="<%=pc.getCertNo() %>"
style="background-color: #eaeaea" readonly></TD>
</tr>
<TR>
<TD width="10%" nowrap><div align="center">性别</TD>
<TD width="23%"><input style="border-style:none" type="text" name="sex" value="<%=pc.getSexDesc()%>"
style="background-color:#eaeaea" readonly></TD>
<TD width="10%" nowrap><div align="center">年龄</TD>
<TD width="23%"><input style="border-style:none" type="text" name="age" value="<%=pc.getAge() %>"
style="background-color:#eaeaea" readonly></TD>
</TR>
<TR>
<TD width="7%" height=25 nowrap><div align="center">手机号码</div></TD>
<TD width="23%"><input style="border-style:none" type="text" name="teleNo" value="<%=pc.getTeleNo() %>"
style="background-color:#eaeaea" readonly></TD>
<TD width="10%" nowrap><div align="center">Email</TD>
<TD width="23%"><input style="border-style:none" type="text" name="email" value="<%=pc.getEmail() %>"
style="background-color:#eaeaea" readonly></TD>
</TR>
<tr>
<TD width="10%" nowrap><div align="center">地址</TD>
<TD width="23%"><input style="border-style:none" type="text" name="address" value="<%=pc.getAddress() %>"
style="background-color:#eaeaea" readonly></TD>
<TD width="7%" height=25 nowrap><div align="center">创建日期</div></TD>
<TD width="23%">
<input style="border-style:none" type="text" name="createTimeStamp" value="<%=pc.getCreateTimestamp() %>"
style="background-color:#eaeaea" readonly />
</TD>
</tr>
<tr>
<TD width="10%" nowrap><div align="center">状态</TD>
<TD width="23%"><pmgt:status id="pcustomerstate" value="0" enable="true" /></TD>
</tr>
修改的时候值允许修改状态,其他的下拉列表都不允许修改。
请各位帮帮忙!
#3
当你进入修改页面的时候把你不需要的select 设置成disable
或者在你提交修改的时候 在你的提交button上设置一个onclick,然后用javascript把
你不需要的select设置成disable,struts就得不到值了
或者在你提交修改的时候 在你的提交button上设置一个onclick,然后用javascript把
你不需要的select设置成disable,struts就得不到值了
this.form.名.disabled=true
#4
上面的文字看懂了,下面的代码没有看懂,代码是写在哪的?
#5
写在jsp上,这是个javascript
#6
我试了,是得不到值,这样在修改完之后 相应设置为disable 的值,在显示的时候都是null
#7
action里得到null了 你就别更新这个下拉选的值了啊
#8
我按照你说的写了javascript,但是还是不行,因为我初始值都是0.非签约用户。我找个了签约用户来修改,改完之后保存,就又变初始值了!
#9
你在action里 得到了哪个下拉选的值就更新哪个,你看看你更新的时候是否输出了正确的sql语句,可能是你没更新对
#10
我把action改成:
/*
* 对数据进行修改的回显
*/
public ActionForward detail(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)throws Exception {
String custid=request.getParameter("custId");
try{
PCustomer pc= pcustomerserviceimpl.findBycustId(custid);
request.setAttribute("pc", pc);
}catch(Exception exp){
exp.printStackTrace();
}
return mapping.findForward("pcustomer_detail");
}
/*
* 对数据进行修改
*/
public ActionForward update(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)throws Exception {
PCustomerForm cf = (PCustomerForm) form;
try{
PCustomer data = this.pcustomerserviceimpl.findBycustId(cf.getCustId());
data.setState(cf.getState());
pcustomerserviceimpl.update(data);
}catch(Exception exp){
exp.printStackTrace();
}
return browser(mapping,form,request,response);
}
又报错了:
org.hibernate.HibernateException: Found two representations of same collection
at org.hibernate.engine.Collections.processReachableCollection(Collections.java:123)
at org.hibernate.event.def.FlushVisitor.processCollection(FlushVisitor.java:37)
at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:104)
at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:64)
at org.hibernate.event.def.AbstractVisitor.processEntityPropertyValues(AbstractVisitor.java:58)
at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:198)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:190)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:70)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:324)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)
at com.crinode.mbank.pmgt.dao.Impl.PCustomerDaoImpl.update(PCustomerDaoImpl.java:104)
at com.crinode.mbank.pmgt.service.Impl.PCustomerserviceImpl.update(PCustomerserviceImpl.java:50)
at com.crinode.mbank.pmgt.action.PCustomerAction.update(PCustomerAction.java:212)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:270)
at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:187)
at org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:110)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at com.crinode.mbank.pmgt.basedata.SetCharsetFilter.doFilter(SetCharsetFilter.java:13)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at com.crinode.mbank.pmgt.basedata.ReqFilter.doFilter(ReqFilter.java:215)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:874)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Unknown Source)
/*
* 对数据进行修改的回显
*/
public ActionForward detail(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)throws Exception {
String custid=request.getParameter("custId");
try{
PCustomer pc= pcustomerserviceimpl.findBycustId(custid);
request.setAttribute("pc", pc);
}catch(Exception exp){
exp.printStackTrace();
}
return mapping.findForward("pcustomer_detail");
}
/*
* 对数据进行修改
*/
public ActionForward update(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)throws Exception {
PCustomerForm cf = (PCustomerForm) form;
try{
PCustomer data = this.pcustomerserviceimpl.findBycustId(cf.getCustId());
data.setState(cf.getState());
pcustomerserviceimpl.update(data);
}catch(Exception exp){
exp.printStackTrace();
}
return browser(mapping,form,request,response);
}
又报错了:
org.hibernate.HibernateException: Found two representations of same collection
at org.hibernate.engine.Collections.processReachableCollection(Collections.java:123)
at org.hibernate.event.def.FlushVisitor.processCollection(FlushVisitor.java:37)
at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:104)
at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:64)
at org.hibernate.event.def.AbstractVisitor.processEntityPropertyValues(AbstractVisitor.java:58)
at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:198)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:190)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:70)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:324)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)
at com.crinode.mbank.pmgt.dao.Impl.PCustomerDaoImpl.update(PCustomerDaoImpl.java:104)
at com.crinode.mbank.pmgt.service.Impl.PCustomerserviceImpl.update(PCustomerserviceImpl.java:50)
at com.crinode.mbank.pmgt.action.PCustomerAction.update(PCustomerAction.java:212)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:270)
at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:187)
at org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:110)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at com.crinode.mbank.pmgt.basedata.SetCharsetFilter.doFilter(SetCharsetFilter.java:13)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at com.crinode.mbank.pmgt.basedata.ReqFilter.doFilter(ReqFilter.java:215)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:874)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Unknown Source)
#11
PCustomer data = this.pcustomerserviceimpl.findBycustId(cf.getCustId());
//在得到以后判断下是否是空的,你现在这样得到了如果是空的
data.setState(cf.getState());
pcustomerserviceimpl.update(data); //你在这更新就把原来有的类型弄成空的了,所以你显示的时候全为0了,明白了吧
//在得到以后判断下是否是空的,你现在这样得到了如果是空的
data.setState(cf.getState());
pcustomerserviceimpl.update(data); //你在这更新就把原来有的类型弄成空的了,所以你显示的时候全为0了,明白了吧
#12
应该怎么写?
#13
是判断cf.getCustId()是否是空的哈,上面没写清楚
#14
问题已经解决!
#1
这是自己的写的类:
public int doStartTag() throws JspException {
HttpServletRequest request = (HttpServletRequest)pageContext.getRequest();
JspWriter out = pageContext.getOut();
if (id.compareToIgnoreCase("pcustomercusttype") == 0)
listCustType(out);
else if (id.compareToIgnoreCase("pcustomercerttype") == 0)
listCertType(out);
else if (id.compareToIgnoreCase("pcustomersex") == 0)
listSex(out);
else if (id.compareToIgnoreCase("pcustomerstate") == 0)
listState(out);
//这是其中的一个方法
private void listCustType(JspWriter out) throws JspException {
try {
if ( enable == false )
out.println("<select class='text' name='custType' disabled >");
else
out.println("<select class='text' name='custType'>");
if ( value == 0 )
out.println("<option value='0' selected >非签约用户</option>");
else
out.println("<option value='0'>非签约用户</option>");
if ( value == 1 )
out.println("<option value='1' selected >签约用户</option>");
else
out.println("<option value='1'>签约用户</option>");
if ( value != 1 && value != 0)
out.println("<option value='2' selected >所有用户</option>");
else
out.println("<option value='2'>所有用户</option>");
out.println("</select>");
} catch (java.io.IOException e) {
throw new JspTagException(e.getMessage());
}
}
public int doStartTag() throws JspException {
HttpServletRequest request = (HttpServletRequest)pageContext.getRequest();
JspWriter out = pageContext.getOut();
if (id.compareToIgnoreCase("pcustomercusttype") == 0)
listCustType(out);
else if (id.compareToIgnoreCase("pcustomercerttype") == 0)
listCertType(out);
else if (id.compareToIgnoreCase("pcustomersex") == 0)
listSex(out);
else if (id.compareToIgnoreCase("pcustomerstate") == 0)
listState(out);
//这是其中的一个方法
private void listCustType(JspWriter out) throws JspException {
try {
if ( enable == false )
out.println("<select class='text' name='custType' disabled >");
else
out.println("<select class='text' name='custType'>");
if ( value == 0 )
out.println("<option value='0' selected >非签约用户</option>");
else
out.println("<option value='0'>非签约用户</option>");
if ( value == 1 )
out.println("<option value='1' selected >签约用户</option>");
else
out.println("<option value='1'>签约用户</option>");
if ( value != 1 && value != 0)
out.println("<option value='2' selected >所有用户</option>");
else
out.println("<option value='2'>所有用户</option>");
out.println("</select>");
} catch (java.io.IOException e) {
throw new JspTagException(e.getMessage());
}
}
#2
这个是修改页面:
<TD width="100%" height=40 vAlign=bottom>
<TABLE width=100% border=0 cellPadding=3 cellSpacing=0>
<TR>
<TD width="10%" height=25 nowrap><div align="center">客户号码</div></TD>
<TD width="23%"><input style="border-style:none" type="text" value="<%=pc.getCustCode() %>" name="custCode"
style="background-color: #eaeaea" readonly/>
</TD>
<TD width="7%" height=25 nowrap><div align="center">客户密码</div></TD>
<TD width="23%"><input style="border-style:none" type="password" name=custPwd value="<%=pc.getCustPwd() %>"
style="background-color: #eaeaea" readonly></TD>
</TR>
<TR>
<TD width="10%" nowrap><div align="center">客户姓名</TD>
<TD width="27%"><input style="border-style:none" type="text" name="custName" value="<%=pc.getCustName() %>"
style="background-color: #eaeaea" readonly></TD>
<TD width="10%" nowrap><div align="center">客户类型</TD>
<TD width="27%"><input style="border-style:none" type="text" name=custType value="<%=pc.getCustTypeDesc()%>"
style="background-color: #eaeaea" readonly></TD>
</TR>
<tr>
<TD width="10%" nowrap><div align="center">证件类型</TD>
<TD width="27%"><input style="border-style:none" type="text" name="certType" value="<%=pc.getCertTypeDesc()%>"
style="background-color: #eaeaea" readonly></TD>
<TD width="7%" height=25 nowrap><div align="center">证件号码</div></TD>
<TD width="23%"><input style="border-style:none" type="text" name="certNo" value="<%=pc.getCertNo() %>"
style="background-color: #eaeaea" readonly></TD>
</tr>
<TR>
<TD width="10%" nowrap><div align="center">性别</TD>
<TD width="23%"><input style="border-style:none" type="text" name="sex" value="<%=pc.getSexDesc()%>"
style="background-color:#eaeaea" readonly></TD>
<TD width="10%" nowrap><div align="center">年龄</TD>
<TD width="23%"><input style="border-style:none" type="text" name="age" value="<%=pc.getAge() %>"
style="background-color:#eaeaea" readonly></TD>
</TR>
<TR>
<TD width="7%" height=25 nowrap><div align="center">手机号码</div></TD>
<TD width="23%"><input style="border-style:none" type="text" name="teleNo" value="<%=pc.getTeleNo() %>"
style="background-color:#eaeaea" readonly></TD>
<TD width="10%" nowrap><div align="center">Email</TD>
<TD width="23%"><input style="border-style:none" type="text" name="email" value="<%=pc.getEmail() %>"
style="background-color:#eaeaea" readonly></TD>
</TR>
<tr>
<TD width="10%" nowrap><div align="center">地址</TD>
<TD width="23%"><input style="border-style:none" type="text" name="address" value="<%=pc.getAddress() %>"
style="background-color:#eaeaea" readonly></TD>
<TD width="7%" height=25 nowrap><div align="center">创建日期</div></TD>
<TD width="23%">
<input style="border-style:none" type="text" name="createTimeStamp" value="<%=pc.getCreateTimestamp() %>"
style="background-color:#eaeaea" readonly />
</TD>
</tr>
<tr>
<TD width="10%" nowrap><div align="center">状态</TD>
<TD width="23%"><pmgt:status id="pcustomerstate" value="0" enable="true" /></TD>
</tr>
修改的时候值允许修改状态,其他的下拉列表都不允许修改。
请各位帮帮忙!
<TD width="100%" height=40 vAlign=bottom>
<TABLE width=100% border=0 cellPadding=3 cellSpacing=0>
<TR>
<TD width="10%" height=25 nowrap><div align="center">客户号码</div></TD>
<TD width="23%"><input style="border-style:none" type="text" value="<%=pc.getCustCode() %>" name="custCode"
style="background-color: #eaeaea" readonly/>
</TD>
<TD width="7%" height=25 nowrap><div align="center">客户密码</div></TD>
<TD width="23%"><input style="border-style:none" type="password" name=custPwd value="<%=pc.getCustPwd() %>"
style="background-color: #eaeaea" readonly></TD>
</TR>
<TR>
<TD width="10%" nowrap><div align="center">客户姓名</TD>
<TD width="27%"><input style="border-style:none" type="text" name="custName" value="<%=pc.getCustName() %>"
style="background-color: #eaeaea" readonly></TD>
<TD width="10%" nowrap><div align="center">客户类型</TD>
<TD width="27%"><input style="border-style:none" type="text" name=custType value="<%=pc.getCustTypeDesc()%>"
style="background-color: #eaeaea" readonly></TD>
</TR>
<tr>
<TD width="10%" nowrap><div align="center">证件类型</TD>
<TD width="27%"><input style="border-style:none" type="text" name="certType" value="<%=pc.getCertTypeDesc()%>"
style="background-color: #eaeaea" readonly></TD>
<TD width="7%" height=25 nowrap><div align="center">证件号码</div></TD>
<TD width="23%"><input style="border-style:none" type="text" name="certNo" value="<%=pc.getCertNo() %>"
style="background-color: #eaeaea" readonly></TD>
</tr>
<TR>
<TD width="10%" nowrap><div align="center">性别</TD>
<TD width="23%"><input style="border-style:none" type="text" name="sex" value="<%=pc.getSexDesc()%>"
style="background-color:#eaeaea" readonly></TD>
<TD width="10%" nowrap><div align="center">年龄</TD>
<TD width="23%"><input style="border-style:none" type="text" name="age" value="<%=pc.getAge() %>"
style="background-color:#eaeaea" readonly></TD>
</TR>
<TR>
<TD width="7%" height=25 nowrap><div align="center">手机号码</div></TD>
<TD width="23%"><input style="border-style:none" type="text" name="teleNo" value="<%=pc.getTeleNo() %>"
style="background-color:#eaeaea" readonly></TD>
<TD width="10%" nowrap><div align="center">Email</TD>
<TD width="23%"><input style="border-style:none" type="text" name="email" value="<%=pc.getEmail() %>"
style="background-color:#eaeaea" readonly></TD>
</TR>
<tr>
<TD width="10%" nowrap><div align="center">地址</TD>
<TD width="23%"><input style="border-style:none" type="text" name="address" value="<%=pc.getAddress() %>"
style="background-color:#eaeaea" readonly></TD>
<TD width="7%" height=25 nowrap><div align="center">创建日期</div></TD>
<TD width="23%">
<input style="border-style:none" type="text" name="createTimeStamp" value="<%=pc.getCreateTimestamp() %>"
style="background-color:#eaeaea" readonly />
</TD>
</tr>
<tr>
<TD width="10%" nowrap><div align="center">状态</TD>
<TD width="23%"><pmgt:status id="pcustomerstate" value="0" enable="true" /></TD>
</tr>
修改的时候值允许修改状态,其他的下拉列表都不允许修改。
请各位帮帮忙!
#3
当你进入修改页面的时候把你不需要的select 设置成disable
或者在你提交修改的时候 在你的提交button上设置一个onclick,然后用javascript把
你不需要的select设置成disable,struts就得不到值了
或者在你提交修改的时候 在你的提交button上设置一个onclick,然后用javascript把
你不需要的select设置成disable,struts就得不到值了
this.form.名.disabled=true
#4
上面的文字看懂了,下面的代码没有看懂,代码是写在哪的?
#5
写在jsp上,这是个javascript
#6
我试了,是得不到值,这样在修改完之后 相应设置为disable 的值,在显示的时候都是null
#7
action里得到null了 你就别更新这个下拉选的值了啊
#8
我按照你说的写了javascript,但是还是不行,因为我初始值都是0.非签约用户。我找个了签约用户来修改,改完之后保存,就又变初始值了!
#9
你在action里 得到了哪个下拉选的值就更新哪个,你看看你更新的时候是否输出了正确的sql语句,可能是你没更新对
#10
我把action改成:
/*
* 对数据进行修改的回显
*/
public ActionForward detail(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)throws Exception {
String custid=request.getParameter("custId");
try{
PCustomer pc= pcustomerserviceimpl.findBycustId(custid);
request.setAttribute("pc", pc);
}catch(Exception exp){
exp.printStackTrace();
}
return mapping.findForward("pcustomer_detail");
}
/*
* 对数据进行修改
*/
public ActionForward update(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)throws Exception {
PCustomerForm cf = (PCustomerForm) form;
try{
PCustomer data = this.pcustomerserviceimpl.findBycustId(cf.getCustId());
data.setState(cf.getState());
pcustomerserviceimpl.update(data);
}catch(Exception exp){
exp.printStackTrace();
}
return browser(mapping,form,request,response);
}
又报错了:
org.hibernate.HibernateException: Found two representations of same collection
at org.hibernate.engine.Collections.processReachableCollection(Collections.java:123)
at org.hibernate.event.def.FlushVisitor.processCollection(FlushVisitor.java:37)
at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:104)
at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:64)
at org.hibernate.event.def.AbstractVisitor.processEntityPropertyValues(AbstractVisitor.java:58)
at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:198)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:190)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:70)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:324)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)
at com.crinode.mbank.pmgt.dao.Impl.PCustomerDaoImpl.update(PCustomerDaoImpl.java:104)
at com.crinode.mbank.pmgt.service.Impl.PCustomerserviceImpl.update(PCustomerserviceImpl.java:50)
at com.crinode.mbank.pmgt.action.PCustomerAction.update(PCustomerAction.java:212)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:270)
at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:187)
at org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:110)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at com.crinode.mbank.pmgt.basedata.SetCharsetFilter.doFilter(SetCharsetFilter.java:13)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at com.crinode.mbank.pmgt.basedata.ReqFilter.doFilter(ReqFilter.java:215)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:874)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Unknown Source)
/*
* 对数据进行修改的回显
*/
public ActionForward detail(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)throws Exception {
String custid=request.getParameter("custId");
try{
PCustomer pc= pcustomerserviceimpl.findBycustId(custid);
request.setAttribute("pc", pc);
}catch(Exception exp){
exp.printStackTrace();
}
return mapping.findForward("pcustomer_detail");
}
/*
* 对数据进行修改
*/
public ActionForward update(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)throws Exception {
PCustomerForm cf = (PCustomerForm) form;
try{
PCustomer data = this.pcustomerserviceimpl.findBycustId(cf.getCustId());
data.setState(cf.getState());
pcustomerserviceimpl.update(data);
}catch(Exception exp){
exp.printStackTrace();
}
return browser(mapping,form,request,response);
}
又报错了:
org.hibernate.HibernateException: Found two representations of same collection
at org.hibernate.engine.Collections.processReachableCollection(Collections.java:123)
at org.hibernate.event.def.FlushVisitor.processCollection(FlushVisitor.java:37)
at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:104)
at org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:64)
at org.hibernate.event.def.AbstractVisitor.processEntityPropertyValues(AbstractVisitor.java:58)
at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:198)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:190)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:70)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:324)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)
at com.crinode.mbank.pmgt.dao.Impl.PCustomerDaoImpl.update(PCustomerDaoImpl.java:104)
at com.crinode.mbank.pmgt.service.Impl.PCustomerserviceImpl.update(PCustomerserviceImpl.java:50)
at com.crinode.mbank.pmgt.action.PCustomerAction.update(PCustomerAction.java:212)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:270)
at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:187)
at org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:110)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at com.crinode.mbank.pmgt.basedata.SetCharsetFilter.doFilter(SetCharsetFilter.java:13)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at com.crinode.mbank.pmgt.basedata.ReqFilter.doFilter(ReqFilter.java:215)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:874)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Unknown Source)
#11
PCustomer data = this.pcustomerserviceimpl.findBycustId(cf.getCustId());
//在得到以后判断下是否是空的,你现在这样得到了如果是空的
data.setState(cf.getState());
pcustomerserviceimpl.update(data); //你在这更新就把原来有的类型弄成空的了,所以你显示的时候全为0了,明白了吧
//在得到以后判断下是否是空的,你现在这样得到了如果是空的
data.setState(cf.getState());
pcustomerserviceimpl.update(data); //你在这更新就把原来有的类型弄成空的了,所以你显示的时候全为0了,明白了吧
#12
应该怎么写?
#13
是判断cf.getCustId()是否是空的哈,上面没写清楚
#14
问题已经解决!