سؤال

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!

هل كانت مفيدة؟

المحلول

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top