0

I'm trying to learn how to use a remote division, so I've been checking the showcase of struts2-jquery-plugin and I didnt understand much how things are working. Here what they have in the download :

struts.xml :

<struts>
    // some other instructions and constants
    <include file="showcase.xml" />
</struts>

showcase.xml : ( Should it be empty?? )

<struts>
    <package name="showcase" extends="struts-default,json-default" namespace="/">
    </package>
</struts>

RemoteDiv.java :

package com.jgeppert.struts2.jquery.showcase;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;

import com.opensymphony.xwork2.ActionSupport;

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

  private static final long serialVersionUID = -6793556760537290969L;

  @Action(value = "/remote-div", results = {
    @Result(location = "remote-div.jsp", name = "success")
  })
  public String execute() throws Exception
  {
    return SUCCESS;
  }
}

So my questions are :

1) Is the annotation @Action obligatory or is it replacing the actions which we should declare in struts.xml?

2) What is /remote-div about? The name of the action which we should mention in struts.xml??

3) In my case I'm using tiles, should I do location = "mypage.tiles" , I mean the name given to the page in tiles.xml ?

4) what about @ParentPackage(value = "showcase"), should we mention the name of the parent package only without the entire path??

5) In which case I would need json plugin?

I do appologise in advance if my questions are stupid. But understand me guys, I'm still a beginner. A big Thanks in advance!

Dave Newton
  • 158,873
  • 26
  • 254
  • 302

1 Answers1

0
  1. It's the action mapping annotation. Actions have to be mapped somehow by annotation, by XML configuration, by convention (i.e., convention or REST plugins).
  2. It's the name of the action. Don't define actions via annotations and XML–pick one.
  3. Yes, and you'll need to define the result type, or use tiles as the default result type.
  4. That's the name of the S2 package, i.e., the <package> in the config file.
  5. In the case you want a JSON result.

Regarding your question "should the package declaration be empty"–only if you want it to be empty. It defines a package, and various things relating to a package (like interceptor stacks, result types, results, the first part of the URL, etc.)

Dave Newton
  • 158,873
  • 26
  • 254
  • 302
  • So in their case they used annotation instead of XML, but I can't see the name of the function.. is it because they have execute only? What should we do in case of other fuctions defined in the Action class? Thank you again –  Aug 01 '12 at 20:26
  • @user1459961 What do you mean, "can't see the name of the function"? – Dave Newton Aug 01 '12 at 20:27
  • normally in xml, for defining the actions we mention the value of the attribute "method" except in case of "execute", so it becomes additional to write method="execute" or not. So what about by the annotation? Also, is it necessary for my case ( manipulating a remote div) to use a JSON result? –  Aug 01 '12 at 20:36
  • 1
    @user1459961 ... The annotated method is the method. Have you even looked at the showcase and its examples? What's a remote div? Do you mean doing what the home page of the showcase app you posted a link to does? I'd *strongly* urge you to learn more about S2 before proceeding much further, it will save you all sorts of time. – Dave Newton Aug 01 '12 at 20:37
  • Ouch! You are totally right! Thank you! The annotation is completely clear now :) . You are right about giving time for learning S2, it's only that we have got an urgent need of S2, and time not enough. About remote div, in our case we need to click on the link and load data from database into an arraylist then iterate it in that div. –  Aug 01 '12 at 20:53
  • @user1459961 The remote links in the showcase app are what you probably want to look at then, although it might be just as easy to just look at the showcase app's client-side source snippets--likely enough to get you going. – Dave Newton Aug 01 '12 at 20:58
  • Okay, I will check about the remote links. Thank you so much sir. Dave Newton for your awsome answers :) –  Aug 01 '12 at 21:20