Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何从Struts 2中的select标记映射多个值?_Java_Jquery_Jquery Ui_Jsp_Struts2 - Fatal编程技术网

Java 如何从Struts 2中的select标记映射多个值?

Java 如何从Struts 2中的select标记映射多个值?,java,jquery,jquery-ui,jsp,struts2,Java,Jquery,Jquery Ui,Jsp,Struts2,我的Struts2 web应用程序中有一个多选组合。我使用ui多部分组件。当我选择并提交值“1”和“2”,然后在我的操作类中检查它时,只设置了最后选择的值。如何设置所有选定值 JSP文件: <%@ taglib prefix="s" uri="/struts-tags"%> <link rel="stylesheet" href="<s:url value="/css/jquery.multiselect.css"/>" type="text/css" /&

我的Struts2 web应用程序中有一个多选组合。我使用ui多部分组件。当我选择并提交值
“1”
“2”
,然后在我的操作类中检查它时,只设置了最后选择的值。如何设置所有选定值

JSP文件:

<%@ taglib prefix="s" uri="/struts-tags"%>
<link rel="stylesheet"
    href="<s:url value="/css/jquery.multiselect.css"/>" type="text/css" />
<link rel="stylesheet"
    href="<s:url value="/css/jquery.multiselect.filter.css"/>"
    type="text/css" />
<link rel="stylesheet"
    href="<s:url value="/css/themes/base/jquery.ui.theme.css"/>"
    type="text/css" />
<script type="text/javascript"
    src="<s:url value="/js/jquery-1.9.1.min.js" />"></script>
<script type="text/javascript"
    src="<s:url value="/js/jquery-ui.min.js" />"></script>
<script type="text/javascript"
    src="<s:url value="/js/jquery.multiselect.min.js" />"></script>
<script type="text/javascript"
    src="<s:url value="/js/jquery.multiselect.filter.js" />"></script>


<script language="javascript">
    $(function() {

        $("select").multiselect({
            multiple : true,
            selectedList : 4,
            noneSelectedText : 'Tous',
            height : 180
        });

        $("select").multiselect().multiselectfilter();
    });
</script>
<s:form id="idForm" action="testOMB.do" name="myForm">

    <div class="contentTable">
        <div class="tbl">

            <table width="100%">
                <tr>
                    <td><s:select id="idCombo1" multiple="multiple"
                            list="listItems" name="listIdSelected"
                            value="listIdSelected" listKey="id" listValue="label"
                            emptyOption="true" /></td>
                </tr>
            </table>
        </div>
    </div>

    <div class="bloc_action">
        <s:submit cssClass="btn_action" value="TEST OMB" />
    </div>
</s:form>
package com.omb.controller.report;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.omb.ui.item.Item;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.Preparable;

@SuppressWarnings("serial")
public class MyAction extends ActionSupport implements Preparable {

    Log log = LogFactory.getLog(MyAction.class);

    private List<Item> listItems = new ArrayList<String>();
    private List<String> listIdSelected = new ArrayList<String>();

    public void prepare() throws Exception {
        listItems.add(new Item("1", "Item 1"));
        listItems.add(new Item("2", "Item 2"));
        listItems.add(new Item("3", "Item 3"));
        listItems.add(new Item("4", "Item 4"));
    }

