S2Tapestry allows Tapestry to be used more easily with S2. Service component is automatically set to a page class so page class only has to call the proper service component. Thus, presentation layer and service layer are separate.
JDK1.4 is required. Furthermore, the sample requires Tomcat, Tomcat Plugin, and Spindle. They must be setup before installing the sample. To setup S2Tapestry as a Eclipse project, extract S2TapestryVx.x.x.jar archive file to some directory. Open a Eclipse project and import s2tapestry directory that was created in the extracted file directory. If Eclipse dialog box prompts if you want to overwrite .classpath, answer "yes" to all. Samples are in a different archive file from S2Tapestry. Download S2TapestryExamleVx.x.x.jar and extract the files to some directory. Open Eclipse and create a Java Project named s2tapestry-example. Note to create a Java Project and NOT a Tomcat Project. Import all s2tapestry-example diretory that was created in the extracted file directory. If Eclipse dialog box prompts if you want to overwrite .classpath, answer "yes" to all. Right click on s2tapestry-example project and select the ->Tomcat property. Check [Tomcat Project] and set application URI to /s2tapestry-example. From the Eclipse menu, select [Tomcat]-[Restart Tomcat] to restart Tomcat. To view the addition sample, open a web browser to open http://localhost:8080/s2tapestry-example/app.
Register necessary components in component definition. Page component is managed by Tapestry so it does not have to be registered. Definition file must be registered in an app.dicon.
To receive service component, property specification is defined in page specification. S2 component may be referenced from Tapestry by global.component name or by global.global.namespace.component when namespace is specified.
Property to receive component is defined in page class. Presentation layer send requests to server layer so presentation layer only need to contain how page is to be shown.
Home.java
package examples.tapestry;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.html.BasePage;
public class Home extends BasePage {
private Integer arg1_;
private Integer arg2_;
private AddService addService_;
public Integer getArg1() {
return arg1_;
}
public void setArg1(Integer arg1) {
arg1_ = arg1;
}
public Integer getArg2() {
return arg1_;
}
public void setArg2(Integer arg2) {
arg2_ = arg2;
}
public AddService getAddService() {
return addService_;
}
public void setAddService(AddService addService) {
addService_ = addService;
}
public void calculate(IRequestCycle cycle) {
int result = addService_.add(arg1_.intValue(), arg2_.intValue());
AddResult next = (AddResult) cycle.getPage("AddResult");
next.setResult(new Integer(result));
cycle.activate(next);
}
}