论坛首页 Java企业应用论坛

struts中如何设置和获得一个列表框

浏览 10061 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2005-09-16  
我的select的value和label属性都是可变的,我想在页面中设置并传到后台,或从后台读取某属性在页面上显示。怎么做呢?请说详细点。
   发表时间:2005-09-16  
使用<html:options />. 你的label 和value 的Collection 可以在action中初始化.

具体使用方法自己看看doc吧
0 请登录后投票
   发表时间:2005-09-16  
就在页面上用LabelValueBean,想要什么值就设什么值,只是代码不雅观。你斟酌一下。
0 请登录后投票
   发表时间:2005-09-16  
若用在页面中写代码方式也不是不能解决,但这样又有一个问题:我要等到用户提交时才能设置这些集合,这个时机如何把握?用javascript判断又访问不到嵌入的java代码,用java 代码又无法判断。。。。how???
0 请登录后投票
   发表时间:2005-09-20  
javascript里面嵌入JAVA代码就可以了.像这样:

<% Vector shopList=(Vector)shopBean.findShopList); %>

<SCRIPT LANGUAGE="JavaScript1.2">
var allShopArr = new Array();
     <%
   int ss = 0;
   if( null != shopList){
   for (Iterator s = shopList.iterator(); s.hasNext();) {
            ShopModel shopModel = (ShopModel)s.next();  
               
        %>           
                  allShopArr[<%= ss %>] = new Object();
                  allShopArr[<%= ss %>].Id = "<%= shopModel.getShopID() %>";
                  allShopArr[<%= ss %>].Name = "<%= shopModel.getShopShortName() %>";
        <%
             ss ++;
           }
           }
        %>



function goto(this) {
    // 这里写上你的ACTION
    //这是当前访问的OPTION: this.selectedIndex;
    //这是当前访问的OPTION的VALUE: allShopArr [this.selectedIndex].ID;
    //这是当前访问的OPTION的LABLE: allShopArr [this.selectedIndex].Name;

}
</script>

<html:select name="allShopId" multiple id="allShopId" size=6 style="width:168px" onChange="javascript:goto(this)">
                      <%  for (Iterator i = shopList.iterator(); i.hasNext();) {
                  ShopModel shopModel = (ShopModel)i.next();
                  String shopName=shopModel.getShopShortName();
                  long shopId=shopModel.getShopID();
             
                  %>
                      <html:option value="<%=String.valueOf(shopId)%>"><%=shopName%></html:option>
                      <%}%>
</html:select>
0 请登录后投票
   发表时间:2005-11-03  
html:optionsCollection
0 请登录后投票
   发表时间:2005-12-07  
我举个例子,比如在jsp页面有个下拉列表框
<html:select property="status">
        <html:options collection="status" property="value" labelProperty="label"/>
</html:select>
在dao里有此方法,简单起见,没有从数据库中取。
public Collection getStatus()
{
     ArrayList rslist = new ArrayList();
     HashMap rscol1 = new HashMap();
     HashMap rscol2 = new HashMap();
     HashMap rscol3 = new HashMap();
     rscol1.put("value","1");
     rscol1.put("label","状态1");
     rslist.add(rscol1);
     rscol2.put("value","2");
     rscol2.put("label","状态2");
     rslist.add(rscol2);
     rscol3.put("value","3");
     rscol3.put("label","状态3");
     rslist.add(rscol3);
     return rslist;
}
在jsp表单相应的form里声明
private String status;
在action的execute方法中调用dao中的方法给下拉列表赋值
httpServletRequest.setAttribute("status",dao.getStatus());
如此这般,就可以实现了下拉列表的选择操作。
0 请登录后投票
   发表时间:2006-01-02  
<bean:define id="_deptList" name="listSearchForm" property="departmentList" type="java.util.Collection" scope="request" />
         <html:select property="deptId"  size="1">
          <html:options collection="_deptList" property="value" labelProperty="label" />
         </html:select>
0 请登录后投票
   发表时间:2006-01-13  
这种情况用AJAX最好了,避免刷新或者在页面上放一大堆的js数据
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics