Question

Has anyone tried implementing Struts2-jQuery example?

I am able to do setup for example given at below link but no values are populated in the page

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

and no error is show in console not able to guess wat is the problem?

SELECTLIST.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>

ACTION CLASS:

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;
  }
}
Was it helpful?

Solution

You are missing the Head Tag

The "head" tag renders required JavaScript code to configure jQuery and is required in order to use any of the tags included in the jQuery plugin.

  <head>
    <sj:head/>
  </head>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top