我想用Struts中的下拉框实现一个功能,功能是,在A页面当下拉框的值发生变化时触发onchange事件,提交到一个Action,在进行业务处理,然手在返回到A页面,这时下拉框的值要是,事件后我选择的值,而非它自已默认选中的,怎么实现啊? 我是用LableValueBean来设置select值的
请大家教我,谢谢。

解决方案 »

  1.   

    比如你的select像下面这样        <html:select property="code" onchange="selectChange(this);">
                <html:optionsCollection name="lableValueList" />
            </html:select>
    选一个值--onchange--提交,我这的名称是code,所以这个值会被提交到你的actionForm的code字段中,
    在action中处理完业务返回页面时,只要保证actionForm的code字段仍然是刚刚你提交的那个值,
    页面的select就会自动对应上刚才你所选的
      

  2.   

    JSP:
    //JS
    function go()  
    {   
    var customerId = document.Form.mrCustomer.value;
    location.href="/action.do?customerId=" + customerId;
    }
    //END JS<html:select property="mrCustomer" style="width:170px" onchange="goJobsite();" >
      <logic:present name="customerList" scope="request">
        <html:options collection="customerList" property="customerId" labelProperty="customerName" />
      </logic:present>
    </html:select>
    ACTION:
    meterReadingForm.setMrCustomer(request.getParameter("customerId"))能看懂吧
      

  3.   

    把你选择的值做为请求参数传到 Action 中去,
    在 Action 处理完之后又把这个值放入 request 中去 
    比如: request.setAttribute("parameterName","selectValue");
    在页面上用 EL 取出来 比如 : value="${requestScope.parameterName}"
      

  4.   

       JSP: 
    //JS 
    function go()  
    {  
    var customerId = document.Form.mrCustomer.value; 
    location.href="/action.do?customerId=" + customerId; 

    //END JS <html:select property="mrCustomer" style="width:170px" onchange="goJobsite();" > 
      <logic:present name="customerList" scope="request"> 
        <html:options collection="customerList" property="customerId" labelProperty="customerName" /> 
      </logic:present> 
    </html:select> 
    ACTION: 
    meterReadingForm.setMrCustomer(request.getParameter("customerId")) 能看懂吧 中的“customerList”在哪里定义的啊?
      

  5.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【myzhou】截止到2008-06-26 23:50:15的历史汇总数据(不包括此帖):
    发帖数:3                  发帖分:80                 
    结贴数:0                  结贴分:0                  
    未结数:3                  未结分:80                 
    结贴率:0.00  %            结分率:0.00  %            
    如何结贴请参考这里:http://topic.csdn.net/u/20080501/09/ef7ba1b3-6466-49f6-9d92-36fe6d471dd1.html
      

  6.   

    csdn  这个论坛真不好玩
      

  7.   

    建议ajax 这种情况为啥要提交表单呢?
      

  8.   

    如果你必须或者非得这么做,最简单的方法,把业务罗辑放form的validate方法中,并且返回error............