zoukankan      html  css  js  c++  java
  • Struts下html:select可以多选时的处理方法

    html:select是支持多选的,单选的时候很简单,后台就是接受一个String,多选的时候如何处理呢? 

    1、创建一个可以多选的select控件需要在属性列表中加入multiple="true"这样的代码,如下: 
    CODE: SELECT ALL
            <html:select property="userlist" size="6" styleClass="uglimitselect" multiple="true">
              <%
                 for (i=0; i<userlist.size(); i++) {
                   tmpstring = (String)userlist.get(i);
              %>
              <html:option value="<%=tmpstring%>"><%=tmpstring%></html:option>
              <%
                 }
              %>
            </html:select>


    2. 定义成multiple之后,对应的ActionFormBean中field要定义成一个String数组,注意,不能用ArrayList或是其他东西,只能用String数组,如下:

    CODE: SELECT ALL
           <!-- Create UG Queue Limit Action -->
           <action   path="/CreateUGQueueLimit"
                     type="com.jointforce.action.CreateUGQueueLimitAction"
                     name="CreateUGQueueLimitForm"
                     scope="request"
                     input="createugqueuelimit">
               <forward name="moduleunavailable" path="/jsp/joblimitunavailable.jsp"/>
               <forward name="createugqueuelimit" path="/jsp/createugqueuelimit.jsp"/>
               <forward name="success" path="/jsp/createugqueuelimitresult.jsp"/>
           </action>

          <!-- Create UG Queue Limit -->
          <form-bean name="CreateUGQueueLimitForm"
                     type="org.apache.struts.validator.DynaValidatorForm">
              <form-property name="userlist" type="java.lang.String[]"/>
              <form-property name="grouplist" type="java.lang.String[]"/>
              <form-property name="hostlist" type="java.lang.String[]"/>
          </form-bean>


    validation.xml中照旧:

    CODE: SELECT ALL
            <form name="CreateUGQueueLimitForm">
                <field property="userlist"></field>
                <field property="hostlist"></field>
                <field property="grouplist"></field>
            </form>

     最后在Action类里面这样就可以取到了: 


    String[] userlist = (String[])PropertyUtils.getProperty(form, "userlist"); 

    用一个for循环就可以取出东东: 

    for (int i=0; i<userlist.length; i++) { 
    System.out.println(userlist[i]); 
    }
  • 相关阅读:
    从头搭建Openstack运行环境(七)--实现负载均衡与外网访问
    ML2分层端口绑定技术在SDN开发中的应用(一)
    从头搭建Openstack运行环境(六)--租户网络间路由与防火墙
    翻译校对1
    pykube-pod.obj的json字符串解析
    第一版k8s
    the server does not allow access to the requested resource
    have fun of Docker
    Clean Development Series
    Understanding the GitHub Flow官方的是最好的,永远要看第一手资料
  • 原文地址:https://www.cnblogs.com/super119/p/1935008.html
Copyright © 2011-2022 走看看