双选的Struts2 jQuery插件问题

时间:2014-08-19 12:44:17

标签: struts2 struts2-jquery-plugin

我有一点(我希望)问题试图使用Struts2 jQuery插件中的Doubleselect元素,在搜索互联网后我发现没有任何关于它的信息所以我来这里是为了得到你的帮助。
我有一个带有两个struts2的jsp,jQuery插件选择根据从第一个选择的项目加载第二个选择( Modelo )( Fabricante )。加载jsp时,加载第一个选择;但是当我从第一个选择中选择一个项目时,该选定项目的值不会到达该操作(值为空),因此无法从数据库中查询第二个选择的值;因此,永远不会加载第二个选择。

我已经关注了struts2-jquery-showcase中的sample

有关我的应用的一些信息:

  • struts2 2.3
  • tiles
  • Spring 3.1(我有struts2-spring集成)

遵循某些文件的代码段

磁贴布局的JSP代码

<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
<tiles:importAttribute/>

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>

        <script type="text/javascript">
            var GB_ROOT_DIR = "res/greybox/";
        </script>
        <script type="text/javascript" src="res/greybox/AJS.js"></script>
        <script type="text/javascript" src="res/greybox/AJS_fx.js"></script>
        <script type="text/javascript" src="res/greybox/gb_scripts.js"></script>
<...>

        <sj:head jqueryui="true" />

    </head>
    <body leftmargin="0" topmargin="0" marginheight="0" marginwidth="0">

             <tiles:insertAttribute name="header" />
             <tiles:insertAttribute name="menu" />

<...>
             <tiles:insertAttribute name="content" />

    </body>
</html>


JSP代码

<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="display" uri="http://displaytag.sf.net"%>
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
<...>
<s:form action="nuevaReparacion2" validate="true" onsubmit="return checkSubmit();" name="formulario" method="post">
<...>
        <table cellpadding="0" cellspacing="0" width="900">
          <tr>
            <td height="2"> Fabricante:
            <s:url id="remoteurl" action="nuevaReparacionCargaModelo"/>
            <sj:select
                    href="%{remoteurl}"
                    id="selectFab"
                    onChangeTopics="reloadModelos"
                    name="idFabricante"
                    list="listFabricantes"
                    listKey="id"
                    listValue="nombre"
                    emptyOption="false"
                    headerKey="-1"
                    headerValue="Seleccione un fabricante"
                    indicator="indicator"
                />
                <img id="indicator"
                    src="res/images/ajax-loader.gif"
                    alt="cargando..."
                    style="display:none"
                />

            </td>
            <td height="2">Modelo:
            <sj:select
                    href="%{remoteurl}"
                    id="selectMod"
                    formIds="formulario"
                    reloadTopics="reloadModelos"
                    name="idModelo"
                    list="listModelos"
                    listKey="id"
                    listValue="nombre"
                    emptyOption="false"
                    headerKey="-1"
                    headerValue="Seleccione un modelo"
                    indicator="indicator2"
                />
                <img id="indicator2"
                    src="res/images/ajax-loader.gif"
                    alt="cargando..."
                    style="display:none"
                />
            </td>

          </tr>
        </table>
<...>



的web.xml

