gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 09:13:25 24 4
gpt4 key购买 nike

我的 Struts2 网络应用程序中有一个多选组合。我使用 ui-multisection 组件。当我选择并提交值 "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>

Action 类:

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;
}


}

struts.xml 文件:

?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>

最佳答案

what should I do for get all value selected ?

你应该做一个select标签接受多个选项。这是通过 multiple="true" 完成的在支柱中 select标签。那么您的拦截器堆栈不完整,因为 multiselect interceptor不见了。您应该添加 <interceptor-ref name="multiselect"/> fileUpload interceptor 之后到您的拦截器堆栈引用。

关于java - 如何从 Struts 2 中的 select 标记映射多个值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21048136/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com