    @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, readOnly = true)
    public String testOMB() throws Exception {
        log.debug("listIdSelected = " + listIdSelected.size());
        return SUCCES;
    }

    public List<Item> getListItems() {
        return this.listItems;
    }

    public void setListItems(List<Item> listItems) {
        this.listItems = listItems;
    }

    public List<String> getListIdSelected() {
        return this.listIdSelected;
    }

    public void setListIdSelected(List<String> listIdSelected) {
        this.listIdSelected = listIdSelected;
    }


}
?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
    <constant name="struts.devMode" value="false" />
    <constant name="struts.action.extension" value="do" />
    <constant name="struts.custom.i18n.resources"
        value="com.omb.i18n.StrutsResourceBundle" />
    <constant name="struts.objectFactory" value="spring" />
    <constant name="struts.objectFactory.spring.autoWire" value="name" />
    <constant name="struts.i18n.encoding" value="ISO-8859-1" />
    <constant name="struts.i18n.reload" value="false" />
    <constant name="struts.configuration.xml.reload" value="false" />
    <constant name="struts.locale" value="fr" />
    <constant name="struts.multipart.maxSize" value="100000000000" />
    <constant name="struts.enable.SlashesInActionNames" value="true" />
    <constant name="struts.mapper.alwaysSelectFullNamespace" value="false"/>

    <constant name="struts.codebehind.classSuffix" value="Controller"/>
    <constant name="struts.codebehind.action.checkImplementsAction" value="false"/>
    <constant name="struts.codebehind.action.checkAnnotation" value="false"/>
    <constant name="struts.codebehind.action.defaultMethodName" value="index"/>
    <constant name="struts.configuration.classpath.defaultParentPackage" value="rest-default" />

    <package name="default" extends="tiles-default" namespace="/">

        <interceptors>

            <interceptor name="userAware"
                class="com.omb.interceptor.UserAwareInterceptor" />

            <interceptor name="params-filter"
                class="com.opensymphony.xwork2.interceptor.ParameterFilterInterceptor" />

            <interceptor-stack name="defaultStack">
                <interceptor-ref name="exception" />
                <interceptor-ref name="alias" />
                <interceptor-ref name="servletConfig" />
                <interceptor-ref name="i18n" />
                <interceptor-ref name="chain" />
                <interceptor-ref name="modelDriven" />
                <interceptor-ref name="fileUpload">
                    <param name="maximumSize">11204928</param>
                </interceptor-ref>
                <interceptor-ref name="staticParams" />
                <interceptor-ref name="conversionError" />
                <interceptor-ref name="params" />
                <interceptor-ref name="prepare" />
                <interceptor-ref name="validation" />
                <interceptor-ref name="workflow" />
                <interceptor-ref name="userAware" />

            </interceptor-stack>

        </interceptors>

        <default-interceptor-ref name="defaultStack" />

        <global-results>
            <result name="technicalError" type="chain">
                errorAction
            </result>
            <result name="sessionInvalidError" type="tiles">
                sessionInvalid
            </result>
            <result name="blank" type="tiles">blank</result>
        </global-results>

        <global-exception-mappings>
            <exception-mapping exception="java.lang.Exception"
                result="technicalError" />
            <exception-mapping
                exception="com.omb.service.exception.UserSessionInvalidException"
                result="sessionInvalidError" />

        </global-exception-mappings>

        <action name="errorAction"
            class="com.omb.controller.ErrorAction">
            <result name="success" type="tiles">errorTile</result>
        </action>

        <action name="*Cache"
            class="com.omb.controller.CacheAction" method="{1}">
            <result name="success" type="tiles">resultCache</result>
            <result name="input" type="tiles">inputCache</result>
        </action>

        <action name="*Login"
            class="com.omb.controller.LoginAction" method="{1}">
            <result name="success" type="tiles">login</result>
            <result name="password" type="tiles">changePassword</result>
        </action>

        <action name="*Welcome"
            class="com.omb.controller.WelcomeAction" method="{1}">
            <result name="success" type="tiles">welcome</result>
            <result name="report" type="redirectAction">
                <param name="namespace">/report</param>
                <param name="actionName">perimetersReport</param>
            </result>
        </action>

    </package>

    <package name="report" extends="default" namespace="/report">
        <action name="*Action"
            class="com.omb.controller.report.MyAction"
            method="{1}">
            <result name="succes" type="tiles">succesTile</result>
        </action>
    </package>
</struts>
试着改变

private List<String> listIdSelected = new ArrayList<String>();
private List listIdSelected=new ArrayList();

private List listIdSelected=new ArrayList();
因为你的能手和二传手都是这样的

要选择“获取所有值”,我应该做什么


您应该做一个
选择
标记以接受多个选项。这是通过struts中的
multiple=“true”
选择标签来完成的。那么您的拦截器堆栈不完整,因为缺少。您应该在
文件上载
拦截器引用之后将
添加到拦截器堆栈中

好的,我明白了…我更新了我的示例代码。在我的代码命名过程中,我在getter/setter中出错了……那么它应该可以工作了;尝试从
私有列表listIdSelected=new ArrayList()中删除初始化,若在拦截器堆栈后它不起作用,那个么一定是出了什么问题……我更改了属性的声明。我删除了带有空列表的初始化,但不是wor。我在帖子中添加了struts.xml。
private List<Integer> listIdSelected = new ArrayList<Integer>();