<...>
 <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/classes/spring-context.xml</param-value>
  </context-param>

  <context-param>
    <param-name>org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG</param-name>
    <param-value>/WEB-INF/classes/tiles.xml</param-value>
  </context-param>

  <filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
  </filter>

   <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/struts/*</url-pattern>
    </filter-mapping>

    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

  <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>*.action</url-pattern>
  </filter-mapping>


  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

  <listener>
    <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
  </listener>

  <listener>
    <listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
  </listener>
<...>


struts.xml中

<...>
      <interceptor-stack name="authenticationMinimalStack">
        <interceptor-ref name="exception" />
        <interceptor-ref name="servletConfig" />
        <interceptor-ref name="securityInterceptor" />
        <interceptor-ref name="prepare" />
        <interceptor-ref name="checkbox" />
        <interceptor-ref name="multiselect" />
        <interceptor-ref name="chain" />
        <interceptor-ref name="fileUpload">
            <!--  <param name="maximumSize">50000000</param> -->
            <param name="maximumSize">80000000</param>
        </interceptor-ref>
        <interceptor-ref name="modelDriven"/>
        <interceptor-ref name="staticParams" />
        <interceptor-ref name="params"/>
        <interceptor-ref name="workflow" />
      </interceptor-stack>
<...>
<...>
   <action name="nuevaReparacionCargaModelo" method="cargaModeloFabricante" class="nuevaReparacionAction">
      <interceptor-ref name="authenticationMinimalStack" />
      <result name="pajax" type="json"></result>
    </action>
<...>


动作类代码

public class NuevaReparacionAction extends AbstractAction<NuevaReparacionForm> {
<...>
public String init() throws Exception {

        if (model.getListFabricantes() == null) {
            List<Fabricante> listFabricantes = referenceDataService.getAllFabricantes();
            model.setListFabricantes(listFabricantes);

        }
<...>
}
<...>
    public String cargaModeloFabricante()  throws Exception {

        if(StringUtils.isNotEmpty(idFabricante)){
            List<Modelo> listModelos = referenceDataService.getAllModelosPorFab(idFabricante);
            model.setListModelos(listModelos);
        }

        String res = "pajax";
        return res;
    }
<...>
}


表单类代码

public class NuevaReparacionForm extends AbstractActionForm {
<...>
private List<Fabricante> listFabricantes;
    private String idFabricante;
    private List<Modelo> listModelos;
    private String idModelo;
<...>
public List<Fabricante> getListFabricantes() {
        return listFabricantes;
    }

    public void setListFabricantes(List<Fabricante> listFabricantes) {
        this.listFabricantes = listFabricantes;
    }

    public String getIdFabricante() {
        return idFabricante;
    }

    public void setIdFabricante(String idFabricante) {
        this.idFabricante = idFabricante;
    }
    public List<Modelo> getListModelos() {
        return listModelos;
    }

    public void setListModelos(List<Modelo> listModelos) {
        this.listModelos = listModelos;
    }

    public String getIdModelo() {
        return idModelo;
    }

    public void setIdModelo(String idModelo) {
        this.idModelo = idModelo;
    }

<...>


Fabricante bean

public class Fabricante extends AbstractObject<Long> {

    private static final long serialVersionUID = -3767216824782509270L;

    private boolean indRepara;


    public boolean isIndRepara() {
        return indRepara;
    }


    public void setIndRepara(boolean indRepara) {
        this.indRepara = indRepara;
    }




    @Override
    public boolean equals(Object obj) {
        if (obj == this) {
            return true;
        }

        if (obj == null) {
            return false;
        }

        if (!obj.getClass().equals(getClass())) {
            return false;
        }

        Fabricante castedObj = (Fabricante) obj;
        return ObjectUtils.equals(getId(), castedObj.getId());
    }


    @Override
    public String toString() {
        return new ToStringBuilder(this)
                   .append("id", getId())
                   .append("nombre", getNombre())
                   .toString();
    }
}


Modelo bean

public class Modelo extends AbstractObject<Long> {

    private static final long serialVersionUID = -5167217040308921281L;

    private Fabricante fabricante;


    public Fabricante getFabricante() {
        return fabricante;
    }

    public void setFabricante(Fabricante fabricante) {
        this.fabricante = fabricante;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == this) {
            return true;
        }

        if (obj == null) {
            return false;
        }

        if (!obj.getClass().equals(getClass())) {
            return false;
        }

        Modelo castedObj = (Modelo) obj;
        return ObjectUtils.equals(getId(), castedObj.getId());
    }


    @Override
    public String toString() {
        return new ToStringBuilder(this)
                   .append("id", getId())
                   .append("nombre", getNombre())
                   .toString();
    }
}


bean的超类

public class AbstractObject<T>  {

    /**
     *
     */
    private static final long serialVersionUID = 7717102673045778131L;
    /**
     * The object id
     */
    private T id;
    private String nombre;


    /**
     * Setter for attribute "id"
     * @param id the object id
     *
    public void setId(T id) {
        this.id = id;
    }

    /**
     * Getter for attribute "id"
     * @return the object id
     *
    public T getId() {
        return id;
    }

    public String getNombre() {
        return nombre;
    }

    public void setNombre(String nombre) {
        this.nombre = nombre;
    }

}


提前谢谢。

0 个答案:

没有答案