1

有没有人尝试过实现 Struts2-jQuery 示例?

例如,我可以在下面的链接中进行设置,但页面中没有填充任何值

http://struts.jgeppert.com/struts2-jquery-showcase/index.action

并且控制台中没有显示错误无法猜测问题是什么?

选择列表.jsp

    <%@ taglib prefix="sx" uri="/struts-dojo-tags" %> 
<%@ taglib prefix="sj" uri="/struts-jquery-tags" %> 
<%@ taglib prefix="s" uri="/struts-tags"%>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Home</title>
</head>
<body>
Reload example with two select boxes.
     <s:form id="formSelectReload" action="echo" theme="simple" cssClass="yform">
        <fieldset>
            <legend>AJAX Form</legend>
            <div class="type-text">
                <label for="language">Language: </label>
                <s:url id="remoteurl" action="jsonsample"/> 
                <sj:select 
                    href="%{remoteurl}" 
                    id="language" 
                    onChangeTopics="reloadsecondlist" 
                    name="language" 
                    list="languageObjList" 
                    listKey="myKey" 
                    listValue="myValue" 
                    emptyOption="true" 
                    headerKey="-1" 
                    headerValue="Please Select a Language"
                />
            </div>
            <div class="type-text">
                <label for="echo">Framework: </label>
                <s:url id="remoteurl" action="jsonsample"/> 
                <sj:select 
                    href="%{remoteurl}" 
                    id="selectWithReloadTopic" 
                    formIds="formSelectReload" 
                    reloadTopics="reloadsecondlist" 
                    name="echo" 
                    list="reloadList" 
                    emptyOption="true" 
                    headerKey="-1" 
                    headerValue="Please Select a Framework"
                />
            </div>
            <div class="type-button">
                <sj:submit 
                    id="submitFormSelectReload"
                    targets="result" 
                    value="AJAX Submit" 
                    indicator="indicator" 
                    button="true"
                    />
                    <img id="indicator" 
                        src="images/indicator.gif" 
                        alt="Loading..." 
                        style="display:none"
                    />
            </div>
        </fieldset>
    </s:form>
    <br/>
    Reload example with one select box and an buttonset.
     <s:form id="formSelectCheckBox" action="echo" theme="xhtml">
        <s:url id="remoteurl" action="jsonsample"/> 
        <sj:select 
            href="%{remoteurl}" 
            id="languageSelect" 
            onChangeTopics="reloadcheckboxes" 
            name="language" 
            list="languageObjList" 
            listKey="myKey" 
            listValue="myValue" 
            emptyOption="true" 
            headerKey="-1" 
            headerValue="Please Select a Language"
            label="Language"
            required="true"
        />
        <s:url id="remoteurl" action="jsonsample"/> 
        <sj:checkboxlist 
            href="%{remoteurl}" 
            id="frameworkCheckboxes" 
            formIds="formSelectCheckBox" 
            reloadTopics="reloadcheckboxes" 
            name="echo" 
            list="reloadList" 
            label="Framework"
            required="true"
            onChangeTopics="submitCheckboxForm"
        />
        <sj:submit 
            id="submitFormSelectCheckBox"
            listenTopics="submitCheckboxForm"
            targets="result" 
            value="AJAX Submit" 
            indicator="indicator2" 
            cssStyle="display : none;"
        />
    </s:form>
    <img id="indicator2" 
        src="images/indicator.gif" 
        alt="Loading..." 
        style="display:none"
    />

    <strong>Result Div :</strong>
</body>
</html>

动作类:

package showcase;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.convention.annotation.*;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Actions;
import org.apache.struts2.convention.annotation.ParentPackage;

import com.opensymphony.xwork2.ActionSupport;

@ParentPackage(value = "showcase")
public class JsonSample extends ActionSupport {

  private static final long   serialVersionUID = -2223948287805083119L;
  private static final Log    log              = LogFactory.getLog(JsonSample.class);
  private List<String>        languageList;
  private List<ListValue>     languageObjList;
  private Map<String, String> languageMap;
  private List<String>        reloadList;
  private String              language;

  @Actions( {
    @Action(value = "/jsonsample", results = {
      @Result(name = "success", type = "json" , location="/web/SelectList.jsp")
    })
  })
  public String execute()
  {

    log.info("build json lists language : " + language);

    languageList = new ArrayList<String>();
    languageObjList = new ArrayList<ListValue>();
    languageMap = new HashMap<String, String>();

    languageList.add("Java");
    languageList.add("PHP");
    languageList.add("C#");

    languageMap.put("J", "Java");
    languageMap.put("P", "PHP");
    languageMap.put("C", "C#");

    languageObjList.add(new ListValue("J", "Java"));
    languageObjList.add(new ListValue("P", "PHP"));
    languageObjList.add(new ListValue("C", "C#"));

    reloadList = new ArrayList<String>();
    if (language != null && language.equalsIgnoreCase("J"))
    {
      reloadList.add("Struts2");
      reloadList.add("MyFaces");
      reloadList.add("Tapestry");
    }
    else if (language != null && language.equalsIgnoreCase("P"))
    {
      reloadList.add("CakePHP");
      reloadList.add("Symfony");
      reloadList.add("Zend");
    }
    else if (language != null && language.equalsIgnoreCase("C"))
    {
      reloadList.add("NStruts");
      reloadList.add("ProMesh.NET");
      reloadList.add("Websharp");
    }

    return SUCCESS;
  }

  public String getJSON()
  {
    return execute();
  }

  public List<String> getLanguageList()
  {
    return languageList;
  }

  public Map<String, String> getLanguageMap()
  {
    return languageMap;
  }

  public List<ListValue> getLanguageObjList()
  {
    return languageObjList;
  }

  public List<String> getReloadList()
  {
    return reloadList;
  }

  public void setLanguage(String language)
  {
    this.language = language;
  }
}
4

1 回答 1

2

您缺少头部标签

“head”标签呈现配置 jQuery 所需的 JavaScript 代码,并且是使用 jQuery 插件中包含的任何标签所必需的

  <head>
    <sj:head/>
  </head>
于 2013-07-04T10:16:38.960 回答