mirror of
https://github.com/apache/struts.git
synced 2026-08-07 15:46:57 +00:00
WW-3900 Refactor the Struts2 Showcase
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1400220 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
+21
-41
@@ -164,10 +164,11 @@
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>1.2.16</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-logging</groupId>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.myfaces.core</groupId>
|
||||
@@ -217,47 +218,35 @@
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.mortbay.jetty</groupId>
|
||||
<artifactId>maven-jetty-plugin</artifactId>
|
||||
<version>6.0.1</version>
|
||||
<artifactId>jetty-maven-plugin</artifactId>
|
||||
<version>8.0.0.M2</version>
|
||||
<configuration>
|
||||
<systemProperties>
|
||||
<systemProperty>
|
||||
<name>log4j.configuration</name>
|
||||
<value>file:${basedir}/src/main/resources/log4j.properties</value>
|
||||
</systemProperty>
|
||||
<systemProperty>
|
||||
<name>slf4j</name>
|
||||
<value>false</value>
|
||||
</systemProperty>
|
||||
</systemProperties>
|
||||
<scanIntervalSeconds>10</scanIntervalSeconds>
|
||||
<webAppSourceDirectory>${basedir}/src/main/webapp/</webAppSourceDirectory>
|
||||
<webAppConfig>
|
||||
<contextPath>/struts2-showcase</contextPath>
|
||||
<descriptor>${basedir}/src/main/webapp/WEB-INF/web.xml</descriptor>
|
||||
</webAppConfig>
|
||||
</configuration>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.myfaces.core</groupId>
|
||||
<artifactId>myfaces-impl</artifactId>
|
||||
<version>1.1.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.myfaces.core</groupId>
|
||||
<artifactId>myfaces-api</artifactId>
|
||||
<version>1.1.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>1.2.9</version>
|
||||
<version>1.2.16</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
<!--
|
||||
<plugin>
|
||||
<groupId>org.twdata.maven</groupId>
|
||||
<artifactId>maven-itblast-plugin</artifactId>
|
||||
<version>0.3</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>integration-test</phase>
|
||||
<goals>
|
||||
<goal>execute</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<containers>tomcat5x</containers>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
-->
|
||||
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
@@ -283,13 +272,4 @@
|
||||
</resources>
|
||||
|
||||
</build>
|
||||
<!--
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>twdata-m2-repository</id>
|
||||
<name>twdata.org Maven Repository</name>
|
||||
<url>http://twdata-m2-repository.googlecode.com/svn/</url>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
-->
|
||||
</project>
|
||||
|
||||
@@ -20,87 +20,84 @@
|
||||
*/
|
||||
package org.apache.struts2.showcase;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
|
||||
/**
|
||||
* <code>DateAction</code>
|
||||
*
|
||||
*/
|
||||
public class DateAction extends ActionSupport {
|
||||
|
||||
private static DateFormat DF = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
|
||||
private static DateFormat DF = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
|
||||
|
||||
private Date now;
|
||||
private Date past;
|
||||
private Date future;
|
||||
private Date after;
|
||||
private Date before;
|
||||
private Date now;
|
||||
private Date past;
|
||||
private Date future;
|
||||
private Date after;
|
||||
private Date before;
|
||||
|
||||
|
||||
public String getDate() {
|
||||
return DF.format(new Date());
|
||||
}
|
||||
public String getDate() {
|
||||
return DF.format(new Date());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Returns the future.
|
||||
*/
|
||||
public Date getFuture() {
|
||||
return future;
|
||||
}
|
||||
/**
|
||||
* @return Returns the future.
|
||||
*/
|
||||
public Date getFuture() {
|
||||
return future;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the now.
|
||||
*/
|
||||
public Date getNow() {
|
||||
return now;
|
||||
}
|
||||
/**
|
||||
* @return Returns the now.
|
||||
*/
|
||||
public Date getNow() {
|
||||
return now;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the past.
|
||||
*/
|
||||
public Date getPast() {
|
||||
return past;
|
||||
}
|
||||
/**
|
||||
* @return Returns the past.
|
||||
*/
|
||||
public Date getPast() {
|
||||
return past;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Returns the before date.
|
||||
*/
|
||||
public Date getBefore() {
|
||||
return before;
|
||||
}
|
||||
/**
|
||||
* @return Returns the before date.
|
||||
*/
|
||||
public Date getBefore() {
|
||||
return before;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Returns the after date.
|
||||
*/
|
||||
public Date getAfter() {
|
||||
return after;
|
||||
}
|
||||
/**
|
||||
* @return Returns the after date.
|
||||
*/
|
||||
public Date getAfter() {
|
||||
return after;
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public String browse() throws Exception {
|
||||
Calendar cal = GregorianCalendar.getInstance();
|
||||
now = cal.getTime();
|
||||
cal.roll(Calendar.DATE, -1);
|
||||
cal.roll(Calendar.HOUR, -3);
|
||||
past = cal.getTime();
|
||||
cal.roll(Calendar.DATE, 2);
|
||||
future = cal.getTime();
|
||||
/**
|
||||
*/
|
||||
public String browse() throws Exception {
|
||||
Calendar cal = GregorianCalendar.getInstance();
|
||||
now = cal.getTime();
|
||||
cal.roll(Calendar.DATE, -1);
|
||||
cal.roll(Calendar.HOUR, -3);
|
||||
past = cal.getTime();
|
||||
cal.roll(Calendar.DATE, 2);
|
||||
future = cal.getTime();
|
||||
|
||||
cal.roll(Calendar.YEAR, -1);
|
||||
before = cal.getTime();
|
||||
cal.roll(Calendar.YEAR, -1);
|
||||
before = cal.getTime();
|
||||
|
||||
cal.roll(Calendar.YEAR, 2);
|
||||
after = cal.getTime();
|
||||
return SUCCESS;
|
||||
}
|
||||
cal.roll(Calendar.YEAR, 2);
|
||||
after = cal.getTime();
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+17
-17
@@ -20,35 +20,35 @@
|
||||
*/
|
||||
package org.apache.struts2.showcase;
|
||||
|
||||
import org.apache.struts2.showcase.ajax.tree.Category;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
import org.apache.struts2.showcase.ajax.tree.Category;
|
||||
|
||||
//START SNIPPET: treeExampleDynamicJavaSelected
|
||||
|
||||
public class DynamicTreeSelectAction extends ActionSupport {
|
||||
|
||||
private long nodeId;
|
||||
private Category currentCategory;
|
||||
private long nodeId;
|
||||
private Category currentCategory;
|
||||
|
||||
|
||||
public void setNodeId(long nodeId) {
|
||||
this.nodeId = nodeId;
|
||||
}
|
||||
public long getNodeId() {
|
||||
return nodeId;
|
||||
}
|
||||
public void setNodeId(long nodeId) {
|
||||
this.nodeId = nodeId;
|
||||
}
|
||||
|
||||
public long getNodeId() {
|
||||
return nodeId;
|
||||
}
|
||||
|
||||
|
||||
public String execute() throws Exception {
|
||||
currentCategory = Category.getById(nodeId);
|
||||
return SUCCESS;
|
||||
}
|
||||
public String execute() throws Exception {
|
||||
currentCategory = Category.getById(nodeId);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
public String getNodeName() {
|
||||
return currentCategory != null ? currentCategory.getName() : "Node not found";
|
||||
}
|
||||
public String getNodeName() {
|
||||
return currentCategory != null ? currentCategory.getName() : "Node not found";
|
||||
}
|
||||
}
|
||||
|
||||
//START SNIPPET: treeExampleDynamicJavaSelected
|
||||
|
||||
+203
-209
@@ -20,267 +20,261 @@
|
||||
*/
|
||||
package org.apache.struts2.showcase;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class LotsOfOptiontransferselectAction extends ActionSupport {
|
||||
|
||||
private List _favouriteCartoonCharactersKeys;
|
||||
private List _notFavouriteCartoonCharactersKeys;
|
||||
private List _favouriteCartoonCharactersKeys;
|
||||
private List _notFavouriteCartoonCharactersKeys;
|
||||
|
||||
private List _favouriteCarsKeys;
|
||||
private List _notFavouriteCarsKeys;
|
||||
private List _favouriteCarsKeys;
|
||||
private List _notFavouriteCarsKeys;
|
||||
|
||||
private List _favouriteMotorcyclesKeys;
|
||||
private List _notFavouriteMotorcyclesKeys;
|
||||
private List _favouriteMotorcyclesKeys;
|
||||
private List _notFavouriteMotorcyclesKeys;
|
||||
|
||||
private List _favouriteCountriesKeys;
|
||||
private List _notFavouriteCountriesKeys;
|
||||
private List _favouriteCountriesKeys;
|
||||
private List _notFavouriteCountriesKeys;
|
||||
|
||||
private List _favouriteSportsKeys;
|
||||
private List _nonFavouriteSportsKeys;
|
||||
private List _favouriteSportsKeys;
|
||||
private List _nonFavouriteSportsKeys;
|
||||
|
||||
private List _favouriteCities;
|
||||
private List _favouriteCities;
|
||||
|
||||
private List _prioritisedFavouriteCartoonCharacters;
|
||||
private List _prioritisedFavouriteCars;
|
||||
private List _prioritisedFavouriteCountries;
|
||||
private List _prioritisedFavouriteCartoonCharacters;
|
||||
private List _prioritisedFavouriteCars;
|
||||
private List _prioritisedFavouriteCountries;
|
||||
|
||||
|
||||
// Cartoon Characters
|
||||
public Map getDefaultFavouriteCartoonCharacters() {
|
||||
Map m = new LinkedHashMap();
|
||||
m.put("heMan", "He-Man");
|
||||
m.put("popeye", "Popeye");
|
||||
m.put("mockeyMouse", "Mickey Mouse");
|
||||
return m;
|
||||
}
|
||||
|
||||
// Cartoon Characters
|
||||
public Map getDefaultFavouriteCartoonCharacters() {
|
||||
Map m = new LinkedHashMap();
|
||||
m.put("heMan", "He-Man");
|
||||
m.put("popeye", "Popeye");
|
||||
m.put("mockeyMouse", "Mickey Mouse");
|
||||
return m;
|
||||
}
|
||||
public Map getDefaultNotFavouriteCartoonCharacters() {
|
||||
Map m = new LinkedHashMap();
|
||||
m.put("donaldDuck", "Donald Duck");
|
||||
m.put("atomicAnt", "Atomic Ant");
|
||||
m.put("pinkPainter", "Pink Painter");
|
||||
return m;
|
||||
}
|
||||
|
||||
public Map getDefaultNotFavouriteCartoonCharacters() {
|
||||
Map m = new LinkedHashMap();
|
||||
m.put("donaldDuck", "Donald Duck");
|
||||
m.put("atomicAnt", "Atomic Ant");
|
||||
m.put("pinkPainter", "Pink Painter");
|
||||
return m;
|
||||
}
|
||||
public List getFavouriteCartoonCharacters() {
|
||||
return _favouriteCartoonCharactersKeys;
|
||||
}
|
||||
|
||||
public List getFavouriteCartoonCharacters() {
|
||||
return _favouriteCartoonCharactersKeys;
|
||||
}
|
||||
public void setFavouriteCartoonCharacters(List favouriteCartoonCharacters) {
|
||||
_favouriteCartoonCharactersKeys = favouriteCartoonCharacters;
|
||||
}
|
||||
|
||||
public void setFavouriteCartoonCharacters(List favouriteCartoonCharacters) {
|
||||
_favouriteCartoonCharactersKeys = favouriteCartoonCharacters;
|
||||
}
|
||||
public List getNotFavouriteCartoonCharacters() {
|
||||
return _notFavouriteCartoonCharactersKeys;
|
||||
}
|
||||
|
||||
public List getNotFavouriteCartoonCharacters() {
|
||||
return _notFavouriteCartoonCharactersKeys;
|
||||
}
|
||||
|
||||
public void setNotFavouriteCartoonCharacters(List notFavouriteCartoonCharacters) {
|
||||
_notFavouriteCartoonCharactersKeys = notFavouriteCartoonCharacters;
|
||||
}
|
||||
public void setNotFavouriteCartoonCharacters(List notFavouriteCartoonCharacters) {
|
||||
_notFavouriteCartoonCharactersKeys = notFavouriteCartoonCharacters;
|
||||
}
|
||||
|
||||
|
||||
// Cars
|
||||
public Map getDefaultFavouriteCars() {
|
||||
Map m = new LinkedHashMap();
|
||||
m.put("alfaRomeo", "Alfa Romeo");
|
||||
m.put("Toyota", "Toyota");
|
||||
m.put("Mitsubitshi", "Mitsubitshi");
|
||||
return m;
|
||||
}
|
||||
|
||||
public Map getDefaultNotFavouriteCars() {
|
||||
Map m = new LinkedHashMap();
|
||||
m.put("ford", "Ford");
|
||||
m.put("landRover", "Land Rover");
|
||||
m.put("mercedes", "Mercedes");
|
||||
return m;
|
||||
}
|
||||
|
||||
public List getFavouriteCars() {
|
||||
return _favouriteCarsKeys;
|
||||
}
|
||||
|
||||
public void setFavouriteCars(List favouriteCars) {
|
||||
_favouriteCarsKeys = favouriteCars;
|
||||
}
|
||||
|
||||
public List getNotFavouriteCars() {
|
||||
return _notFavouriteCarsKeys;
|
||||
}
|
||||
|
||||
public void setNotFavouriteCars(List notFavouriteCars) {
|
||||
_notFavouriteCarsKeys = notFavouriteCars;
|
||||
}
|
||||
|
||||
|
||||
// Motorcycles
|
||||
public Map getDefaultFavouriteMotorcycles() {
|
||||
Map m = new LinkedHashMap();
|
||||
m.put("honda", "Honda");
|
||||
m.put("yamaha", "Yamaha");
|
||||
m.put("Aprillia", "Aprillia");
|
||||
return m;
|
||||
}
|
||||
|
||||
// Cars
|
||||
public Map getDefaultFavouriteCars() {
|
||||
Map m = new LinkedHashMap();
|
||||
m.put("alfaRomeo", "Alfa Romeo");
|
||||
m.put("Toyota", "Toyota");
|
||||
m.put("Mitsubitshi", "Mitsubitshi");
|
||||
return m;
|
||||
}
|
||||
public Map getDefaultNotFavouriteMotorcycles() {
|
||||
Map m = new LinkedHashMap();
|
||||
m.put("cagiva", "Cagiva");
|
||||
m.put("harleyDavidson", "Harley Davidson");
|
||||
m.put("suzuki", "Suzuki");
|
||||
return m;
|
||||
}
|
||||
|
||||
public Map getDefaultNotFavouriteCars() {
|
||||
Map m = new LinkedHashMap();
|
||||
m.put("ford", "Ford");
|
||||
m.put("landRover", "Land Rover");
|
||||
m.put("mercedes", "Mercedes");
|
||||
return m;
|
||||
}
|
||||
public List getFavouriteMotorcycles() {
|
||||
return _favouriteMotorcyclesKeys;
|
||||
}
|
||||
|
||||
public List getFavouriteCars() {
|
||||
return _favouriteCarsKeys;
|
||||
}
|
||||
public void setFavouriteMotorcycles(List favouriteMotorcycles) {
|
||||
_favouriteMotorcyclesKeys = favouriteMotorcycles;
|
||||
}
|
||||
|
||||
public void setFavouriteCars(List favouriteCars) {
|
||||
_favouriteCarsKeys = favouriteCars;
|
||||
}
|
||||
public List getNotFavouriteMotorcycles() {
|
||||
return _notFavouriteMotorcyclesKeys;
|
||||
}
|
||||
|
||||
public List getNotFavouriteCars() {
|
||||
return _notFavouriteCarsKeys;
|
||||
}
|
||||
|
||||
public void setNotFavouriteCars(List notFavouriteCars) {
|
||||
_notFavouriteCarsKeys = notFavouriteCars;
|
||||
}
|
||||
public void setNotFavouriteMotorcycles(List notFavouriteMotorcycles) {
|
||||
_notFavouriteMotorcyclesKeys = notFavouriteMotorcycles;
|
||||
}
|
||||
|
||||
|
||||
// Countries
|
||||
public Map getDefaultFavouriteCountries() {
|
||||
Map m = new LinkedHashMap();
|
||||
m.put("england", "England");
|
||||
m.put("america", "America");
|
||||
m.put("brazil", "Brazil");
|
||||
return m;
|
||||
}
|
||||
|
||||
// Motorcycles
|
||||
public Map getDefaultFavouriteMotorcycles() {
|
||||
Map m = new LinkedHashMap();
|
||||
m.put("honda", "Honda");
|
||||
m.put("yamaha", "Yamaha");
|
||||
m.put("Aprillia", "Aprillia");
|
||||
return m;
|
||||
}
|
||||
public Map getDefaultNotFavouriteCountries() {
|
||||
Map m = new LinkedHashMap();
|
||||
m.put("germany", "Germany");
|
||||
m.put("china", "China");
|
||||
m.put("russia", "Russia");
|
||||
return m;
|
||||
}
|
||||
|
||||
public Map getDefaultNotFavouriteMotorcycles() {
|
||||
Map m = new LinkedHashMap();
|
||||
m.put("cagiva", "Cagiva");
|
||||
m.put("harleyDavidson", "Harley Davidson");
|
||||
m.put("suzuki", "Suzuki");
|
||||
return m;
|
||||
}
|
||||
public List getFavouriteCountries() {
|
||||
return _favouriteCountriesKeys;
|
||||
}
|
||||
|
||||
public List getFavouriteMotorcycles() {
|
||||
return _favouriteMotorcyclesKeys;
|
||||
}
|
||||
public void setFavouriteCountries(List favouriteCountries) {
|
||||
_favouriteCountriesKeys = favouriteCountries;
|
||||
}
|
||||
|
||||
public void setFavouriteMotorcycles(List favouriteMotorcycles) {
|
||||
_favouriteMotorcyclesKeys = favouriteMotorcycles;
|
||||
}
|
||||
public List getNotFavouriteCountries() {
|
||||
return _notFavouriteCountriesKeys;
|
||||
}
|
||||
|
||||
public List getNotFavouriteMotorcycles() {
|
||||
return _notFavouriteMotorcyclesKeys;
|
||||
}
|
||||
public void setNotFavouriteCountries(List notFavouriteCountries) {
|
||||
_notFavouriteCountriesKeys = notFavouriteCountries;
|
||||
}
|
||||
|
||||
public void setNotFavouriteMotorcycles(List notFavouriteMotorcycles) {
|
||||
_notFavouriteMotorcyclesKeys = notFavouriteMotorcycles;
|
||||
}
|
||||
// Sports
|
||||
public Map getDefaultNonFavoriteSports() {
|
||||
Map m = new LinkedHashMap();
|
||||
m.put("basketball", "Basketball");
|
||||
m.put("football", "Football");
|
||||
m.put("baseball", "Baseball");
|
||||
return m;
|
||||
}
|
||||
|
||||
public Map getDefaultFavoriteSports() {
|
||||
return new LinkedHashMap();
|
||||
}
|
||||
|
||||
public List getFavouriteSports() {
|
||||
return _favouriteSportsKeys;
|
||||
}
|
||||
|
||||
public void setFavouriteSports(List favouriteSportsKeys) {
|
||||
this._favouriteSportsKeys = favouriteSportsKeys;
|
||||
}
|
||||
|
||||
public List getNonFavouriteSports() {
|
||||
return _nonFavouriteSportsKeys;
|
||||
}
|
||||
|
||||
public void setNonFavouriteSports(List notFavouriteSportsKeys) {
|
||||
this._nonFavouriteSportsKeys = notFavouriteSportsKeys;
|
||||
}
|
||||
|
||||
|
||||
public List getPrioritisedFavouriteCartoonCharacters() {
|
||||
return _prioritisedFavouriteCartoonCharacters;
|
||||
}
|
||||
|
||||
// Countries
|
||||
public Map getDefaultFavouriteCountries() {
|
||||
Map m = new LinkedHashMap();
|
||||
m.put("england", "England");
|
||||
m.put("america", "America");
|
||||
m.put("brazil", "Brazil");
|
||||
return m;
|
||||
}
|
||||
public void setPrioritisedFavouriteCartoonCharacters(List prioritisedFavouriteCartoonCharacters) {
|
||||
_prioritisedFavouriteCartoonCharacters = prioritisedFavouriteCartoonCharacters;
|
||||
}
|
||||
|
||||
public Map getDefaultNotFavouriteCountries() {
|
||||
Map m = new LinkedHashMap();
|
||||
m.put("germany", "Germany");
|
||||
m.put("china", "China");
|
||||
m.put("russia", "Russia");
|
||||
return m;
|
||||
}
|
||||
public List getPrioritisedFavouriteCars() {
|
||||
return _prioritisedFavouriteCars;
|
||||
}
|
||||
|
||||
public List getFavouriteCountries() {
|
||||
return _favouriteCountriesKeys;
|
||||
}
|
||||
|
||||
public void setFavouriteCountries(List favouriteCountries) {
|
||||
_favouriteCountriesKeys = favouriteCountries;
|
||||
}
|
||||
|
||||
public List getNotFavouriteCountries() {
|
||||
return _notFavouriteCountriesKeys;
|
||||
}
|
||||
|
||||
public void setNotFavouriteCountries(List notFavouriteCountries) {
|
||||
_notFavouriteCountriesKeys = notFavouriteCountries;
|
||||
}
|
||||
|
||||
// Sports
|
||||
public Map getDefaultNonFavoriteSports() {
|
||||
Map m = new LinkedHashMap();
|
||||
m.put("basketball", "Basketball");
|
||||
m.put("football", "Football");
|
||||
m.put("baseball", "Baseball");
|
||||
return m;
|
||||
}
|
||||
|
||||
public Map getDefaultFavoriteSports() {
|
||||
return new LinkedHashMap();
|
||||
}
|
||||
|
||||
public List getFavouriteSports() {
|
||||
return _favouriteSportsKeys;
|
||||
}
|
||||
|
||||
public void setFavouriteSports(List favouriteSportsKeys) {
|
||||
this._favouriteSportsKeys = favouriteSportsKeys;
|
||||
}
|
||||
|
||||
public List getNonFavouriteSports() {
|
||||
return _nonFavouriteSportsKeys;
|
||||
}
|
||||
|
||||
public void setNonFavouriteSports(List notFavouriteSportsKeys) {
|
||||
this._nonFavouriteSportsKeys = notFavouriteSportsKeys;
|
||||
}
|
||||
public void setPrioritisedFavouriteCars(List prioritisedFavouriteCars) {
|
||||
_prioritisedFavouriteCars = prioritisedFavouriteCars;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public List getPrioritisedFavouriteCountries() {
|
||||
return _prioritisedFavouriteCountries;
|
||||
}
|
||||
|
||||
public List getPrioritisedFavouriteCartoonCharacters() {
|
||||
return _prioritisedFavouriteCartoonCharacters;
|
||||
}
|
||||
public void setPrioritisedFavouriteCartoonCharacters(List prioritisedFavouriteCartoonCharacters) {
|
||||
_prioritisedFavouriteCartoonCharacters = prioritisedFavouriteCartoonCharacters;
|
||||
}
|
||||
|
||||
public List getPrioritisedFavouriteCars() {
|
||||
return _prioritisedFavouriteCars;
|
||||
}
|
||||
public void setPrioritisedFavouriteCars(List prioritisedFavouriteCars) {
|
||||
_prioritisedFavouriteCars = prioritisedFavouriteCars;
|
||||
}
|
||||
public void setPrioritisedFavouriteCountries(List prioritisedFavouriteCountries) {
|
||||
_prioritisedFavouriteCountries = prioritisedFavouriteCountries;
|
||||
}
|
||||
|
||||
|
||||
public List getPrioritisedFavouriteCountries() {
|
||||
return _prioritisedFavouriteCountries;
|
||||
}
|
||||
public void setPrioritisedFavouriteCountries(List prioritisedFavouriteCountries) {
|
||||
_prioritisedFavouriteCountries = prioritisedFavouriteCountries;
|
||||
}
|
||||
public Map getAvailableCities() {
|
||||
Map map = new LinkedHashMap();
|
||||
map.put("boston", "Boston");
|
||||
map.put("new york", "New York");
|
||||
map.put("london", "London");
|
||||
map.put("rome", "Rome");
|
||||
return map;
|
||||
}
|
||||
|
||||
public List getDefaultFavouriteCities() {
|
||||
List list = new ArrayList();
|
||||
list.add("boston");
|
||||
list.add("rome");
|
||||
return list;
|
||||
}
|
||||
|
||||
public List getFavouriteCities() {
|
||||
return _favouriteCities;
|
||||
}
|
||||
|
||||
public Map getAvailableCities() {
|
||||
Map map = new LinkedHashMap();
|
||||
map.put("boston", "Boston");
|
||||
map.put("new york", "New York");
|
||||
map.put("london", "London");
|
||||
map.put("rome", "Rome");
|
||||
return map;
|
||||
}
|
||||
public void setFavouriteCities(List favouriteCities) {
|
||||
this._favouriteCities = favouriteCities;
|
||||
}
|
||||
|
||||
public List getDefaultFavouriteCities() {
|
||||
List list = new ArrayList();
|
||||
list.add("boston");
|
||||
list.add("rome");
|
||||
return list;
|
||||
}
|
||||
// actions
|
||||
|
||||
public List getFavouriteCities() {
|
||||
return _favouriteCities;
|
||||
}
|
||||
public String input() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
public void setFavouriteCities(List favouriteCities) {
|
||||
this._favouriteCities = favouriteCities;
|
||||
}
|
||||
|
||||
// actions
|
||||
|
||||
public String input() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
public String submit() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
public String submit() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
+38
-38
@@ -27,52 +27,52 @@ import com.opensymphony.xwork2.ActionSupport;
|
||||
*/
|
||||
public class LotsOfRichtexteditorAction extends ActionSupport {
|
||||
|
||||
public String description1;
|
||||
public String description2 = "This is Description 2";
|
||||
public String description3;
|
||||
public String description4 = "This is Description 4";
|
||||
public String description1;
|
||||
public String description2 = "This is Description 2";
|
||||
public String description3;
|
||||
public String description4 = "This is Description 4";
|
||||
|
||||
public String getDescription1() {
|
||||
return this.description1;
|
||||
}
|
||||
public void setDescription1(String description1) {
|
||||
this.description1 = description1;
|
||||
}
|
||||
public String getDescription1() {
|
||||
return this.description1;
|
||||
}
|
||||
|
||||
public void setDescription1(String description1) {
|
||||
this.description1 = description1;
|
||||
}
|
||||
|
||||
|
||||
public String getDescription2() {
|
||||
return this.description2;
|
||||
}
|
||||
public void setDescription2(String description2) {
|
||||
this.description2 = description2;
|
||||
}
|
||||
public String getDescription2() {
|
||||
return this.description2;
|
||||
}
|
||||
|
||||
public void setDescription2(String description2) {
|
||||
this.description2 = description2;
|
||||
}
|
||||
|
||||
|
||||
public String getDescription3() {
|
||||
return this.description3;
|
||||
}
|
||||
public void setDescription3(String description3) {
|
||||
this.description3 = description3;
|
||||
}
|
||||
public String getDescription3() {
|
||||
return this.description3;
|
||||
}
|
||||
|
||||
public void setDescription3(String description3) {
|
||||
this.description3 = description3;
|
||||
}
|
||||
|
||||
|
||||
public String getDescription4() {
|
||||
return this.description4;
|
||||
}
|
||||
|
||||
public void setDescription4(String description4) {
|
||||
this.description4 = description4;
|
||||
}
|
||||
|
||||
|
||||
public String getDescription4() {
|
||||
return this.description4;
|
||||
}
|
||||
public void setDescription4(String description4) {
|
||||
this.description4 = description4;
|
||||
}
|
||||
public String input() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public String input() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
public String submit() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
public String submit() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,114 +22,115 @@ package org.apache.struts2.showcase;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class MoreSelectsAction extends ActionSupport {
|
||||
|
||||
|
||||
private List _prioritisedFavouriteCartoonCharacters;
|
||||
private List _prioritisedFavouriteCars;
|
||||
private List _prioritisedFavouriteCountries;
|
||||
private List favouriteNumbers;
|
||||
private List _prioritisedFavouriteCartoonCharacters;
|
||||
private List _prioritisedFavouriteCars;
|
||||
private List _prioritisedFavouriteCountries;
|
||||
private List favouriteNumbers;
|
||||
|
||||
|
||||
// Cartoon Characters
|
||||
public Map getDefaultFavouriteCartoonCharacters() {
|
||||
Map m = new LinkedHashMap();
|
||||
m.put("heMan", "He-Man");
|
||||
m.put("popeye", "Popeye");
|
||||
m.put("mockeyMouse", "Mickey Mouse");
|
||||
return m;
|
||||
}
|
||||
// Cartoon Characters
|
||||
public Map getDefaultFavouriteCartoonCharacters() {
|
||||
Map m = new LinkedHashMap();
|
||||
m.put("heMan", "He-Man");
|
||||
m.put("popeye", "Popeye");
|
||||
m.put("mockeyMouse", "Mickey Mouse");
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
// Cars
|
||||
public Map getDefaultFavouriteCars() {
|
||||
Map m = new LinkedHashMap();
|
||||
m.put("alfaRomeo", "Alfa Romeo");
|
||||
m.put("Toyota", "Toyota");
|
||||
m.put("Mitsubitshi", "Mitsubitshi");
|
||||
return m;
|
||||
}
|
||||
// Cars
|
||||
public Map getDefaultFavouriteCars() {
|
||||
Map m = new LinkedHashMap();
|
||||
m.put("alfaRomeo", "Alfa Romeo");
|
||||
m.put("Toyota", "Toyota");
|
||||
m.put("Mitsubitshi", "Mitsubitshi");
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
// Countries
|
||||
public Map getDefaultFavouriteCountries() {
|
||||
Map m = new LinkedHashMap();
|
||||
m.put("england", "England");
|
||||
m.put("america", "America");
|
||||
m.put("brazil", "Brazil");
|
||||
return m;
|
||||
}
|
||||
|
||||
// Countries
|
||||
public Map getDefaultFavouriteCountries() {
|
||||
Map m = new LinkedHashMap();
|
||||
m.put("england", "England");
|
||||
m.put("america", "America");
|
||||
m.put("brazil", "Brazil");
|
||||
return m;
|
||||
}
|
||||
|
||||
public List getDefaultFavouriteNumbers() {
|
||||
List list = new ArrayList();
|
||||
list.add("Three");
|
||||
list.add("Seven");
|
||||
return list;
|
||||
}
|
||||
public List getDefaultFavouriteNumbers() {
|
||||
List list = new ArrayList();
|
||||
list.add("Three");
|
||||
list.add("Seven");
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
public List getPrioritisedFavouriteCartoonCharacters() {
|
||||
return _prioritisedFavouriteCartoonCharacters;
|
||||
}
|
||||
|
||||
public List getPrioritisedFavouriteCartoonCharacters() {
|
||||
return _prioritisedFavouriteCartoonCharacters;
|
||||
}
|
||||
public void setPrioritisedFavouriteCartoonCharacters(List prioritisedFavouriteCartoonCharacters) {
|
||||
_prioritisedFavouriteCartoonCharacters = prioritisedFavouriteCartoonCharacters;
|
||||
}
|
||||
public void setPrioritisedFavouriteCartoonCharacters(List prioritisedFavouriteCartoonCharacters) {
|
||||
_prioritisedFavouriteCartoonCharacters = prioritisedFavouriteCartoonCharacters;
|
||||
}
|
||||
|
||||
public List getPrioritisedFavouriteCars() {
|
||||
return _prioritisedFavouriteCars;
|
||||
}
|
||||
public void setPrioritisedFavouriteCars(List prioritisedFavouriteCars) {
|
||||
_prioritisedFavouriteCars = prioritisedFavouriteCars;
|
||||
}
|
||||
public List getPrioritisedFavouriteCars() {
|
||||
return _prioritisedFavouriteCars;
|
||||
}
|
||||
|
||||
public void setPrioritisedFavouriteCars(List prioritisedFavouriteCars) {
|
||||
_prioritisedFavouriteCars = prioritisedFavouriteCars;
|
||||
}
|
||||
|
||||
|
||||
public List getPrioritisedFavouriteCountries() {
|
||||
return _prioritisedFavouriteCountries;
|
||||
}
|
||||
public void setPrioritisedFavouriteCountries(List prioritisedFavouriteCountries) {
|
||||
_prioritisedFavouriteCountries = prioritisedFavouriteCountries;
|
||||
}
|
||||
public List getPrioritisedFavouriteCountries() {
|
||||
return _prioritisedFavouriteCountries;
|
||||
}
|
||||
|
||||
public List getFavouriteNumbers() {
|
||||
return favouriteNumbers;
|
||||
}
|
||||
public void setPrioritisedFavouriteCountries(List prioritisedFavouriteCountries) {
|
||||
_prioritisedFavouriteCountries = prioritisedFavouriteCountries;
|
||||
}
|
||||
|
||||
public void setFavouriteNumbers(List favouriteNumbers) {
|
||||
this.favouriteNumbers = favouriteNumbers;
|
||||
}
|
||||
public List getFavouriteNumbers() {
|
||||
return favouriteNumbers;
|
||||
}
|
||||
|
||||
public Map getAvailableCities() {
|
||||
Map map = new LinkedHashMap();
|
||||
map.put("boston", "Boston");
|
||||
map.put("new york", "New York");
|
||||
map.put("london", "London");
|
||||
map.put("rome", "Rome");
|
||||
return map;
|
||||
}
|
||||
public void setFavouriteNumbers(List favouriteNumbers) {
|
||||
this.favouriteNumbers = favouriteNumbers;
|
||||
}
|
||||
|
||||
public List getDefaultFavouriteCities() {
|
||||
List list = new ArrayList();
|
||||
list.add("boston");
|
||||
list.add("rome");
|
||||
return list;
|
||||
}
|
||||
public Map getAvailableCities() {
|
||||
Map map = new LinkedHashMap();
|
||||
map.put("boston", "Boston");
|
||||
map.put("new york", "New York");
|
||||
map.put("london", "London");
|
||||
map.put("rome", "Rome");
|
||||
return map;
|
||||
}
|
||||
|
||||
// actions
|
||||
public List getDefaultFavouriteCities() {
|
||||
List list = new ArrayList();
|
||||
list.add("boston");
|
||||
list.add("rome");
|
||||
return list;
|
||||
}
|
||||
|
||||
public String input() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
// actions
|
||||
|
||||
public String submit() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
public String input() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
public String submit() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
+11
-12
@@ -20,22 +20,21 @@
|
||||
*/
|
||||
package org.apache.struts2.showcase;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
import org.apache.struts2.showcase.ajax.tree.Category;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
|
||||
public class ShowAjaxDynamicTreeAction extends ActionSupport {
|
||||
private int nodeId = 1;
|
||||
private int nodeId = 1;
|
||||
|
||||
public Category getCategory() {
|
||||
return Category.getById(nodeId);
|
||||
}
|
||||
public Category getCategory() {
|
||||
return Category.getById(nodeId);
|
||||
}
|
||||
|
||||
public int getNodeId() {
|
||||
return nodeId;
|
||||
}
|
||||
public int getNodeId() {
|
||||
return nodeId;
|
||||
}
|
||||
|
||||
public void setNodeId(int nodeId) {
|
||||
this.nodeId = nodeId;
|
||||
}
|
||||
public void setNodeId(int nodeId) {
|
||||
this.nodeId = nodeId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,17 +20,16 @@
|
||||
*/
|
||||
package org.apache.struts2.showcase;
|
||||
|
||||
import org.apache.struts2.showcase.ajax.tree.Category;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
import org.apache.struts2.showcase.ajax.tree.Category;
|
||||
|
||||
// START SNIPPET: treeExampleDynamicJavaShow
|
||||
|
||||
public class ShowDynamicTreeAction extends ActionSupport {
|
||||
|
||||
public Category getTreeRootNode() {
|
||||
return Category.getById(1);
|
||||
}
|
||||
public Category getTreeRootNode() {
|
||||
return Category.getById(1);
|
||||
}
|
||||
}
|
||||
|
||||
// END SNIPPET: treeExampleDynamicJavaShow
|
||||
|
||||
@@ -32,306 +32,318 @@ import java.util.*;
|
||||
*/
|
||||
public class UITagExample extends ActionSupport implements Validateable {
|
||||
|
||||
private static final long serialVersionUID = -94044809860988047L;
|
||||
|
||||
|
||||
String name;
|
||||
Date birthday;
|
||||
Date wakeup;
|
||||
String bio;
|
||||
String favouriteColor;
|
||||
List friends;
|
||||
String bestFriend;
|
||||
boolean legalAge;
|
||||
String state;
|
||||
String region;
|
||||
File picture;
|
||||
String pictureContentType;
|
||||
String pictureFileName;
|
||||
String favouriteLanguage;
|
||||
String favouriteVehicalType = "MotorcycleKey";
|
||||
String favouriteVehicalSpecific = "YamahaKey";
|
||||
|
||||
List leftSideCartoonCharacters;
|
||||
List rightSideCartoonCharacters;
|
||||
|
||||
List favouriteLanguages = new ArrayList();
|
||||
List vehicalTypeList = new ArrayList();
|
||||
Map vehicalSpecificMap = new HashMap();
|
||||
|
||||
String thoughts;
|
||||
|
||||
public UITagExample() {
|
||||
favouriteLanguages.add(new Language("EnglishKey", "English Language", "color: blue; font-style: italic;"));
|
||||
favouriteLanguages.add(new Language("FrenchKey", "French Language", "color: grey;"));
|
||||
favouriteLanguages.add(new Language("SpanishKey", "Spanish Language", "color: red; font-wight: bold;"));
|
||||
|
||||
VehicalType car = new VehicalType("CarKey", "Car");
|
||||
VehicalType motorcycle = new VehicalType("MotorcycleKey", "Motorcycle");
|
||||
vehicalTypeList.add(car);
|
||||
vehicalTypeList.add(motorcycle);
|
||||
|
||||
List cars = new ArrayList();
|
||||
cars.add(new VehicalSpecific("MercedesKey", "Mercedes"));
|
||||
cars.add(new VehicalSpecific("HondaKey", "Honda"));
|
||||
cars.add(new VehicalSpecific("FordKey", "Ford"));
|
||||
|
||||
List motorcycles = new ArrayList();
|
||||
motorcycles.add(new VehicalSpecific("SuzukiKey", "Suzuki"));
|
||||
motorcycles.add(new VehicalSpecific("YamahaKey", "Yamaha"));
|
||||
|
||||
vehicalSpecificMap.put(car, cars);
|
||||
vehicalSpecificMap.put(motorcycle, motorcycles);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public List getLeftSideCartoonCharacters() {
|
||||
return leftSideCartoonCharacters;
|
||||
}
|
||||
public void setLeftSideCartoonCharacters(List leftSideCartoonCharacters) {
|
||||
this.leftSideCartoonCharacters = leftSideCartoonCharacters;
|
||||
}
|
||||
|
||||
|
||||
public List getRightSideCartoonCharacters() {
|
||||
return rightSideCartoonCharacters;
|
||||
}
|
||||
public void setRightSideCartoonCharacters(List rightSideCartoonCharacters) {
|
||||
this.rightSideCartoonCharacters = rightSideCartoonCharacters;
|
||||
}
|
||||
|
||||
|
||||
public String getFavouriteVehicalType() {
|
||||
return favouriteVehicalType;
|
||||
}
|
||||
|
||||
public void setFavouriteVehicalType(String favouriteVehicalType) {
|
||||
this.favouriteVehicalType = favouriteVehicalType;
|
||||
}
|
||||
|
||||
public String getFavouriteVehicalSpecific() {
|
||||
return favouriteVehicalSpecific;
|
||||
}
|
||||
|
||||
public void setFavouriteVehicalSpecific(String favouriteVehicalSpecific) {
|
||||
this.favouriteVehicalSpecific = favouriteVehicalSpecific;
|
||||
}
|
||||
|
||||
public List getVehicalTypeList() {
|
||||
return vehicalTypeList;
|
||||
}
|
||||
|
||||
public List getVehicalSpecificList() {
|
||||
ValueStack stack = ServletActionContext.getValueStack(ServletActionContext.getRequest());
|
||||
Object vehicalType = stack.findValue("top");
|
||||
if (vehicalType != null && vehicalType instanceof VehicalType) {
|
||||
List l = (List) vehicalSpecificMap.get(vehicalType);
|
||||
return l;
|
||||
}
|
||||
return Collections.EMPTY_LIST;
|
||||
}
|
||||
|
||||
public List getFavouriteLanguages() {
|
||||
return favouriteLanguages;
|
||||
}
|
||||
|
||||
public String execute() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Date getBirthday() {
|
||||
return birthday;
|
||||
}
|
||||
private static final long serialVersionUID = -94044809860988047L;
|
||||
|
||||
|
||||
String name;
|
||||
Date birthday;
|
||||
Date wakeup;
|
||||
String bio;
|
||||
String favouriteColor;
|
||||
List friends;
|
||||
String bestFriend;
|
||||
boolean legalAge;
|
||||
String state;
|
||||
String region;
|
||||
File picture;
|
||||
String pictureContentType;
|
||||
String pictureFileName;
|
||||
String favouriteLanguage;
|
||||
String favouriteVehicalType = "MotorcycleKey";
|
||||
String favouriteVehicalSpecific = "YamahaKey";
|
||||
|
||||
List leftSideCartoonCharacters;
|
||||
List rightSideCartoonCharacters;
|
||||
|
||||
List favouriteLanguages = new ArrayList();
|
||||
List vehicalTypeList = new ArrayList();
|
||||
Map vehicalSpecificMap = new HashMap();
|
||||
|
||||
String thoughts;
|
||||
|
||||
public UITagExample() {
|
||||
favouriteLanguages.add(new Language("EnglishKey", "English Language", "color: blue; font-style: italic;"));
|
||||
favouriteLanguages.add(new Language("FrenchKey", "French Language", "color: grey;"));
|
||||
favouriteLanguages.add(new Language("SpanishKey", "Spanish Language", "color: red; font-wight: bold;"));
|
||||
|
||||
VehicalType car = new VehicalType("CarKey", "Car");
|
||||
VehicalType motorcycle = new VehicalType("MotorcycleKey", "Motorcycle");
|
||||
vehicalTypeList.add(car);
|
||||
vehicalTypeList.add(motorcycle);
|
||||
|
||||
List cars = new ArrayList();
|
||||
cars.add(new VehicalSpecific("MercedesKey", "Mercedes"));
|
||||
cars.add(new VehicalSpecific("HondaKey", "Honda"));
|
||||
cars.add(new VehicalSpecific("FordKey", "Ford"));
|
||||
|
||||
List motorcycles = new ArrayList();
|
||||
motorcycles.add(new VehicalSpecific("SuzukiKey", "Suzuki"));
|
||||
motorcycles.add(new VehicalSpecific("YamahaKey", "Yamaha"));
|
||||
|
||||
vehicalSpecificMap.put(car, cars);
|
||||
vehicalSpecificMap.put(motorcycle, motorcycles);
|
||||
}
|
||||
|
||||
|
||||
public List getLeftSideCartoonCharacters() {
|
||||
return leftSideCartoonCharacters;
|
||||
}
|
||||
|
||||
public void setLeftSideCartoonCharacters(List leftSideCartoonCharacters) {
|
||||
this.leftSideCartoonCharacters = leftSideCartoonCharacters;
|
||||
}
|
||||
|
||||
|
||||
public List getRightSideCartoonCharacters() {
|
||||
return rightSideCartoonCharacters;
|
||||
}
|
||||
|
||||
public void setRightSideCartoonCharacters(List rightSideCartoonCharacters) {
|
||||
this.rightSideCartoonCharacters = rightSideCartoonCharacters;
|
||||
}
|
||||
|
||||
|
||||
public String getFavouriteVehicalType() {
|
||||
return favouriteVehicalType;
|
||||
}
|
||||
|
||||
public void setFavouriteVehicalType(String favouriteVehicalType) {
|
||||
this.favouriteVehicalType = favouriteVehicalType;
|
||||
}
|
||||
|
||||
public String getFavouriteVehicalSpecific() {
|
||||
return favouriteVehicalSpecific;
|
||||
}
|
||||
|
||||
public void setFavouriteVehicalSpecific(String favouriteVehicalSpecific) {
|
||||
this.favouriteVehicalSpecific = favouriteVehicalSpecific;
|
||||
}
|
||||
|
||||
public List getVehicalTypeList() {
|
||||
return vehicalTypeList;
|
||||
}
|
||||
|
||||
public List getVehicalSpecificList() {
|
||||
ValueStack stack = ServletActionContext.getValueStack(ServletActionContext.getRequest());
|
||||
Object vehicalType = stack.findValue("top");
|
||||
if (vehicalType != null && vehicalType instanceof VehicalType) {
|
||||
List l = (List) vehicalSpecificMap.get(vehicalType);
|
||||
return l;
|
||||
}
|
||||
return Collections.EMPTY_LIST;
|
||||
}
|
||||
|
||||
public List getFavouriteLanguages() {
|
||||
return favouriteLanguages;
|
||||
}
|
||||
|
||||
public String execute() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setBirthday(Date birthday) {
|
||||
this.birthday = birthday;
|
||||
}
|
||||
|
||||
public String getBio() {
|
||||
return bio;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setBio(String bio) {
|
||||
this.bio = bio;
|
||||
}
|
||||
public Date getBirthday() {
|
||||
return birthday;
|
||||
}
|
||||
|
||||
public String getFavouriteColor() {
|
||||
return favouriteColor;
|
||||
}
|
||||
public void setBirthday(Date birthday) {
|
||||
this.birthday = birthday;
|
||||
}
|
||||
|
||||
public void setFavouriteColor(String favoriteColor) {
|
||||
this.favouriteColor = favoriteColor;
|
||||
}
|
||||
public String getBio() {
|
||||
return bio;
|
||||
}
|
||||
|
||||
public List getFriends() {
|
||||
return friends;
|
||||
}
|
||||
public void setBio(String bio) {
|
||||
this.bio = bio;
|
||||
}
|
||||
|
||||
public void setFriends(List friends) {
|
||||
this.friends = friends;
|
||||
}
|
||||
|
||||
public String getBestFriend() {
|
||||
return bestFriend;
|
||||
}
|
||||
public String getFavouriteColor() {
|
||||
return favouriteColor;
|
||||
}
|
||||
|
||||
public void setBestFriend(String bestFriend) {
|
||||
this.bestFriend = bestFriend;
|
||||
}
|
||||
|
||||
public boolean isLegalAge() {
|
||||
return legalAge;
|
||||
}
|
||||
|
||||
public void setLegalAge(boolean legalAge) {
|
||||
this.legalAge = legalAge;
|
||||
}
|
||||
|
||||
public String getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public void setState(String state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public String getRegion() {
|
||||
return region;
|
||||
}
|
||||
|
||||
public void setRegion(String region) {
|
||||
this.region = region;
|
||||
}
|
||||
|
||||
public void setPicture(File picture) {
|
||||
this.picture = picture;
|
||||
}
|
||||
|
||||
public File getPicture() {
|
||||
return this.picture;
|
||||
}
|
||||
|
||||
public void setPictureContentType(String pictureContentType) {
|
||||
this.pictureContentType = pictureContentType;
|
||||
}
|
||||
|
||||
public void setPictureFileName(String pictureFileName) {
|
||||
this.pictureFileName = pictureFileName;
|
||||
}
|
||||
|
||||
public void setFavouriteLanguage(String favouriteLanguage) {
|
||||
this.favouriteLanguage = favouriteLanguage;
|
||||
}
|
||||
|
||||
public String getFavouriteLanguage() {
|
||||
return favouriteLanguage;
|
||||
}
|
||||
|
||||
|
||||
public void setThoughts(String thoughts) {
|
||||
this.thoughts = thoughts;
|
||||
}
|
||||
|
||||
public String getThoughts() {
|
||||
return this.thoughts;
|
||||
}
|
||||
|
||||
public Date getWakeup() {
|
||||
return wakeup;
|
||||
}
|
||||
|
||||
public void setWakeup(Date wakeup) {
|
||||
this.wakeup = wakeup;
|
||||
}
|
||||
|
||||
public String doSubmit() {
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// === inner class
|
||||
public static class Language {
|
||||
String description;
|
||||
String key;
|
||||
String style;
|
||||
|
||||
public Language(String key, String description, String style) {
|
||||
this.key = key;
|
||||
this.description = description;
|
||||
this.style = style;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
public String getStyle() {
|
||||
return style;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static class VehicalType {
|
||||
String key;
|
||||
String description;
|
||||
public VehicalType(String key, String description) {
|
||||
this.key = key;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getKey() { return this.key; }
|
||||
public String getDescription() { return this.description; }
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (! (obj instanceof VehicalType)) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return key.equals(((VehicalType)obj).getKey());
|
||||
}
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return key.hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class VehicalSpecific {
|
||||
String key;
|
||||
String description;
|
||||
public VehicalSpecific(String key, String description) {
|
||||
this.key = key;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getKey() { return this.key; }
|
||||
public String getDescription() { return this.description; }
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (! (obj instanceof VehicalSpecific)) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return key.equals(((VehicalSpecific)obj).getKey());
|
||||
}
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return key.hashCode();
|
||||
}
|
||||
}
|
||||
public void setFavouriteColor(String favoriteColor) {
|
||||
this.favouriteColor = favoriteColor;
|
||||
}
|
||||
|
||||
public List getFriends() {
|
||||
return friends;
|
||||
}
|
||||
|
||||
public void setFriends(List friends) {
|
||||
this.friends = friends;
|
||||
}
|
||||
|
||||
public String getBestFriend() {
|
||||
return bestFriend;
|
||||
}
|
||||
|
||||
public void setBestFriend(String bestFriend) {
|
||||
this.bestFriend = bestFriend;
|
||||
}
|
||||
|
||||
public boolean isLegalAge() {
|
||||
return legalAge;
|
||||
}
|
||||
|
||||
public void setLegalAge(boolean legalAge) {
|
||||
this.legalAge = legalAge;
|
||||
}
|
||||
|
||||
public String getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public void setState(String state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public String getRegion() {
|
||||
return region;
|
||||
}
|
||||
|
||||
public void setRegion(String region) {
|
||||
this.region = region;
|
||||
}
|
||||
|
||||
public void setPicture(File picture) {
|
||||
this.picture = picture;
|
||||
}
|
||||
|
||||
public File getPicture() {
|
||||
return this.picture;
|
||||
}
|
||||
|
||||
public void setPictureContentType(String pictureContentType) {
|
||||
this.pictureContentType = pictureContentType;
|
||||
}
|
||||
|
||||
public void setPictureFileName(String pictureFileName) {
|
||||
this.pictureFileName = pictureFileName;
|
||||
}
|
||||
|
||||
public void setFavouriteLanguage(String favouriteLanguage) {
|
||||
this.favouriteLanguage = favouriteLanguage;
|
||||
}
|
||||
|
||||
public String getFavouriteLanguage() {
|
||||
return favouriteLanguage;
|
||||
}
|
||||
|
||||
|
||||
public void setThoughts(String thoughts) {
|
||||
this.thoughts = thoughts;
|
||||
}
|
||||
|
||||
public String getThoughts() {
|
||||
return this.thoughts;
|
||||
}
|
||||
|
||||
public Date getWakeup() {
|
||||
return wakeup;
|
||||
}
|
||||
|
||||
public void setWakeup(Date wakeup) {
|
||||
this.wakeup = wakeup;
|
||||
}
|
||||
|
||||
public String doSubmit() {
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
// === inner class
|
||||
public static class Language {
|
||||
String description;
|
||||
String key;
|
||||
String style;
|
||||
|
||||
public Language(String key, String description, String style) {
|
||||
this.key = key;
|
||||
this.description = description;
|
||||
this.style = style;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public String getStyle() {
|
||||
return style;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static class VehicalType {
|
||||
String key;
|
||||
String description;
|
||||
|
||||
public VehicalType(String key, String description) {
|
||||
this.key = key;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return this.key;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return this.description;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof VehicalType)) {
|
||||
return false;
|
||||
} else {
|
||||
return key.equals(((VehicalType) obj).getKey());
|
||||
}
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return key.hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class VehicalSpecific {
|
||||
String key;
|
||||
String description;
|
||||
|
||||
public VehicalSpecific(String key, String description) {
|
||||
this.key = key;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return this.key;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return this.description;
|
||||
}
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof VehicalSpecific)) {
|
||||
return false;
|
||||
} else {
|
||||
return key.equals(((VehicalSpecific) obj).getKey());
|
||||
}
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return key.hashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+52
-54
@@ -20,78 +20,76 @@
|
||||
*/
|
||||
package org.apache.struts2.showcase.action;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.struts2.showcase.dao.Dao;
|
||||
import org.apache.struts2.showcase.model.IdEntity;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* AbstractCRUDAction.
|
||||
*
|
||||
*/
|
||||
|
||||
public abstract class AbstractCRUDAction extends ActionSupport {
|
||||
|
||||
private static final Logger log = Logger.getLogger(AbstractCRUDAction.class);
|
||||
private static final Logger log = Logger.getLogger(AbstractCRUDAction.class);
|
||||
|
||||
private Collection availableItems;
|
||||
private String[] toDelete;
|
||||
private Collection availableItems;
|
||||
private String[] toDelete;
|
||||
|
||||
protected abstract Dao getDao();
|
||||
protected abstract Dao getDao();
|
||||
|
||||
|
||||
public Collection getAvailableItems() {
|
||||
return availableItems;
|
||||
}
|
||||
public Collection getAvailableItems() {
|
||||
return availableItems;
|
||||
}
|
||||
|
||||
public String[] getToDelete() {
|
||||
return toDelete;
|
||||
}
|
||||
public String[] getToDelete() {
|
||||
return toDelete;
|
||||
}
|
||||
|
||||
public void setToDelete(String[] toDelete) {
|
||||
this.toDelete = toDelete;
|
||||
}
|
||||
public void setToDelete(String[] toDelete) {
|
||||
this.toDelete = toDelete;
|
||||
}
|
||||
|
||||
public String list() throws Exception {
|
||||
this.availableItems = getDao().findAll();
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("AbstractCRUDAction - [list]: " + (availableItems !=null?""+availableItems.size():"no") + " items found");
|
||||
}
|
||||
return execute();
|
||||
}
|
||||
public String list() throws Exception {
|
||||
this.availableItems = getDao().findAll();
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("AbstractCRUDAction - [list]: " + (availableItems != null ? "" + availableItems.size() : "no") + " items found");
|
||||
}
|
||||
return execute();
|
||||
}
|
||||
|
||||
public String delete() throws Exception {
|
||||
if (toDelete != null) {
|
||||
int count=0;
|
||||
for (int i = 0, j=toDelete.length; i < j; i++) {
|
||||
count = count + getDao().delete(toDelete[i]);
|
||||
}
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("AbstractCRUDAction - [delete]: " + count + " items deleted.");
|
||||
}
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
public String delete() throws Exception {
|
||||
if (toDelete != null) {
|
||||
int count = 0;
|
||||
for (int i = 0, j = toDelete.length; i < j; i++) {
|
||||
count = count + getDao().delete(toDelete[i]);
|
||||
}
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("AbstractCRUDAction - [delete]: " + count + " items deleted.");
|
||||
}
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method for fetching already persistent object from storage for usage in params-prepare-params cycle.
|
||||
*
|
||||
* @param tryId The id to try to get persistent object for
|
||||
* @param tryObject The object, induced by first params invocation, possibly containing id to try to get persistent
|
||||
* object for
|
||||
* @return The persistent object, if found. <tt>null</tt> otherwise.
|
||||
*/
|
||||
protected IdEntity fetch(Serializable tryId, IdEntity tryObject) {
|
||||
IdEntity result = null;
|
||||
if (tryId != null) {
|
||||
result = getDao().get(tryId);
|
||||
} else if (tryObject != null) {
|
||||
result = getDao().get(tryObject.getId());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* Utility method for fetching already persistent object from storage for usage in params-prepare-params cycle.
|
||||
*
|
||||
* @param tryId The id to try to get persistent object for
|
||||
* @param tryObject The object, induced by first params invocation, possibly containing id to try to get persistent
|
||||
* object for
|
||||
* @return The persistent object, if found. <tt>null</tt> otherwise.
|
||||
*/
|
||||
protected IdEntity fetch(Serializable tryId, IdEntity tryObject) {
|
||||
IdEntity result = null;
|
||||
if (tryId != null) {
|
||||
result = getDao().get(tryId);
|
||||
} else if (tryObject != null) {
|
||||
result = getDao().get(tryObject.getId());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
+68
-73
@@ -20,19 +20,19 @@
|
||||
*/
|
||||
package org.apache.struts2.showcase.action;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import com.opensymphony.xwork2.Preparable;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.struts2.showcase.application.TestDataProvider;
|
||||
import org.apache.struts2.showcase.dao.Dao;
|
||||
import org.apache.struts2.showcase.dao.EmployeeDao;
|
||||
import org.apache.struts2.showcase.model.Employee;
|
||||
import org.apache.struts2.showcase.model.Skill;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.opensymphony.xwork2.Preparable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* JsfEmployeeAction.
|
||||
@@ -40,87 +40,82 @@ import com.opensymphony.xwork2.Preparable;
|
||||
|
||||
public class EmployeeAction extends AbstractCRUDAction implements Preparable {
|
||||
|
||||
private static final long serialVersionUID = 7047317819789938957L;
|
||||
private static final long serialVersionUID = 7047317819789938957L;
|
||||
|
||||
private static final Logger log = Logger.getLogger(EmployeeAction.class);
|
||||
private static final Logger log = Logger.getLogger(EmployeeAction.class);
|
||||
|
||||
private Long empId;
|
||||
protected EmployeeDao employeeDao;
|
||||
private Employee currentEmployee;
|
||||
private List selectedSkills;
|
||||
@Autowired
|
||||
private EmployeeDao employeeDao;
|
||||
|
||||
public Long getEmpId() {
|
||||
return empId;
|
||||
}
|
||||
private Long empId;
|
||||
private Employee currentEmployee;
|
||||
private List<String> selectedSkills;
|
||||
|
||||
public void setEmpId(Long empId) {
|
||||
this.empId = empId;
|
||||
}
|
||||
public String execute() throws Exception {
|
||||
if (getCurrentEmployee() != null && getCurrentEmployee().getOtherSkills() != null) {
|
||||
setSelectedSkills(new ArrayList<String>());
|
||||
Iterator it = getCurrentEmployee().getOtherSkills().iterator();
|
||||
while (it.hasNext()) {
|
||||
getSelectedSkills().add(((Skill) it.next()).getName());
|
||||
}
|
||||
}
|
||||
return super.execute();
|
||||
}
|
||||
|
||||
public Employee getCurrentEmployee() {
|
||||
return currentEmployee;
|
||||
}
|
||||
public String save() throws Exception {
|
||||
if (getCurrentEmployee() != null) {
|
||||
setEmpId((Long) employeeDao.merge(getCurrentEmployee()));
|
||||
employeeDao.setSkills(getEmpId(), getSelectedSkills());
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
public void setCurrentEmployee(Employee currentEmployee) {
|
||||
this.currentEmployee = currentEmployee;
|
||||
}
|
||||
public Long getEmpId() {
|
||||
return empId;
|
||||
}
|
||||
|
||||
public String[] getAvailablePositions() {
|
||||
return TestDataProvider.POSITIONS;
|
||||
}
|
||||
public void setEmpId(Long empId) {
|
||||
this.empId = empId;
|
||||
}
|
||||
|
||||
public List getAvailableLevels() {
|
||||
return Arrays.asList(TestDataProvider.LEVELS);
|
||||
}
|
||||
public Employee getCurrentEmployee() {
|
||||
return currentEmployee;
|
||||
}
|
||||
|
||||
public List getSelectedSkills() {
|
||||
return selectedSkills;
|
||||
}
|
||||
public void setCurrentEmployee(Employee currentEmployee) {
|
||||
this.currentEmployee = currentEmployee;
|
||||
}
|
||||
|
||||
public void setSelectedSkills(List selectedSkills) {
|
||||
this.selectedSkills = selectedSkills;
|
||||
}
|
||||
public String[] getAvailablePositions() {
|
||||
return TestDataProvider.POSITIONS;
|
||||
}
|
||||
|
||||
protected Dao getDao() {
|
||||
return employeeDao;
|
||||
}
|
||||
public List getAvailableLevels() {
|
||||
return Arrays.asList(TestDataProvider.LEVELS);
|
||||
}
|
||||
|
||||
public void setEmployeeDao(EmployeeDao employeeDao) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("JsfEmployeeAction - [setEmployeeDao]: employeeDao injected.");
|
||||
}
|
||||
this.employeeDao = employeeDao;
|
||||
}
|
||||
public List<String> getSelectedSkills() {
|
||||
return selectedSkills;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called to allow the action to prepare itself.
|
||||
*
|
||||
* @throws Exception thrown if a system level exception occurs.
|
||||
*/
|
||||
public void prepare() throws Exception {
|
||||
Employee preFetched = (Employee) fetch(getEmpId(), getCurrentEmployee());
|
||||
if (preFetched != null) {
|
||||
setCurrentEmployee(preFetched);
|
||||
}
|
||||
}
|
||||
public void setSelectedSkills(List<String> selectedSkills) {
|
||||
this.selectedSkills = selectedSkills;
|
||||
}
|
||||
|
||||
public String execute() throws Exception {
|
||||
if (getCurrentEmployee() != null && getCurrentEmployee().getOtherSkills() != null) {
|
||||
setSelectedSkills(new ArrayList());
|
||||
Iterator it = getCurrentEmployee().getOtherSkills().iterator();
|
||||
while (it.hasNext()) {
|
||||
getSelectedSkills().add(((Skill) it.next()).getName());
|
||||
}
|
||||
}
|
||||
return super.execute();
|
||||
}
|
||||
protected Dao getDao() {
|
||||
return employeeDao;
|
||||
}
|
||||
|
||||
public String save() throws Exception {
|
||||
if (getCurrentEmployee() != null) {
|
||||
setEmpId((Long) employeeDao.merge(getCurrentEmployee()));
|
||||
employeeDao.setSkills(getEmpId(), getSelectedSkills());
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
/**
|
||||
* This method is called to allow the action to prepare itself.
|
||||
*
|
||||
* @throws Exception thrown if a system level exception occurs.
|
||||
*/
|
||||
public void prepare() throws Exception {
|
||||
Employee preFetched = (Employee) fetch(getEmpId(), getCurrentEmployee());
|
||||
if (preFetched != null) {
|
||||
setCurrentEmployee(preFetched);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,69 +20,65 @@
|
||||
*/
|
||||
package org.apache.struts2.showcase.action;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class ExampleAction extends ActionSupport {
|
||||
public static final String CONSTANT = "Struts Rocks!";
|
||||
|
||||
public static Date getCurrentDate() {
|
||||
return new Date();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "John Galt";
|
||||
}
|
||||
public static final String CONSTANT = "Struts Rocks!";
|
||||
|
||||
public String[] getBands() {
|
||||
return new String[] { "Pink Floyd", "Metallica", "Guns & Roses" };
|
||||
}
|
||||
public static Date getCurrentDate() {
|
||||
return new Date();
|
||||
}
|
||||
|
||||
public List<String> getMovies() {
|
||||
return Arrays.asList("Lord of the Rings", "Matrix");
|
||||
}
|
||||
public String getName() {
|
||||
return "John Galt";
|
||||
}
|
||||
|
||||
public Book getBook() {
|
||||
return new Book("Iliad", "Homer");
|
||||
}
|
||||
public String[] getBands() {
|
||||
return new String[]{"Pink Floyd", "Metallica", "Guns & Roses"};
|
||||
}
|
||||
|
||||
public Map<String, Book> getBooks() {
|
||||
Map<String, Book> books = new HashMap<String, Book>();
|
||||
books.put("Iliad", new Book("Iliad", "Homer"));
|
||||
books.put("The Republic", new Book("The Replublic", "Plato"));
|
||||
books.put("Thus Spake Zarathustra", new Book("Thus Spake Zarathustra",
|
||||
"Friedrich Nietzsche"));
|
||||
return books;
|
||||
}
|
||||
public List<String> getMovies() {
|
||||
return Arrays.asList("Lord of the Rings", "Matrix");
|
||||
}
|
||||
|
||||
public Book getBook() {
|
||||
return new Book("Iliad", "Homer");
|
||||
}
|
||||
|
||||
public Map<String, Book> getBooks() {
|
||||
Map<String, Book> books = new HashMap<String, Book>();
|
||||
books.put("Iliad", new Book("Iliad", "Homer"));
|
||||
books.put("The Republic", new Book("The Replublic", "Plato"));
|
||||
books.put("Thus Spake Zarathustra", new Book("Thus Spake Zarathustra",
|
||||
"Friedrich Nietzsche"));
|
||||
return books;
|
||||
}
|
||||
}
|
||||
|
||||
class Book {
|
||||
private String title;
|
||||
private String author;
|
||||
private String title;
|
||||
private String author;
|
||||
|
||||
public Book(String title, String author) {
|
||||
this.title = title;
|
||||
this.author = author;
|
||||
}
|
||||
public Book(String title, String author) {
|
||||
this.title = title;
|
||||
this.author = author;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getAuthor() {
|
||||
return author;
|
||||
}
|
||||
public String getAuthor() {
|
||||
return author;
|
||||
}
|
||||
|
||||
public void setAuthor(String author) {
|
||||
this.author = author;
|
||||
}
|
||||
public void setAuthor(String author) {
|
||||
this.author = author;
|
||||
}
|
||||
}
|
||||
@@ -20,58 +20,52 @@
|
||||
*/
|
||||
package org.apache.struts2.showcase.action;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
|
||||
import org.apache.struts2.ServletActionContext;
|
||||
|
||||
import com.opensymphony.xwork2.Action;
|
||||
import com.opensymphony.xwork2.interceptor.annotations.After;
|
||||
import org.apache.struts2.ServletActionContext;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* Will only work on containers that unzip war files
|
||||
*
|
||||
*/
|
||||
public class JSPEvalAction extends ExampleAction {
|
||||
private String jsp;
|
||||
private final static String FILE = "/interactive/demo.jsp";
|
||||
private String jsp;
|
||||
private final static String FILE = "/interactive/demo.jsp";
|
||||
|
||||
public String execute() throws IOException {
|
||||
if (jsp != null) {
|
||||
//write it to file
|
||||
URL url = ServletActionContext.getServletContext().getResource(FILE);
|
||||
BufferedWriter writer = new BufferedWriter(new FileWriter(new File(url
|
||||
.getFile())));
|
||||
try {
|
||||
//directive
|
||||
writer.write("<%@ taglib prefix=\"s\" uri=\"/struts-tags\" %>");
|
||||
writer.write(jsp);
|
||||
} finally {
|
||||
if (writer != null)
|
||||
writer.close();
|
||||
}
|
||||
}
|
||||
return Action.SUCCESS;
|
||||
}
|
||||
public String execute() throws IOException {
|
||||
if (jsp != null) {
|
||||
//write it to file
|
||||
URL url = ServletActionContext.getServletContext().getResource(FILE);
|
||||
BufferedWriter writer = new BufferedWriter(new FileWriter(new File(url
|
||||
.getFile())));
|
||||
try {
|
||||
//directive
|
||||
writer.write("<%@ taglib prefix=\"s\" uri=\"/struts-tags\" %>");
|
||||
writer.write(jsp);
|
||||
} finally {
|
||||
if (writer != null)
|
||||
writer.close();
|
||||
}
|
||||
}
|
||||
return Action.SUCCESS;
|
||||
}
|
||||
|
||||
@After
|
||||
public void cleanUp() throws IOException {
|
||||
URL url = ServletActionContext.getServletContext().getResource(FILE);
|
||||
FileOutputStream out = new FileOutputStream(new File(url.getFile()));
|
||||
try {
|
||||
out.getChannel().truncate(0);
|
||||
} finally {
|
||||
if (out != null)
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
@After
|
||||
public void cleanUp() throws IOException {
|
||||
URL url = ServletActionContext.getServletContext().getResource(FILE);
|
||||
FileOutputStream out = new FileOutputStream(new File(url.getFile()));
|
||||
try {
|
||||
out.getChannel().truncate(0);
|
||||
} finally {
|
||||
if (out != null)
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
|
||||
public void setJsp(String jsp) {
|
||||
this.jsp = jsp;
|
||||
}
|
||||
public void setJsp(String jsp) {
|
||||
this.jsp = jsp;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,70 +20,64 @@
|
||||
*/
|
||||
package org.apache.struts2.showcase.action;
|
||||
|
||||
import com.opensymphony.xwork2.Preparable;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.struts2.showcase.dao.Dao;
|
||||
import org.apache.struts2.showcase.dao.SkillDao;
|
||||
import org.apache.struts2.showcase.model.Skill;
|
||||
|
||||
import com.opensymphony.xwork2.Preparable;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
* SkillAction.
|
||||
*
|
||||
*/
|
||||
|
||||
public class SkillAction extends AbstractCRUDAction implements Preparable {
|
||||
|
||||
private static final Logger log = Logger.getLogger(SkillAction.class);
|
||||
private static final Logger log = Logger.getLogger(SkillAction.class);
|
||||
|
||||
private String skillName;
|
||||
protected SkillDao skillDao;
|
||||
private Skill currentSkill;
|
||||
@Autowired
|
||||
private SkillDao skillDao;
|
||||
|
||||
public String getSkillName() {
|
||||
return skillName;
|
||||
}
|
||||
private String skillName;
|
||||
private Skill currentSkill;
|
||||
|
||||
public void setSkillName(String skillName) {
|
||||
this.skillName = skillName;
|
||||
}
|
||||
/**
|
||||
* This method is called to allow the action to prepare itself.
|
||||
*
|
||||
* @throws Exception thrown if a system level exception occurs.
|
||||
*/
|
||||
public void prepare() throws Exception {
|
||||
Skill preFetched = (Skill) fetch(getSkillName(), getCurrentSkill());
|
||||
if (preFetched != null) {
|
||||
setCurrentSkill(preFetched);
|
||||
}
|
||||
}
|
||||
|
||||
protected Dao getDao() {
|
||||
return skillDao;
|
||||
}
|
||||
public String save() throws Exception {
|
||||
if (getCurrentSkill() != null) {
|
||||
setSkillName((String) skillDao.merge(getCurrentSkill()));
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
public void setSkillDao(SkillDao skillDao) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("SkillAction - [setSkillDao]: skillDao injected.");
|
||||
}
|
||||
this.skillDao = skillDao;
|
||||
}
|
||||
public String getSkillName() {
|
||||
return skillName;
|
||||
}
|
||||
|
||||
public Skill getCurrentSkill() {
|
||||
return currentSkill;
|
||||
}
|
||||
public void setSkillName(String skillName) {
|
||||
this.skillName = skillName;
|
||||
}
|
||||
|
||||
public void setCurrentSkill(Skill currentSkill) {
|
||||
this.currentSkill = currentSkill;
|
||||
}
|
||||
protected Dao getDao() {
|
||||
return skillDao;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called to allow the action to prepare itself.
|
||||
*
|
||||
* @throws Exception thrown if a system level exception occurs.
|
||||
*/
|
||||
public void prepare() throws Exception {
|
||||
Skill preFetched = (Skill) fetch(getSkillName(), getCurrentSkill());
|
||||
if (preFetched != null) {
|
||||
setCurrentSkill(preFetched);
|
||||
}
|
||||
}
|
||||
public Skill getCurrentSkill() {
|
||||
return currentSkill;
|
||||
}
|
||||
|
||||
public String save() throws Exception {
|
||||
if (getCurrentSkill() != null) {
|
||||
setSkillName((String) skillDao.merge(getCurrentSkill()));
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
public void setCurrentSkill(Skill currentSkill) {
|
||||
this.currentSkill = currentSkill;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+11
-14
@@ -22,24 +22,21 @@ package org.apache.struts2.showcase.actionchaining;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class ActionChain1 extends ActionSupport {
|
||||
|
||||
private static final long serialVersionUID = -6811701750042275153L;
|
||||
private static final long serialVersionUID = -6811701750042275153L;
|
||||
|
||||
private String actionChain1Property1 = "Property Set In Action Chain 1";
|
||||
private String actionChain1Property1 = "Property Set In Action Chain 1";
|
||||
|
||||
public String getActionChain1Property1() {
|
||||
return actionChain1Property1;
|
||||
}
|
||||
public void setActionChain1Property1(String actionChain1Property1) {
|
||||
this.actionChain1Property1 = actionChain1Property1;
|
||||
}
|
||||
public String input() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
public String getActionChain1Property1() {
|
||||
return actionChain1Property1;
|
||||
}
|
||||
|
||||
public String input() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
public void setActionChain1Property1(String actionChain1Property1) {
|
||||
this.actionChain1Property1 = actionChain1Property1;
|
||||
}
|
||||
}
|
||||
|
||||
+21
-27
@@ -22,37 +22,31 @@ package org.apache.struts2.showcase.actionchaining;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class ActionChain2 extends ActionSupport {
|
||||
|
||||
private static final long serialVersionUID = 3951745956044674809L;
|
||||
private static final long serialVersionUID = 3951745956044674809L;
|
||||
|
||||
private String actionChain1Property1;
|
||||
private String actionChain2Property1 = "Property Set in Action Chain 2";
|
||||
private String actionChain1Property1;
|
||||
private String actionChain2Property1 = "Property Set in Action Chain 2";
|
||||
|
||||
public String execute() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
public String getActionChain1Property1() {
|
||||
return actionChain1Property1;
|
||||
}
|
||||
|
||||
public void setActionChain1Property1(String actionChain1Property1) {
|
||||
this.actionChain1Property1 = actionChain1Property1;
|
||||
}
|
||||
|
||||
|
||||
public String getActionChain1Property1() {
|
||||
return actionChain1Property1;
|
||||
}
|
||||
public void setActionChain1Property1(String actionChain1Property1) {
|
||||
this.actionChain1Property1 = actionChain1Property1;
|
||||
}
|
||||
public String getActionChain2Property1() {
|
||||
return actionChain2Property1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String getActionChain2Property1() {
|
||||
return actionChain2Property1;
|
||||
}
|
||||
public void setActionChain2Property1(String actionChain2Property1) {
|
||||
this.actionChain2Property1 = actionChain2Property1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public String execute() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
public void setActionChain2Property1(String actionChain2Property1) {
|
||||
this.actionChain2Property1 = actionChain2Property1;
|
||||
}
|
||||
}
|
||||
|
||||
+27
-32
@@ -22,47 +22,42 @@ package org.apache.struts2.showcase.actionchaining;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class ActionChain3 extends ActionSupport {
|
||||
|
||||
private static final long serialVersionUID = -1456568865075250621L;
|
||||
private static final long serialVersionUID = -1456568865075250621L;
|
||||
|
||||
private String actionChain1Property1;
|
||||
private String actionChain2Property1;
|
||||
private String actionChain3Property1 = "Property set in Action Chain 3";
|
||||
private String actionChain1Property1;
|
||||
private String actionChain2Property1;
|
||||
private String actionChain3Property1 = "Property set in Action Chain 3";
|
||||
|
||||
|
||||
public String getActionChain1Property1() {
|
||||
return actionChain1Property1;
|
||||
}
|
||||
public void setActionChain1Property1(String actionChain1Property1) {
|
||||
this.actionChain1Property1 = actionChain1Property1;
|
||||
}
|
||||
public String execute() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
public String getActionChain1Property1() {
|
||||
return actionChain1Property1;
|
||||
}
|
||||
|
||||
public void setActionChain1Property1(String actionChain1Property1) {
|
||||
this.actionChain1Property1 = actionChain1Property1;
|
||||
}
|
||||
|
||||
|
||||
public String getActionChain2Property1() {
|
||||
return actionChain2Property1;
|
||||
}
|
||||
|
||||
public String getActionChain2Property1() {
|
||||
return actionChain2Property1;
|
||||
}
|
||||
public void setActionChain2Property1(String actionChain2Property1) {
|
||||
this.actionChain2Property1 = actionChain2Property1;
|
||||
}
|
||||
public void setActionChain2Property1(String actionChain2Property1) {
|
||||
this.actionChain2Property1 = actionChain2Property1;
|
||||
}
|
||||
|
||||
|
||||
public String getActionChain3Property1() {
|
||||
return actionChain3Property1;
|
||||
}
|
||||
|
||||
public String getActionChain3Property1() {
|
||||
return actionChain3Property1;
|
||||
}
|
||||
public void setActionChain3Property1(String actionChain3Property1) {
|
||||
this.actionChain3Property1 = actionChain3Property1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public String execute() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
public void setActionChain3Property1(String actionChain3Property1) {
|
||||
this.actionChain3Property1 = actionChain3Property1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,30 +25,28 @@ import com.opensymphony.xwork2.Action;
|
||||
import java.io.Serializable;
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
public class AjaxTestAction implements Action, Serializable {
|
||||
|
||||
private static int counter = 0;
|
||||
private String data;
|
||||
private static int counter = 0;
|
||||
private String data;
|
||||
|
||||
public long getServerTime() {
|
||||
return System.currentTimeMillis();
|
||||
}
|
||||
public String execute() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return ++counter;
|
||||
}
|
||||
public long getServerTime() {
|
||||
return System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public String getData() {
|
||||
return data;
|
||||
}
|
||||
public int getCount() {
|
||||
return ++counter;
|
||||
}
|
||||
|
||||
public void setData(String data) {
|
||||
this.data = data;
|
||||
}
|
||||
public String getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public String execute() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
public void setData(String data) {
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
|
||||
+27
-27
@@ -20,40 +20,40 @@
|
||||
*/
|
||||
package org.apache.struts2.showcase.ajax;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
|
||||
public class AutocompleterExampleAction extends ActionSupport {
|
||||
private String select;
|
||||
private List<String> options = new ArrayList<String>();
|
||||
private String select;
|
||||
private List<String> options = new ArrayList<String>();
|
||||
|
||||
private static final long serialVersionUID = -8481638176160014396L;
|
||||
private static final long serialVersionUID = -8481638176160014396L;
|
||||
|
||||
public String execute() throws Exception {
|
||||
if ("fruits".equals(select)) {
|
||||
options.add("apple");
|
||||
options.add("banana");
|
||||
options.add("grape");
|
||||
options.add("pear");
|
||||
} else if ("colors".equals(select)) {
|
||||
options.add("red");
|
||||
options.add("green");
|
||||
options.add("blue");
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
public String execute() throws Exception {
|
||||
if ("fruits".equals(select)) {
|
||||
options.add("apple");
|
||||
options.add("banana");
|
||||
options.add("grape");
|
||||
options.add("pear");
|
||||
} else if ("colors".equals(select)) {
|
||||
options.add("red");
|
||||
options.add("green");
|
||||
options.add("blue");
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
public String getSelect() {
|
||||
return select;
|
||||
}
|
||||
public String getSelect() {
|
||||
return select;
|
||||
}
|
||||
|
||||
public void setSelect(String select) {
|
||||
this.select = select;
|
||||
}
|
||||
public void setSelect(String select) {
|
||||
this.select = select;
|
||||
}
|
||||
|
||||
public List<String> getOptions() {
|
||||
return options;
|
||||
}
|
||||
public List<String> getOptions() {
|
||||
return options;
|
||||
}
|
||||
}
|
||||
|
||||
+34
-34
@@ -20,56 +20,56 @@
|
||||
*/
|
||||
package org.apache.struts2.showcase.ajax;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
|
||||
/**
|
||||
* @version $Date$ $Id$
|
||||
*/
|
||||
public class Example4ShowPanelAction extends ActionSupport {
|
||||
|
||||
private String name;
|
||||
private String gender;
|
||||
private String name;
|
||||
private String gender;
|
||||
|
||||
private static final long serialVersionUID = 7751976335066456596L;
|
||||
private static final long serialVersionUID = 7751976335066456596L;
|
||||
|
||||
public String panel1() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
public String panel1() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
public String panel2() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
public String panel2() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
public String panel3() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
public String panel3() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
public String getGender() {
|
||||
return gender;
|
||||
}
|
||||
public String getGender() {
|
||||
return gender;
|
||||
}
|
||||
|
||||
public void setGender(String gender) {
|
||||
this.gender = gender;
|
||||
}
|
||||
public void setGender(String gender) {
|
||||
this.gender = gender;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getTodayDate() {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("dd-MMMM-yyyy");
|
||||
return sdf.format(new Date());
|
||||
}
|
||||
public String getTodayDate() {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("dd-MMMM-yyyy");
|
||||
return sdf.format(new Date());
|
||||
}
|
||||
|
||||
public String getTodayTime() {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("kk:mm:ss");
|
||||
return sdf.format(new Date());
|
||||
}
|
||||
public String getTodayTime() {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("kk:mm:ss");
|
||||
return sdf.format(new Date());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,20 +24,28 @@ import com.opensymphony.xwork2.ActionSupport;
|
||||
|
||||
public class Example5Action extends ActionSupport {
|
||||
|
||||
private static final long serialVersionUID = 2111967621952300611L;
|
||||
private static final long serialVersionUID = 2111967621952300611L;
|
||||
|
||||
private String name;
|
||||
private Integer age;
|
||||
private String name;
|
||||
private Integer age;
|
||||
|
||||
public String execute() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
public String getName() { return name; }
|
||||
public void setName(String name) { this.name = name; }
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Integer getAge() { return age; }
|
||||
public void setAge(Integer age) { this.age = age; }
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String execute() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
public Integer getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public void setAge(Integer age) {
|
||||
this.age = age;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,77 +28,77 @@ import java.util.Map;
|
||||
/**
|
||||
*/
|
||||
public class Category {
|
||||
private static Map<Long, Category> catMap = new HashMap<Long, Category>();
|
||||
private static Map<Long, Category> catMap = new HashMap<Long, Category>();
|
||||
|
||||
static {
|
||||
new Category(1, "Root",
|
||||
new Category(2, "Java",
|
||||
new Category(3, "Web Frameworks",
|
||||
new Category(4, "Struts"),
|
||||
new Category(7, "Stripes"),
|
||||
new Category(8, "Rife")),
|
||||
new Category(9, "Persistence",
|
||||
new Category(10, "iBatis"),
|
||||
new Category(11, "Hibernate"),
|
||||
new Category(12, "JDO"),
|
||||
new Category(13, "JDBC"))),
|
||||
new Category(14, "JavaScript",
|
||||
new Category(15, "Dojo"),
|
||||
new Category(16, "Prototype"),
|
||||
new Category(17, "Scriptaculous"),
|
||||
new Category(18, "OpenRico"),
|
||||
new Category(19, "DWR")));
|
||||
}
|
||||
static {
|
||||
new Category(1, "Root",
|
||||
new Category(2, "Java",
|
||||
new Category(3, "Web Frameworks",
|
||||
new Category(4, "Struts"),
|
||||
new Category(7, "Stripes"),
|
||||
new Category(8, "Rife")),
|
||||
new Category(9, "Persistence",
|
||||
new Category(10, "iBatis"),
|
||||
new Category(11, "Hibernate"),
|
||||
new Category(12, "JDO"),
|
||||
new Category(13, "JDBC"))),
|
||||
new Category(14, "JavaScript",
|
||||
new Category(15, "Dojo"),
|
||||
new Category(16, "Prototype"),
|
||||
new Category(17, "Scriptaculous"),
|
||||
new Category(18, "OpenRico"),
|
||||
new Category(19, "DWR")));
|
||||
}
|
||||
|
||||
public static Category getById(long id) {
|
||||
return catMap.get(id);
|
||||
}
|
||||
public static Category getById(long id) {
|
||||
return catMap.get(id);
|
||||
}
|
||||
|
||||
private long id;
|
||||
private String name;
|
||||
private List<Category> children;
|
||||
private boolean toggle;
|
||||
private long id;
|
||||
private String name;
|
||||
private List<Category> children;
|
||||
private boolean toggle;
|
||||
|
||||
public Category(long id, String name, Category... children) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.children = new ArrayList<Category>();
|
||||
for (Category child : children) {
|
||||
this.children.add(child);
|
||||
}
|
||||
public Category(long id, String name, Category... children) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.children = new ArrayList<Category>();
|
||||
for (Category child : children) {
|
||||
this.children.add(child);
|
||||
}
|
||||
|
||||
catMap.put(id, this);
|
||||
}
|
||||
catMap.put(id, this);
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public List<Category> getChildren() {
|
||||
return children;
|
||||
}
|
||||
public List<Category> getChildren() {
|
||||
return children;
|
||||
}
|
||||
|
||||
public void setChildren(List<Category> children) {
|
||||
this.children = children;
|
||||
}
|
||||
public void setChildren(List<Category> children) {
|
||||
this.children = children;
|
||||
}
|
||||
|
||||
public void toggle() {
|
||||
toggle = !toggle;
|
||||
}
|
||||
public void toggle() {
|
||||
toggle = !toggle;
|
||||
}
|
||||
|
||||
public boolean isToggle() {
|
||||
return toggle;
|
||||
}
|
||||
public boolean isToggle() {
|
||||
return toggle;
|
||||
}
|
||||
}
|
||||
|
||||
+16
-16
@@ -25,25 +25,25 @@ import com.opensymphony.xwork2.ActionSupport;
|
||||
/**
|
||||
*/
|
||||
public class GetCategory extends ActionSupport {
|
||||
private long catId;
|
||||
private Category category;
|
||||
private long catId;
|
||||
private Category category;
|
||||
|
||||
public String execute() throws Exception {
|
||||
if (catId < 1) {
|
||||
// force the root
|
||||
catId = 1;
|
||||
}
|
||||
public String execute() throws Exception {
|
||||
if (catId < 1) {
|
||||
// force the root
|
||||
catId = 1;
|
||||
}
|
||||
|
||||
category = Category.getById(catId);
|
||||
category = Category.getById(catId);
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
public void setCatId(long catId) {
|
||||
this.catId = catId;
|
||||
}
|
||||
public void setCatId(long catId) {
|
||||
this.catId = catId;
|
||||
}
|
||||
|
||||
public Category getCategory() {
|
||||
return category;
|
||||
}
|
||||
public Category getCategory() {
|
||||
return category;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,11 +24,11 @@ package org.apache.struts2.showcase.ajax.tree;
|
||||
/**
|
||||
*/
|
||||
public class Toggle extends GetCategory {
|
||||
public String execute() throws Exception {
|
||||
super.execute();
|
||||
public String execute() throws Exception {
|
||||
super.execute();
|
||||
|
||||
getCategory().toggle();
|
||||
getCategory().toggle();
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
+96
-93
@@ -20,123 +20,126 @@
|
||||
*/
|
||||
package org.apache.struts2.showcase.application;
|
||||
|
||||
import org.apache.struts2.showcase.exception.CreateException;
|
||||
import org.apache.struts2.showcase.exception.DuplicateKeyException;
|
||||
import org.apache.struts2.showcase.exception.StorageException;
|
||||
import org.apache.struts2.showcase.exception.UpdateException;
|
||||
import org.apache.struts2.showcase.model.IdEntity;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.struts2.showcase.exception.CreateException;
|
||||
import org.apache.struts2.showcase.exception.DuplicateKeyException;
|
||||
import org.apache.struts2.showcase.exception.StorageException;
|
||||
import org.apache.struts2.showcase.exception.UpdateException;
|
||||
import org.apache.struts2.showcase.model.IdEntity;
|
||||
|
||||
/**
|
||||
* MemoryStorage.
|
||||
* Very simple in-memory persistence emulation.
|
||||
*
|
||||
*/
|
||||
|
||||
@Repository
|
||||
@Scope("singleton")
|
||||
public class MemoryStorage implements Storage {
|
||||
|
||||
private static final long serialVersionUID = 8611213748834904125L;
|
||||
private static final long serialVersionUID = 8611213748834904125L;
|
||||
|
||||
|
||||
private Map memory = new HashMap();
|
||||
private Map memory = new HashMap();
|
||||
|
||||
private Map getEntityMap ( Class entityClass ) {
|
||||
if (entityClass != null) {
|
||||
Map tryMap = (Map) memory.get(entityClass);
|
||||
if (tryMap == null) {
|
||||
synchronized(memory) {
|
||||
tryMap = new HashMap();
|
||||
memory.put(entityClass, tryMap);
|
||||
}
|
||||
}
|
||||
return tryMap;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
private Map getEntityMap(Class entityClass) {
|
||||
if (entityClass != null) {
|
||||
Map tryMap = (Map) memory.get(entityClass);
|
||||
if (tryMap == null) {
|
||||
synchronized (memory) {
|
||||
tryMap = new HashMap();
|
||||
memory.put(entityClass, tryMap);
|
||||
}
|
||||
}
|
||||
return tryMap;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private IdEntity intStore( Class entityClass, IdEntity object ) {
|
||||
getEntityMap(entityClass).put(object.getId(), object);
|
||||
return object;
|
||||
}
|
||||
private IdEntity intStore(Class entityClass, IdEntity object) {
|
||||
getEntityMap(entityClass).put(object.getId(), object);
|
||||
return object;
|
||||
}
|
||||
|
||||
public IdEntity get( Class entityClass, Serializable id ) {
|
||||
if (entityClass != null && id != null) {
|
||||
return (IdEntity) getEntityMap(entityClass).get(id);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public IdEntity get(Class entityClass, Serializable id) {
|
||||
if (entityClass != null && id != null) {
|
||||
return (IdEntity) getEntityMap(entityClass).get(id);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Serializable create ( IdEntity object ) throws CreateException {
|
||||
if (object == null) {
|
||||
throw new CreateException("Either given class or object was null");
|
||||
}
|
||||
if (object.getId() == null) {
|
||||
throw new CreateException("Cannot store object with null id");
|
||||
}
|
||||
if (get(object.getClass(), object.getId()) != null) {
|
||||
throw new DuplicateKeyException("Object with this id already exists.");
|
||||
}
|
||||
return intStore(object.getClass(), object).getId();
|
||||
}
|
||||
public Serializable create(IdEntity object) throws CreateException {
|
||||
if (object == null) {
|
||||
throw new CreateException("Either given class or object was null");
|
||||
}
|
||||
if (object.getId() == null) {
|
||||
throw new CreateException("Cannot store object with null id");
|
||||
}
|
||||
if (get(object.getClass(), object.getId()) != null) {
|
||||
throw new DuplicateKeyException("Object with this id already exists.");
|
||||
}
|
||||
return intStore(object.getClass(), object).getId();
|
||||
}
|
||||
|
||||
public IdEntity update ( IdEntity object ) throws UpdateException {
|
||||
if (object == null) {
|
||||
throw new UpdateException("Cannot update null object.");
|
||||
}
|
||||
if ( get(object.getClass(), object.getId())==null ) {
|
||||
throw new UpdateException("Object to update not found.");
|
||||
}
|
||||
return intStore(object.getClass(), object);
|
||||
}
|
||||
public IdEntity update(IdEntity object) throws UpdateException {
|
||||
if (object == null) {
|
||||
throw new UpdateException("Cannot update null object.");
|
||||
}
|
||||
if (get(object.getClass(), object.getId()) == null) {
|
||||
throw new UpdateException("Object to update not found.");
|
||||
}
|
||||
return intStore(object.getClass(), object);
|
||||
}
|
||||
|
||||
public Serializable merge ( IdEntity object ) throws StorageException {
|
||||
if (object == null) {
|
||||
throw new StorageException("Cannot merge null object");
|
||||
}
|
||||
if (object.getId() == null || get(object.getClass(), object.getId())==null) {
|
||||
return create(object);
|
||||
} else {
|
||||
return update(object).getId();
|
||||
}
|
||||
}
|
||||
public Serializable merge(IdEntity object) throws StorageException {
|
||||
if (object == null) {
|
||||
throw new StorageException("Cannot merge null object");
|
||||
}
|
||||
if (object.getId() == null || get(object.getClass(), object.getId()) == null) {
|
||||
return create(object);
|
||||
} else {
|
||||
return update(object).getId();
|
||||
}
|
||||
}
|
||||
|
||||
public int delete( Class entityClass, Serializable id ) throws CreateException {
|
||||
try {
|
||||
if (get(entityClass, id) != null) {
|
||||
getEntityMap(entityClass).remove(id);
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new CreateException(e);
|
||||
}
|
||||
}
|
||||
public int delete(Class entityClass, Serializable id) throws CreateException {
|
||||
try {
|
||||
if (get(entityClass, id) != null) {
|
||||
getEntityMap(entityClass).remove(id);
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new CreateException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public int delete( IdEntity object ) throws CreateException {
|
||||
if (object == null) {
|
||||
throw new CreateException("Cannot delete null object");
|
||||
}
|
||||
return delete(object.getClass(), object.getId());
|
||||
}
|
||||
public int delete(IdEntity object) throws CreateException {
|
||||
if (object == null) {
|
||||
throw new CreateException("Cannot delete null object");
|
||||
}
|
||||
return delete(object.getClass(), object.getId());
|
||||
}
|
||||
|
||||
public Collection findAll( Class entityClass ) {
|
||||
if (entityClass != null) {
|
||||
return getEntityMap(entityClass).values();
|
||||
} else {
|
||||
return new ArrayList();
|
||||
}
|
||||
}
|
||||
public Collection findAll(Class entityClass) {
|
||||
if (entityClass != null) {
|
||||
return getEntityMap(entityClass).values();
|
||||
} else {
|
||||
return new ArrayList();
|
||||
}
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
this.memory = new HashMap();
|
||||
}
|
||||
public void reset() {
|
||||
this.memory = new HashMap();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,31 +20,30 @@
|
||||
*/
|
||||
package org.apache.struts2.showcase.application;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.apache.struts2.showcase.exception.CreateException;
|
||||
import org.apache.struts2.showcase.exception.StorageException;
|
||||
import org.apache.struts2.showcase.exception.UpdateException;
|
||||
import org.apache.struts2.showcase.model.IdEntity;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Storage. Interface.
|
||||
*
|
||||
*/
|
||||
|
||||
public interface Storage extends Serializable {
|
||||
IdEntity get( Class entityClass, Serializable id );
|
||||
IdEntity get(Class entityClass, Serializable id);
|
||||
|
||||
Serializable create ( IdEntity object ) throws CreateException;
|
||||
Serializable create(IdEntity object) throws CreateException;
|
||||
|
||||
IdEntity update ( IdEntity object ) throws UpdateException;
|
||||
IdEntity update(IdEntity object) throws UpdateException;
|
||||
|
||||
Serializable merge ( IdEntity object ) throws StorageException;
|
||||
Serializable merge(IdEntity object) throws StorageException;
|
||||
|
||||
int delete( Class entityClass, Serializable id ) throws CreateException;
|
||||
int delete(Class entityClass, Serializable id) throws CreateException;
|
||||
|
||||
int delete( IdEntity object ) throws CreateException;
|
||||
int delete(IdEntity object) throws CreateException;
|
||||
|
||||
Collection findAll( Class entityClass );
|
||||
Collection findAll(Class entityClass);
|
||||
}
|
||||
|
||||
+66
-71
@@ -20,10 +20,6 @@
|
||||
*/
|
||||
package org.apache.struts2.showcase.application;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.struts2.showcase.dao.EmployeeDao;
|
||||
import org.apache.struts2.showcase.dao.SkillDao;
|
||||
@@ -31,88 +27,87 @@ import org.apache.struts2.showcase.exception.StorageException;
|
||||
import org.apache.struts2.showcase.model.Employee;
|
||||
import org.apache.struts2.showcase.model.Skill;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* TestDataProvider.
|
||||
*
|
||||
*/
|
||||
|
||||
@Service
|
||||
public class TestDataProvider implements Serializable, InitializingBean {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final Logger log = Logger.getLogger(TestDataProvider.class);
|
||||
|
||||
private static final Logger log = Logger.getLogger(TestDataProvider.class);
|
||||
public static final String[] POSITIONS = {
|
||||
"Developer",
|
||||
"System Architect",
|
||||
"Sales Manager",
|
||||
"CEO"
|
||||
};
|
||||
|
||||
public static final String[] POSITIONS = {
|
||||
"Developer",
|
||||
"System Architect",
|
||||
"Sales Manager",
|
||||
"CEO"
|
||||
};
|
||||
public static final String[] LEVELS = {
|
||||
"Junior",
|
||||
"Senior",
|
||||
"Master"
|
||||
};
|
||||
|
||||
public static final String[] LEVELS = {
|
||||
"Junior",
|
||||
"Senior",
|
||||
"Master"
|
||||
};
|
||||
private static final Skill[] TEST_SKILLS = {
|
||||
new Skill("WW-SEN", "Struts Senior Developer"),
|
||||
new Skill("WW-JUN", "Struts Junior Developer"),
|
||||
new Skill("SPRING-DEV", "Spring Developer")
|
||||
};
|
||||
|
||||
private static final Skill[] TEST_SKILLS = {
|
||||
new Skill("WW-SEN", "Struts Senior Developer"),
|
||||
new Skill("WW-JUN", "Struts Junior Developer"),
|
||||
new Skill("SPRING-DEV", "Spring Developer")
|
||||
};
|
||||
public static final Employee[] TEST_EMPLOYEES = {
|
||||
new Employee(new Long(1), "Alan", "Smithee", new Date(), new Float(2000f), true, POSITIONS[0],
|
||||
TEST_SKILLS[0], null, "alan", LEVELS[0], "Nice guy"),
|
||||
new Employee(new Long(2), "Robert", "Robson", new Date(), new Float(10000f), false, POSITIONS[1],
|
||||
TEST_SKILLS[1], Arrays.asList(TEST_SKILLS).subList(1, TEST_SKILLS.length), "rob", LEVELS[1], "Smart guy")
|
||||
};
|
||||
|
||||
public static final Employee[] TEST_EMPLOYEES = {
|
||||
new Employee(new Long(1), "Alan", "Smithee", new Date(), new Float(2000f), true, POSITIONS[0],
|
||||
TEST_SKILLS[0], null, "alan", LEVELS[0], "Nice guy"),
|
||||
new Employee(new Long(2), "Robert", "Robson", new Date(), new Float(10000f), false, POSITIONS[1],
|
||||
TEST_SKILLS[1], Arrays.asList(TEST_SKILLS).subList(1,TEST_SKILLS.length), "rob", LEVELS[1], "Smart guy")
|
||||
};
|
||||
@Autowired
|
||||
private SkillDao skillDao;
|
||||
|
||||
private SkillDao skillDao;
|
||||
private EmployeeDao employeeDao;
|
||||
@Autowired
|
||||
private EmployeeDao employeeDao;
|
||||
|
||||
public void setSkillDao(SkillDao skillDao) {
|
||||
this.skillDao = skillDao;
|
||||
}
|
||||
protected void addTestSkills() {
|
||||
try {
|
||||
for (int i = 0, j = TEST_SKILLS.length; i < j; i++) {
|
||||
skillDao.merge(TEST_SKILLS[i]);
|
||||
}
|
||||
if (log.isInfoEnabled()) {
|
||||
log.info("TestDataProvider - [addTestSkills]: Added test skill data.");
|
||||
}
|
||||
} catch (StorageException e) {
|
||||
log.error("TestDataProvider - [addTestSkills]: Exception catched: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void setEmployeeDao(EmployeeDao employeeDao) {
|
||||
this.employeeDao = employeeDao;
|
||||
}
|
||||
protected void addTestEmployees() {
|
||||
try {
|
||||
for (int i = 0, j = TEST_EMPLOYEES.length; i < j; i++) {
|
||||
employeeDao.merge(TEST_EMPLOYEES[i]);
|
||||
}
|
||||
if (log.isInfoEnabled()) {
|
||||
log.info("TestDataProvider - [addTestEmployees]: Added test employee data.");
|
||||
}
|
||||
} catch (StorageException e) {
|
||||
log.error("TestDataProvider - [addTestEmployees]: Exception catched: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
protected void addTestSkills() {
|
||||
try {
|
||||
for (int i = 0, j = TEST_SKILLS.length; i < j; i++) {
|
||||
skillDao.merge(TEST_SKILLS[i]);
|
||||
}
|
||||
if (log.isInfoEnabled()) {
|
||||
log.info("TestDataProvider - [addTestSkills]: Added test skill data.");
|
||||
}
|
||||
} catch (StorageException e) {
|
||||
log.error("TestDataProvider - [addTestSkills]: Exception catched: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
protected void addTestData() {
|
||||
addTestSkills();
|
||||
addTestEmployees();
|
||||
}
|
||||
|
||||
protected void addTestEmployees() {
|
||||
try {
|
||||
for (int i = 0, j = TEST_EMPLOYEES.length; i < j; i++) {
|
||||
employeeDao.merge(TEST_EMPLOYEES[i]);
|
||||
}
|
||||
if (log.isInfoEnabled()) {
|
||||
log.info("TestDataProvider - [addTestEmployees]: Added test employee data.");
|
||||
}
|
||||
} catch (StorageException e) {
|
||||
log.error("TestDataProvider - [addTestEmployees]: Exception catched: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
protected void addTestData() {
|
||||
addTestSkills();
|
||||
addTestEmployees();
|
||||
}
|
||||
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
addTestData();
|
||||
}
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
addTestData();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+17
-20
@@ -21,40 +21,37 @@
|
||||
package org.apache.struts2.showcase.chat;
|
||||
|
||||
|
||||
import org.apache.struts2.dispatcher.SessionMap;
|
||||
|
||||
import com.opensymphony.xwork2.Action;
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.ActionInvocation;
|
||||
import com.opensymphony.xwork2.interceptor.Interceptor;
|
||||
import com.opensymphony.xwork2.util.logging.Logger;
|
||||
import com.opensymphony.xwork2.util.logging.LoggerFactory;
|
||||
import org.apache.struts2.dispatcher.SessionMap;
|
||||
|
||||
public class ChatAuthenticationInterceptor implements Interceptor {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ChatAuthenticationInterceptor.class);
|
||||
public static final String USER_SESSION_KEY = "chatUserSessionKey";
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ChatAuthenticationInterceptor.class);
|
||||
public void destroy() {
|
||||
}
|
||||
|
||||
public static final String USER_SESSION_KEY = "chatUserSessionKey";
|
||||
public void init() {
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
}
|
||||
public String intercept(ActionInvocation invocation) throws Exception {
|
||||
|
||||
public void init() {
|
||||
}
|
||||
LOG.debug("Authenticating chat user");
|
||||
|
||||
public String intercept(ActionInvocation invocation) throws Exception {
|
||||
SessionMap session = (SessionMap) ActionContext.getContext().get(ActionContext.SESSION);
|
||||
User user = (User) session.get(USER_SESSION_KEY);
|
||||
|
||||
LOG.debug("Authenticating chat user");
|
||||
|
||||
SessionMap session = (SessionMap) ActionContext.getContext().get(ActionContext.SESSION);
|
||||
User user = (User) session.get(USER_SESSION_KEY);
|
||||
|
||||
if (user == null) {
|
||||
return Action.LOGIN;
|
||||
}
|
||||
return invocation.invoke();
|
||||
}
|
||||
if (user == null) {
|
||||
return Action.LOGIN;
|
||||
}
|
||||
return invocation.invoke();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,15 +22,15 @@ package org.apache.struts2.showcase.chat;
|
||||
|
||||
public class ChatException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public enum ErrorType {
|
||||
ROOM_ALREADY_EXISTS,
|
||||
USER_ALREADY_EXISTS,
|
||||
NO_SUCH_ROOM_EXISTS
|
||||
}
|
||||
public enum ErrorType {
|
||||
ROOM_ALREADY_EXISTS,
|
||||
USER_ALREADY_EXISTS,
|
||||
NO_SUCH_ROOM_EXISTS
|
||||
}
|
||||
|
||||
public ChatException(String description, ErrorType type) {
|
||||
super(description);
|
||||
}
|
||||
public ChatException(String description, ErrorType type) {
|
||||
super(description);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,8 +20,6 @@
|
||||
*/
|
||||
package org.apache.struts2.showcase.chat;
|
||||
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import com.opensymphony.xwork2.Action;
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.ActionInvocation;
|
||||
@@ -29,32 +27,34 @@ import com.opensymphony.xwork2.interceptor.Interceptor;
|
||||
import com.opensymphony.xwork2.util.logging.Logger;
|
||||
import com.opensymphony.xwork2.util.logging.LoggerFactory;
|
||||
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
/**
|
||||
* Authenticate showcase chat example, make sure everyone have a username.
|
||||
*/
|
||||
public class ChatInterceptor implements Interceptor {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ChatInterceptor.class);
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ChatInterceptor.class);
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static final String CHAT_USER_SESSION_KEY = "ChatUserSessionKey";
|
||||
public static final String CHAT_USER_SESSION_KEY = "ChatUserSessionKey";
|
||||
|
||||
public void destroy() {
|
||||
}
|
||||
public void destroy() {
|
||||
}
|
||||
|
||||
public void init() {
|
||||
}
|
||||
public void init() {
|
||||
}
|
||||
|
||||
public String intercept(ActionInvocation invocation) throws Exception {
|
||||
HttpSession session = (HttpSession) ActionContext.getContext().get(ActionContext.SESSION);
|
||||
User chatUser = (User) session.getAttribute(CHAT_USER_SESSION_KEY);
|
||||
if (chatUser == null) {
|
||||
LOG.debug("Chat user not logged in");
|
||||
return Action.LOGIN;
|
||||
}
|
||||
return invocation.invoke();
|
||||
}
|
||||
public String intercept(ActionInvocation invocation) throws Exception {
|
||||
HttpSession session = (HttpSession) ActionContext.getContext().get(ActionContext.SESSION);
|
||||
User chatUser = (User) session.getAttribute(CHAT_USER_SESSION_KEY);
|
||||
if (chatUser == null) {
|
||||
LOG.debug("Chat user not logged in");
|
||||
return Action.LOGIN;
|
||||
}
|
||||
return invocation.invoke();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -20,49 +20,48 @@
|
||||
*/
|
||||
package org.apache.struts2.showcase.chat;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
import org.apache.struts2.interceptor.SessionAware;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
import java.util.Map;
|
||||
|
||||
public class ChatLoginAction extends ActionSupport implements SessionAware {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private ChatService chatService;
|
||||
private Map session;
|
||||
private ChatService chatService;
|
||||
private Map session;
|
||||
|
||||
private String name;
|
||||
private String name;
|
||||
|
||||
public ChatLoginAction(ChatService chatService) {
|
||||
this.chatService = chatService;
|
||||
}
|
||||
public ChatLoginAction(ChatService chatService) {
|
||||
this.chatService = chatService;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
public String execute() throws Exception {
|
||||
try {
|
||||
chatService.login(new User(name));
|
||||
session.put(ChatAuthenticationInterceptor.USER_SESSION_KEY, new User(name));
|
||||
}
|
||||
catch(ChatException e) {
|
||||
e.printStackTrace();
|
||||
addActionError(e.getMessage());
|
||||
return INPUT;
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
public String execute() throws Exception {
|
||||
try {
|
||||
chatService.login(new User(name));
|
||||
session.put(ChatAuthenticationInterceptor.USER_SESSION_KEY, new User(name));
|
||||
} catch (ChatException e) {
|
||||
e.printStackTrace();
|
||||
addActionError(e.getMessage());
|
||||
return INPUT;
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
// === SessionAware ===
|
||||
public void setSession(Map session) {
|
||||
this.session = session;
|
||||
}
|
||||
// === SessionAware ===
|
||||
public void setSession(Map session) {
|
||||
this.session = session;
|
||||
}
|
||||
}
|
||||
|
||||
+20
-21
@@ -20,39 +20,38 @@
|
||||
*/
|
||||
package org.apache.struts2.showcase.chat;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
import org.apache.struts2.interceptor.SessionAware;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
import java.util.Map;
|
||||
|
||||
public class ChatLogoutAction extends ActionSupport implements SessionAware {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private ChatService chatService;
|
||||
private ChatService chatService;
|
||||
|
||||
private Map session;
|
||||
private Map session;
|
||||
|
||||
|
||||
public ChatLogoutAction(ChatService chatService) {
|
||||
this.chatService = chatService;
|
||||
}
|
||||
public ChatLogoutAction(ChatService chatService) {
|
||||
this.chatService = chatService;
|
||||
}
|
||||
|
||||
public String execute() throws Exception {
|
||||
public String execute() throws Exception {
|
||||
|
||||
User user = (User) session.get(ChatAuthenticationInterceptor.USER_SESSION_KEY);
|
||||
if (user != null) {
|
||||
chatService.logout(user.getName());
|
||||
session.remove(ChatAuthenticationInterceptor.USER_SESSION_KEY);
|
||||
}
|
||||
User user = (User) session.get(ChatAuthenticationInterceptor.USER_SESSION_KEY);
|
||||
if (user != null) {
|
||||
chatService.logout(user.getName());
|
||||
session.remove(ChatAuthenticationInterceptor.USER_SESSION_KEY);
|
||||
}
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
// === SessionAware ===
|
||||
public void setSession(Map session) {
|
||||
this.session = session;
|
||||
}
|
||||
// === SessionAware ===
|
||||
public void setSession(Map session) {
|
||||
this.session = session;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,26 +24,28 @@ import java.util.Date;
|
||||
|
||||
public class ChatMessage {
|
||||
|
||||
private Date creationDate;
|
||||
private String message;
|
||||
private User creator;
|
||||
private Date creationDate;
|
||||
private String message;
|
||||
private User creator;
|
||||
|
||||
public ChatMessage(String message, User creator) {
|
||||
assert(message != null);
|
||||
assert(creator != null);
|
||||
public ChatMessage(String message, User creator) {
|
||||
assert (message != null);
|
||||
assert (creator != null);
|
||||
|
||||
this.creationDate = new Date(System.currentTimeMillis());
|
||||
this.message = message;
|
||||
this.creator = creator;
|
||||
}
|
||||
this.creationDate = new Date(System.currentTimeMillis());
|
||||
this.message = message;
|
||||
this.creator = creator;
|
||||
}
|
||||
|
||||
public Date getCreationDate() {
|
||||
return creationDate;
|
||||
}
|
||||
public User getCreator() {
|
||||
return creator;
|
||||
}
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
public Date getCreationDate() {
|
||||
return creationDate;
|
||||
}
|
||||
|
||||
public User getCreator() {
|
||||
return creator;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,15 +23,23 @@ package org.apache.struts2.showcase.chat;
|
||||
import java.util.List;
|
||||
|
||||
public interface ChatService {
|
||||
List<User> getAvailableUsers();
|
||||
void login(User user);
|
||||
void logout(String name);
|
||||
List<User> getAvailableUsers();
|
||||
|
||||
List<Room> getAvailableRooms();
|
||||
void addRoom(Room room);
|
||||
void enterRoom(User user, String roomName);
|
||||
void exitRoom(String userName, String roomName);
|
||||
List<ChatMessage> getMessagesInRoom(String roomName);
|
||||
void sendMessageToRoom(String roomName, User user, String message);
|
||||
List<User> getUsersAvailableInRoom(String roomName);
|
||||
void login(User user);
|
||||
|
||||
void logout(String name);
|
||||
|
||||
List<Room> getAvailableRooms();
|
||||
|
||||
void addRoom(Room room);
|
||||
|
||||
void enterRoom(User user, String roomName);
|
||||
|
||||
void exitRoom(String userName, String roomName);
|
||||
|
||||
List<ChatMessage> getMessagesInRoom(String roomName);
|
||||
|
||||
void sendMessageToRoom(String roomName, User user, String message);
|
||||
|
||||
List<User> getUsersAvailableInRoom(String roomName);
|
||||
}
|
||||
|
||||
@@ -27,89 +27,89 @@ import java.util.Map;
|
||||
|
||||
public class ChatServiceImpl implements ChatService {
|
||||
|
||||
private Map<String, User> availableUsers = new LinkedHashMap<String, User>();
|
||||
private Map<String, Room> availableRooms = new LinkedHashMap<String, Room>();
|
||||
private Map<String, User> availableUsers = new LinkedHashMap<String, User>();
|
||||
private Map<String, Room> availableRooms = new LinkedHashMap<String, Room>();
|
||||
|
||||
|
||||
public List<User> getAvailableUsers() {
|
||||
return new ArrayList<User>(availableUsers.values());
|
||||
}
|
||||
public List<User> getAvailableUsers() {
|
||||
return new ArrayList<User>(availableUsers.values());
|
||||
}
|
||||
|
||||
public List<Room> getAvailableRooms() {
|
||||
return new ArrayList<Room>(availableRooms.values());
|
||||
}
|
||||
public List<Room> getAvailableRooms() {
|
||||
return new ArrayList<Room>(availableRooms.values());
|
||||
}
|
||||
|
||||
public void addRoom(Room room) {
|
||||
if (availableRooms.containsKey(room.getName())) {
|
||||
throw new ChatException("room ["+room.getName()+"] is already available", ChatException.ErrorType.valueOf("ROOM_ALREADY_EXISTS"));
|
||||
}
|
||||
availableRooms.put(room.getName(), room);
|
||||
}
|
||||
public void addRoom(Room room) {
|
||||
if (availableRooms.containsKey(room.getName())) {
|
||||
throw new ChatException("room [" + room.getName() + "] is already available", ChatException.ErrorType.valueOf("ROOM_ALREADY_EXISTS"));
|
||||
}
|
||||
availableRooms.put(room.getName(), room);
|
||||
}
|
||||
|
||||
public void login(User user) {
|
||||
assert(user != null);
|
||||
if (availableUsers.containsKey(user.getName())) {
|
||||
throw new ChatException("User ["+user.getName()+"] already exists", ChatException.ErrorType.valueOf("USER_ALREADY_EXISTS"));
|
||||
}
|
||||
availableUsers.put(user.getName(), user);
|
||||
}
|
||||
public void login(User user) {
|
||||
assert (user != null);
|
||||
if (availableUsers.containsKey(user.getName())) {
|
||||
throw new ChatException("User [" + user.getName() + "] already exists", ChatException.ErrorType.valueOf("USER_ALREADY_EXISTS"));
|
||||
}
|
||||
availableUsers.put(user.getName(), user);
|
||||
}
|
||||
|
||||
public void logout(String name) {
|
||||
assert(name != null);
|
||||
assert(name.trim().length() > 0);
|
||||
availableUsers.remove(name);
|
||||
for (Room room : availableRooms.values()) {
|
||||
if (room.hasMember(name)) {
|
||||
room.memberExit(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
public void logout(String name) {
|
||||
assert (name != null);
|
||||
assert (name.trim().length() > 0);
|
||||
availableUsers.remove(name);
|
||||
for (Room room : availableRooms.values()) {
|
||||
if (room.hasMember(name)) {
|
||||
room.memberExit(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void exitRoom(String userName, String roomName) {
|
||||
assert(roomName != null);
|
||||
assert(roomName.trim().length()> 0);
|
||||
public void exitRoom(String userName, String roomName) {
|
||||
assert (roomName != null);
|
||||
assert (roomName.trim().length() > 0);
|
||||
|
||||
if (availableRooms.containsKey(roomName)) {
|
||||
Room room = availableRooms.get(roomName);
|
||||
room.memberExit(userName);
|
||||
}
|
||||
}
|
||||
if (availableRooms.containsKey(roomName)) {
|
||||
Room room = availableRooms.get(roomName);
|
||||
room.memberExit(userName);
|
||||
}
|
||||
}
|
||||
|
||||
public void enterRoom(User user, String roomName) {
|
||||
assert(roomName != null);
|
||||
assert(roomName.trim().length() > 0);
|
||||
if (! availableRooms.containsKey(roomName)) {
|
||||
throw new ChatException("No such room exists ["+roomName+"]", ChatException.ErrorType.NO_SUCH_ROOM_EXISTS);
|
||||
}
|
||||
Room room = availableRooms.get(roomName);
|
||||
room.memberEnter(user);
|
||||
}
|
||||
public void enterRoom(User user, String roomName) {
|
||||
assert (roomName != null);
|
||||
assert (roomName.trim().length() > 0);
|
||||
if (!availableRooms.containsKey(roomName)) {
|
||||
throw new ChatException("No such room exists [" + roomName + "]", ChatException.ErrorType.NO_SUCH_ROOM_EXISTS);
|
||||
}
|
||||
Room room = availableRooms.get(roomName);
|
||||
room.memberEnter(user);
|
||||
}
|
||||
|
||||
public List<ChatMessage> getMessagesInRoom(String roomName) {
|
||||
assert(roomName != null);
|
||||
assert(roomName.trim().length() > 0);
|
||||
if (! availableRooms.containsKey(roomName)) {
|
||||
throw new ChatException("No such room exists ["+roomName+"]", ChatException.ErrorType.NO_SUCH_ROOM_EXISTS);
|
||||
}
|
||||
Room room = availableRooms.get(roomName);
|
||||
return room.getChatMessages();
|
||||
}
|
||||
public List<ChatMessage> getMessagesInRoom(String roomName) {
|
||||
assert (roomName != null);
|
||||
assert (roomName.trim().length() > 0);
|
||||
if (!availableRooms.containsKey(roomName)) {
|
||||
throw new ChatException("No such room exists [" + roomName + "]", ChatException.ErrorType.NO_SUCH_ROOM_EXISTS);
|
||||
}
|
||||
Room room = availableRooms.get(roomName);
|
||||
return room.getChatMessages();
|
||||
}
|
||||
|
||||
public void sendMessageToRoom(String roomName, User user, String message) {
|
||||
assert(roomName != null);
|
||||
if (! availableRooms.containsKey(roomName)) {
|
||||
throw new ChatException("No such room exists ["+roomName+"]", ChatException.ErrorType.NO_SUCH_ROOM_EXISTS);
|
||||
}
|
||||
Room room = availableRooms.get(roomName);
|
||||
room.addMessage(new ChatMessage(message, user));
|
||||
}
|
||||
public void sendMessageToRoom(String roomName, User user, String message) {
|
||||
assert (roomName != null);
|
||||
if (!availableRooms.containsKey(roomName)) {
|
||||
throw new ChatException("No such room exists [" + roomName + "]", ChatException.ErrorType.NO_SUCH_ROOM_EXISTS);
|
||||
}
|
||||
Room room = availableRooms.get(roomName);
|
||||
room.addMessage(new ChatMessage(message, user));
|
||||
}
|
||||
|
||||
public List<User> getUsersAvailableInRoom(String roomName) {
|
||||
assert(roomName != null);
|
||||
if (! availableRooms.containsKey(roomName)) {
|
||||
throw new ChatException("No such room exists ["+roomName+"]", ChatException.ErrorType.NO_SUCH_ROOM_EXISTS);
|
||||
}
|
||||
Room room = availableRooms.get(roomName);
|
||||
return room.getMembers();
|
||||
}
|
||||
public List<User> getUsersAvailableInRoom(String roomName) {
|
||||
assert (roomName != null);
|
||||
if (!availableRooms.containsKey(roomName)) {
|
||||
throw new ChatException("No such room exists [" + roomName + "]", ChatException.ErrorType.NO_SUCH_ROOM_EXISTS);
|
||||
}
|
||||
Room room = availableRooms.get(roomName);
|
||||
return room.getMembers();
|
||||
}
|
||||
}
|
||||
|
||||
+20
-21
@@ -20,35 +20,34 @@
|
||||
*/
|
||||
package org.apache.struts2.showcase.chat;
|
||||
|
||||
import com.opensymphony.xwork2.util.logging.Logger;
|
||||
import com.opensymphony.xwork2.util.logging.LoggerFactory;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
import org.springframework.web.context.support.WebApplicationContextUtils;
|
||||
|
||||
import javax.servlet.http.HttpSession;
|
||||
import javax.servlet.http.HttpSessionEvent;
|
||||
import javax.servlet.http.HttpSessionListener;
|
||||
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
import org.springframework.web.context.support.WebApplicationContextUtils;
|
||||
|
||||
import com.opensymphony.xwork2.util.logging.Logger;
|
||||
import com.opensymphony.xwork2.util.logging.LoggerFactory;
|
||||
|
||||
public class ChatSessionListener implements HttpSessionListener {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ChatSessionListener.class);
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ChatSessionListener.class);
|
||||
|
||||
public void sessionCreated(HttpSessionEvent event) {
|
||||
}
|
||||
public void sessionCreated(HttpSessionEvent event) {
|
||||
}
|
||||
|
||||
public void sessionDestroyed(HttpSessionEvent event) {
|
||||
HttpSession session = event.getSession();
|
||||
WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(session.getServletContext());
|
||||
if (context != null) {
|
||||
User user = (User) session.getAttribute(ChatInterceptor.CHAT_USER_SESSION_KEY);
|
||||
if (user != null) {
|
||||
ChatService service = (ChatService) context.getBean("chatService");
|
||||
service.logout(user.getName());
|
||||
public void sessionDestroyed(HttpSessionEvent event) {
|
||||
HttpSession session = event.getSession();
|
||||
WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(session.getServletContext());
|
||||
if (context != null) {
|
||||
User user = (User) session.getAttribute(ChatInterceptor.CHAT_USER_SESSION_KEY);
|
||||
if (user != null) {
|
||||
ChatService service = (ChatService) context.getBean("chatService");
|
||||
service.logout(user.getName());
|
||||
|
||||
LOG.info("session expired, logged user ["+user.getName()+"] out");
|
||||
}
|
||||
}
|
||||
}
|
||||
LOG.info("session expired, logged user [" + user.getName() + "] out");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,5 +21,5 @@
|
||||
package org.apache.struts2.showcase.chat;
|
||||
|
||||
public class Constants {
|
||||
public static String UPDATE_FREQ = "5000";
|
||||
public static String UPDATE_FREQ = "5000";
|
||||
}
|
||||
|
||||
@@ -24,41 +24,40 @@ import com.opensymphony.xwork2.ActionSupport;
|
||||
|
||||
public class CrudRoomAction extends ActionSupport {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private ChatService chatService;
|
||||
private ChatService chatService;
|
||||
|
||||
private String name;
|
||||
private String description;
|
||||
private String name;
|
||||
private String description;
|
||||
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public CrudRoomAction(ChatService chatService) {
|
||||
this.chatService = chatService;
|
||||
}
|
||||
public CrudRoomAction(ChatService chatService) {
|
||||
this.chatService = chatService;
|
||||
}
|
||||
|
||||
public String create() throws Exception {
|
||||
try {
|
||||
chatService.addRoom(new Room(name, description));
|
||||
}
|
||||
catch(ChatException e) {
|
||||
addActionError(e.getMessage());
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
public String create() throws Exception {
|
||||
try {
|
||||
chatService.addRoom(new Room(name, description));
|
||||
} catch (ChatException e) {
|
||||
addActionError(e.getMessage());
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,41 +20,39 @@
|
||||
*/
|
||||
package org.apache.struts2.showcase.chat;
|
||||
|
||||
import com.opensymphony.xwork2.util.logging.Logger;
|
||||
import com.opensymphony.xwork2.util.logging.LoggerFactory;
|
||||
import org.apache.struts2.util.StrutsTypeConverter;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.struts2.util.StrutsTypeConverter;
|
||||
|
||||
import com.opensymphony.xwork2.util.logging.Logger;
|
||||
import com.opensymphony.xwork2.util.logging.LoggerFactory;
|
||||
|
||||
public class DateConverter extends StrutsTypeConverter {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(DateConverter.class);
|
||||
private static final Logger LOG = LoggerFactory.getLogger(DateConverter.class);
|
||||
|
||||
public Object convertFromString(Map context, String[] values, Class toClass) {
|
||||
public Object convertFromString(Map context, String[] values, Class toClass) {
|
||||
|
||||
if (values.length > 0 && values[0] != null && values[0].trim().length() > 0) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat();
|
||||
try {
|
||||
return sdf.parse(values[0]);
|
||||
}
|
||||
catch(ParseException e) {
|
||||
LOG.error("error converting value ["+values[0]+"] to Date ", e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
if (values.length > 0 && values[0] != null && values[0].trim().length() > 0) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat();
|
||||
try {
|
||||
return sdf.parse(values[0]);
|
||||
} catch (ParseException e) {
|
||||
LOG.error("error converting value [" + values[0] + "] to Date ", e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String convertToString(Map context, Object o) {
|
||||
public String convertToString(Map context, Object o) {
|
||||
|
||||
if (o instanceof Date) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss");
|
||||
return sdf.format((Date) o);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
if (o instanceof Date) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss");
|
||||
return sdf.format((Date) o);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,43 +20,46 @@
|
||||
*/
|
||||
package org.apache.struts2.showcase.chat;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
import org.apache.struts2.interceptor.SessionAware;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
import java.util.Map;
|
||||
|
||||
public class EnterRoomAction extends ActionSupport implements SessionAware {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private ChatService chatService;
|
||||
private Map session;
|
||||
private String roomName;
|
||||
private ChatService chatService;
|
||||
private Map session;
|
||||
private String roomName;
|
||||
|
||||
public String getRoomName() { return this.roomName; }
|
||||
public void setRoomName(String roomName) { this.roomName = roomName; }
|
||||
public String getRoomName() {
|
||||
return this.roomName;
|
||||
}
|
||||
|
||||
public EnterRoomAction(ChatService chatService) {
|
||||
this.chatService = chatService;
|
||||
}
|
||||
public void setRoomName(String roomName) {
|
||||
this.roomName = roomName;
|
||||
}
|
||||
|
||||
public String execute() throws Exception {
|
||||
public EnterRoomAction(ChatService chatService) {
|
||||
this.chatService = chatService;
|
||||
}
|
||||
|
||||
User user = (User) session.get(ChatAuthenticationInterceptor.USER_SESSION_KEY);
|
||||
try {
|
||||
chatService.enterRoom(user, roomName);
|
||||
}
|
||||
catch(Exception e) {
|
||||
addActionError(e.getMessage());
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
public String execute() throws Exception {
|
||||
|
||||
User user = (User) session.get(ChatAuthenticationInterceptor.USER_SESSION_KEY);
|
||||
try {
|
||||
chatService.enterRoom(user, roomName);
|
||||
} catch (Exception e) {
|
||||
addActionError(e.getMessage());
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
// === SessionAware ===
|
||||
public void setSession(Map session) {
|
||||
this.session = session;
|
||||
}
|
||||
// === SessionAware ===
|
||||
public void setSession(Map session) {
|
||||
this.session = session;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,39 +20,43 @@
|
||||
*/
|
||||
package org.apache.struts2.showcase.chat;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
import org.apache.struts2.interceptor.SessionAware;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
import java.util.Map;
|
||||
|
||||
public class ExitRoomAction extends ActionSupport implements SessionAware {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String roomName;
|
||||
private String roomName;
|
||||
|
||||
private Map session;
|
||||
private Map session;
|
||||
|
||||
public String getRoomName() { return roomName; }
|
||||
public void setRoomName(String roomName) { this.roomName = roomName; }
|
||||
public String getRoomName() {
|
||||
return roomName;
|
||||
}
|
||||
|
||||
private ChatService chatService;
|
||||
public void setRoomName(String roomName) {
|
||||
this.roomName = roomName;
|
||||
}
|
||||
|
||||
public ExitRoomAction(ChatService chatService) {
|
||||
this.chatService = chatService;
|
||||
}
|
||||
private ChatService chatService;
|
||||
|
||||
public String execute() throws Exception {
|
||||
User user = (User) session.get(ChatAuthenticationInterceptor.USER_SESSION_KEY);
|
||||
chatService.exitRoom(user.getName(), roomName);
|
||||
public ExitRoomAction(ChatService chatService) {
|
||||
this.chatService = chatService;
|
||||
}
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
public String execute() throws Exception {
|
||||
User user = (User) session.get(ChatAuthenticationInterceptor.USER_SESSION_KEY);
|
||||
chatService.exitRoom(user.getName(), roomName);
|
||||
|
||||
// === SessionAware ===
|
||||
public void setSession(Map session) {
|
||||
this.session = session;
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
// === SessionAware ===
|
||||
public void setSession(Map session) {
|
||||
this.session = session;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+27
-25
@@ -20,40 +20,42 @@
|
||||
*/
|
||||
package org.apache.struts2.showcase.chat;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
|
||||
public class MessagesAvailableInRoomAction extends ActionSupport {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String roomName;
|
||||
private ChatService chatService;
|
||||
private List<ChatMessage> messagesAvailableInRoom = new ArrayList<ChatMessage>();
|
||||
private String roomName;
|
||||
private ChatService chatService;
|
||||
private List<ChatMessage> messagesAvailableInRoom = new ArrayList<ChatMessage>();
|
||||
|
||||
public String getRoomName() { return this.roomName; }
|
||||
public void setRoomName(String roomName) {
|
||||
this.roomName = roomName;
|
||||
}
|
||||
public String getRoomName() {
|
||||
return this.roomName;
|
||||
}
|
||||
|
||||
public List<ChatMessage> getMessagesAvailableInRoom() {
|
||||
return messagesAvailableInRoom;
|
||||
}
|
||||
public void setRoomName(String roomName) {
|
||||
this.roomName = roomName;
|
||||
}
|
||||
|
||||
public MessagesAvailableInRoomAction(ChatService chatService) {
|
||||
this.chatService = chatService;
|
||||
}
|
||||
public List<ChatMessage> getMessagesAvailableInRoom() {
|
||||
return messagesAvailableInRoom;
|
||||
}
|
||||
|
||||
public String execute() throws Exception {
|
||||
try {
|
||||
messagesAvailableInRoom = chatService.getMessagesInRoom(roomName);
|
||||
}
|
||||
catch(ChatException e) {
|
||||
addActionError(e.getMessage());
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
public MessagesAvailableInRoomAction(ChatService chatService) {
|
||||
this.chatService = chatService;
|
||||
}
|
||||
|
||||
public String execute() throws Exception {
|
||||
try {
|
||||
messagesAvailableInRoom = chatService.getMessagesInRoom(roomName);
|
||||
} catch (ChatException e) {
|
||||
addActionError(e.getMessage());
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,82 +20,81 @@
|
||||
*/
|
||||
package org.apache.struts2.showcase.chat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
public class Room {
|
||||
|
||||
private static final int MAX_CHAT_MESSAGES = 10;
|
||||
private static final int MAX_CHAT_MESSAGES = 10;
|
||||
|
||||
private String name;
|
||||
private String description;
|
||||
private Date creationDate;
|
||||
private String name;
|
||||
private String description;
|
||||
private Date creationDate;
|
||||
|
||||
private List<ChatMessage> messages = new ArrayList<ChatMessage>();
|
||||
private List<ChatMessage> messages = new ArrayList<ChatMessage>();
|
||||
|
||||
private Map<String, User> members = new LinkedHashMap<String, User>();
|
||||
private Map<String, User> members = new LinkedHashMap<String, User>();
|
||||
|
||||
public Room(String name, String description) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.creationDate = new Date(System.currentTimeMillis());
|
||||
}
|
||||
public Room(String name, String description) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.creationDate = new Date(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
|
||||
// properties
|
||||
public Date getCreationDate() {
|
||||
return creationDate;
|
||||
}
|
||||
// properties
|
||||
public Date getCreationDate() {
|
||||
return creationDate;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
// (behaviour) members
|
||||
public List<User> getMembers() {
|
||||
return new ArrayList<User>(members.values());
|
||||
}
|
||||
public User findMember(String name) {
|
||||
assert(name != null);
|
||||
return members.get(name);
|
||||
}
|
||||
public boolean hasMember(String name) {
|
||||
assert(name != null);
|
||||
return members.containsKey(name);
|
||||
}
|
||||
public void memberEnter(User member) {
|
||||
assert(member != null);
|
||||
if (! hasMember(member.getName())) {
|
||||
members.put(member.getName(), member);
|
||||
}
|
||||
}
|
||||
// (behaviour) members
|
||||
public List<User> getMembers() {
|
||||
return new ArrayList<User>(members.values());
|
||||
}
|
||||
|
||||
public void memberExit(String memberName) {
|
||||
assert(memberName != null);
|
||||
assert(memberName.trim().length() > 0);
|
||||
members.remove(memberName);
|
||||
}
|
||||
public User findMember(String name) {
|
||||
assert (name != null);
|
||||
return members.get(name);
|
||||
}
|
||||
|
||||
public boolean hasMember(String name) {
|
||||
assert (name != null);
|
||||
return members.containsKey(name);
|
||||
}
|
||||
|
||||
public void memberEnter(User member) {
|
||||
assert (member != null);
|
||||
if (!hasMember(member.getName())) {
|
||||
members.put(member.getName(), member);
|
||||
}
|
||||
}
|
||||
|
||||
public void memberExit(String memberName) {
|
||||
assert (memberName != null);
|
||||
assert (memberName.trim().length() > 0);
|
||||
members.remove(memberName);
|
||||
}
|
||||
|
||||
|
||||
// (behaviour) chat messags
|
||||
public void addMessage(ChatMessage chatMessage) {
|
||||
if (messages.size() > MAX_CHAT_MESSAGES) {
|
||||
// messages.remove(messages.size() - 1);
|
||||
messages.remove(0);
|
||||
}
|
||||
messages.add(chatMessage);
|
||||
}
|
||||
// (behaviour) chat messags
|
||||
public void addMessage(ChatMessage chatMessage) {
|
||||
if (messages.size() > MAX_CHAT_MESSAGES) {
|
||||
// messages.remove(messages.size() - 1);
|
||||
messages.remove(0);
|
||||
}
|
||||
messages.add(chatMessage);
|
||||
}
|
||||
|
||||
public List<ChatMessage> getChatMessages() {
|
||||
return new ArrayList<ChatMessage>(messages);
|
||||
}
|
||||
public List<ChatMessage> getChatMessages() {
|
||||
return new ArrayList<ChatMessage>(messages);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+15
-15
@@ -20,29 +20,29 @@
|
||||
*/
|
||||
package org.apache.struts2.showcase.chat;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
|
||||
public class RoomsAvailableAction extends ActionSupport {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private List<Room> availableRooms = new ArrayList<Room>();
|
||||
private List<Room> availableRooms = new ArrayList<Room>();
|
||||
|
||||
private ChatService chatService;
|
||||
private ChatService chatService;
|
||||
|
||||
public RoomsAvailableAction(ChatService chatService) {
|
||||
this.chatService = chatService;
|
||||
}
|
||||
public RoomsAvailableAction(ChatService chatService) {
|
||||
this.chatService = chatService;
|
||||
}
|
||||
|
||||
public String execute() throws Exception {
|
||||
availableRooms = chatService.getAvailableRooms();
|
||||
return SUCCESS;
|
||||
}
|
||||
public String execute() throws Exception {
|
||||
availableRooms = chatService.getAvailableRooms();
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
public List<Room> getAvailableRooms() {
|
||||
return availableRooms;
|
||||
}
|
||||
public List<Room> getAvailableRooms() {
|
||||
return availableRooms;
|
||||
}
|
||||
}
|
||||
|
||||
+36
-31
@@ -20,51 +20,56 @@
|
||||
*/
|
||||
package org.apache.struts2.showcase.chat;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
import org.apache.struts2.interceptor.SessionAware;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
import java.util.Map;
|
||||
|
||||
public class SendMessageToRoomAction extends ActionSupport implements SessionAware {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private ChatService chatService;
|
||||
private ChatService chatService;
|
||||
|
||||
private String roomName;
|
||||
private String message;
|
||||
private Map session;
|
||||
private String roomName;
|
||||
private String message;
|
||||
private Map session;
|
||||
|
||||
|
||||
public SendMessageToRoomAction(ChatService chatService) {
|
||||
this.chatService = chatService;
|
||||
}
|
||||
public SendMessageToRoomAction(ChatService chatService) {
|
||||
this.chatService = chatService;
|
||||
}
|
||||
|
||||
public String getRoomName() { return this.roomName; }
|
||||
public void setRoomName(String roomName) {
|
||||
this.roomName = roomName;
|
||||
}
|
||||
public String getRoomName() {
|
||||
return this.roomName;
|
||||
}
|
||||
|
||||
public String getMessage() { return this.message; }
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
public void setRoomName(String roomName) {
|
||||
this.roomName = roomName;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return this.message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
|
||||
public String execute() throws Exception {
|
||||
User user = (User) session.get(ChatAuthenticationInterceptor.USER_SESSION_KEY);
|
||||
try {
|
||||
chatService.sendMessageToRoom(roomName, user, message);
|
||||
}catch(ChatException e) {
|
||||
addActionError(e.getMessage());
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
public String execute() throws Exception {
|
||||
User user = (User) session.get(ChatAuthenticationInterceptor.USER_SESSION_KEY);
|
||||
try {
|
||||
chatService.sendMessageToRoom(roomName, user, message);
|
||||
} catch (ChatException e) {
|
||||
addActionError(e.getMessage());
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
public void setSession(Map session) {
|
||||
this.session = session;
|
||||
}
|
||||
public void setSession(Map session) {
|
||||
this.session = session;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -26,23 +26,24 @@ import java.util.Date;
|
||||
/**
|
||||
* Represends a user in the Chat example.
|
||||
*/
|
||||
public class User implements Serializable {
|
||||
public class User implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -1434958919516089297L;
|
||||
private static final long serialVersionUID = -1434958919516089297L;
|
||||
|
||||
private String name;
|
||||
private Date creationDate;
|
||||
private String name;
|
||||
private Date creationDate;
|
||||
|
||||
|
||||
public User(String name) {
|
||||
this.name = name;
|
||||
this.creationDate = new Date(System.currentTimeMillis());
|
||||
}
|
||||
public User(String name) {
|
||||
this.name = name;
|
||||
this.creationDate = new Date(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public Date getCreationDate() {
|
||||
return creationDate;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public Date getCreationDate() {
|
||||
return creationDate;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
+15
-15
@@ -20,30 +20,30 @@
|
||||
*/
|
||||
package org.apache.struts2.showcase.chat;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
|
||||
public class UsersAvailableAction extends ActionSupport {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private List<User> availableUsers = new ArrayList<User>();
|
||||
private ChatService chatService;
|
||||
private List<User> availableUsers = new ArrayList<User>();
|
||||
private ChatService chatService;
|
||||
|
||||
public UsersAvailableAction(ChatService chatService) {
|
||||
this.chatService = chatService;
|
||||
}
|
||||
public UsersAvailableAction(ChatService chatService) {
|
||||
this.chatService = chatService;
|
||||
}
|
||||
|
||||
public String execute() throws Exception {
|
||||
public String execute() throws Exception {
|
||||
|
||||
availableUsers = chatService.getAvailableUsers();
|
||||
availableUsers = chatService.getAvailableUsers();
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
public List<User> getAvailableUsers() {
|
||||
return availableUsers;
|
||||
}
|
||||
public List<User> getAvailableUsers() {
|
||||
return availableUsers;
|
||||
}
|
||||
}
|
||||
|
||||
+27
-25
@@ -20,42 +20,44 @@
|
||||
*/
|
||||
package org.apache.struts2.showcase.chat;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
|
||||
public class UsersAvailableInRoomAction extends ActionSupport {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private ChatService chatService;
|
||||
private List<User> usersAvailableInRoom = new ArrayList<User>();
|
||||
private ChatService chatService;
|
||||
private List<User> usersAvailableInRoom = new ArrayList<User>();
|
||||
|
||||
private String roomName;
|
||||
private String roomName;
|
||||
|
||||
public UsersAvailableInRoomAction(ChatService chatService) {
|
||||
this.chatService = chatService;
|
||||
}
|
||||
public UsersAvailableInRoomAction(ChatService chatService) {
|
||||
this.chatService = chatService;
|
||||
}
|
||||
|
||||
|
||||
public String getRoomName() { return this.roomName; }
|
||||
public void setRoomName(String roomName) {
|
||||
this.roomName = roomName;
|
||||
}
|
||||
public String getRoomName() {
|
||||
return this.roomName;
|
||||
}
|
||||
|
||||
public List<User> getUsersAvailableInRoom() {
|
||||
return usersAvailableInRoom;
|
||||
}
|
||||
public void setRoomName(String roomName) {
|
||||
this.roomName = roomName;
|
||||
}
|
||||
|
||||
public String execute() throws Exception {
|
||||
try {
|
||||
usersAvailableInRoom = chatService.getUsersAvailableInRoom(roomName);
|
||||
}
|
||||
catch(ChatException e) {
|
||||
addActionError(e.getMessage());
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
public List<User> getUsersAvailableInRoom() {
|
||||
return usersAvailableInRoom;
|
||||
}
|
||||
|
||||
public String execute() throws Exception {
|
||||
try {
|
||||
usersAvailableInRoom = chatService.getUsersAvailableInRoom(roomName);
|
||||
} catch (ChatException e) {
|
||||
addActionError(e.getMessage());
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,13 +26,23 @@ package org.apache.struts2.showcase.conversion;
|
||||
*/
|
||||
public class Address {
|
||||
|
||||
private String id;
|
||||
private String address;
|
||||
private String id;
|
||||
private String address;
|
||||
|
||||
public String getId() { return id; }
|
||||
public void setId(String id) { this.id = id; }
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getAddress() { return address; }
|
||||
public void setAddress(String address) { this.address = address; }
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+16
-12
@@ -20,28 +20,32 @@
|
||||
*/
|
||||
package org.apache.struts2.showcase.conversion;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
|
||||
/**
|
||||
* @version $Date$ $Id$
|
||||
*/
|
||||
public class AddressAction extends ActionSupport {
|
||||
|
||||
private Set addresses = new LinkedHashSet();
|
||||
private Set<Address> addresses = new LinkedHashSet<Address>();
|
||||
|
||||
public Set getAddresses() { return addresses; }
|
||||
public void setAddresses(Set addresses) { this.addresses = addresses; }
|
||||
public String input() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
public String submit() throws Exception {
|
||||
System.out.println(addresses);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
public String input() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
public Set<Address> getAddresses() {
|
||||
return addresses;
|
||||
}
|
||||
|
||||
public String submit() throws Exception {
|
||||
System.out.println(addresses);
|
||||
return SUCCESS;
|
||||
}
|
||||
public void setAddresses(Set<Address> addresses) {
|
||||
this.addresses = addresses;
|
||||
}
|
||||
}
|
||||
|
||||
+22
-22
@@ -20,39 +20,39 @@
|
||||
*/
|
||||
package org.apache.struts2.showcase.conversion;
|
||||
|
||||
import org.apache.struts2.util.StrutsTypeConverter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.struts2.util.StrutsTypeConverter;
|
||||
|
||||
/**
|
||||
* @version $Date$ $Id$
|
||||
*/
|
||||
public class EnumTypeConverter extends StrutsTypeConverter {
|
||||
|
||||
@Override
|
||||
public Object convertFromString(Map context, String[] values, Class toClass) {
|
||||
List<Enum> result = new ArrayList<Enum>();
|
||||
for (int a=0; a< values.length; a++) {
|
||||
Enum e = Enum.valueOf(OperationsEnum.class, values[a]);
|
||||
if (e != null)
|
||||
result.add(e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public Object convertFromString(Map context, String[] values, Class toClass) {
|
||||
List<Enum> result = new ArrayList<Enum>();
|
||||
for (int a = 0; a < values.length; a++) {
|
||||
Enum e = Enum.valueOf(OperationsEnum.class, values[a]);
|
||||
if (e != null)
|
||||
result.add(e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertToString(Map context, Object o) {
|
||||
List l = (List) o;
|
||||
String result ="<";
|
||||
for (Iterator i = l.iterator(); i.hasNext(); ) {
|
||||
result = result + "["+ i.next() +"]";
|
||||
}
|
||||
result = result+">";
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public String convertToString(Map context, Object o) {
|
||||
List l = (List) o;
|
||||
String result = "<";
|
||||
for (Iterator i = l.iterator(); i.hasNext(); ) {
|
||||
result = result + "[" + i.next() + "]";
|
||||
}
|
||||
result = result + ">";
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
+5
-6
@@ -21,13 +21,12 @@
|
||||
package org.apache.struts2.showcase.conversion;
|
||||
|
||||
/**
|
||||
*
|
||||
* @version $Date$ $Id$
|
||||
*/
|
||||
public enum OperationsEnum {
|
||||
ADD,
|
||||
MINUS,
|
||||
DIVIDE,
|
||||
MULTIPLY,
|
||||
REMAINDER;
|
||||
ADD,
|
||||
MINUS,
|
||||
DIVIDE,
|
||||
MULTIPLY,
|
||||
REMAINDER;
|
||||
}
|
||||
|
||||
+22
-19
@@ -20,37 +20,40 @@
|
||||
*/
|
||||
package org.apache.struts2.showcase.conversion;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
|
||||
/**
|
||||
*
|
||||
* @version $Date$ $Id$
|
||||
*/
|
||||
public class OperationsEnumAction extends ActionSupport {
|
||||
|
||||
private static final long serialVersionUID = -2229489704988870318L;
|
||||
private static final long serialVersionUID = -2229489704988870318L;
|
||||
|
||||
private List<OperationsEnum> selectedOperations = new LinkedList<OperationsEnum>();
|
||||
private List<OperationsEnum> selectedOperations = new LinkedList<OperationsEnum>();
|
||||
|
||||
public List<OperationsEnum> getSelectedOperations() { return this.selectedOperations; }
|
||||
public void setSelectedOperations(List<OperationsEnum> selectedOperations) {
|
||||
this.selectedOperations = selectedOperations;
|
||||
}
|
||||
public String input() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
public String submit() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
public List<OperationsEnum> getSelectedOperations() {
|
||||
return this.selectedOperations;
|
||||
}
|
||||
|
||||
public void setSelectedOperations(List<OperationsEnum> selectedOperations) {
|
||||
this.selectedOperations = selectedOperations;
|
||||
}
|
||||
|
||||
|
||||
public List<OperationsEnum> getAvailableOperations() {
|
||||
return Arrays.asList(OperationsEnum.values());
|
||||
}
|
||||
|
||||
public String input() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
public String submit() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
public List<OperationsEnum> getAvailableOperations() {
|
||||
return Arrays.asList(OperationsEnum.values());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,16 +22,23 @@ package org.apache.struts2.showcase.conversion;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class Person implements Serializable {
|
||||
private String name;
|
||||
private Integer age;
|
||||
private String name;
|
||||
private Integer age;
|
||||
|
||||
public void setName(String name) { this.name = name; }
|
||||
public String getName() { return this.name; }
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setAge(Integer age) { this.age = age; }
|
||||
public Integer getAge() { return this.age; }
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setAge(Integer age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public Integer getAge() {
|
||||
return this.age;
|
||||
}
|
||||
}
|
||||
|
||||
+15
-14
@@ -20,27 +20,28 @@
|
||||
*/
|
||||
package org.apache.struts2.showcase.conversion;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
import java.util.List;
|
||||
|
||||
public class PersonAction extends ActionSupport {
|
||||
|
||||
private List persons;
|
||||
private List<Person> persons;
|
||||
|
||||
public List getPersons() { return persons; }
|
||||
public void setPersons(List persons) { this.persons = persons; }
|
||||
public String input() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
public String submit() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
public List<Person> getPersons() {
|
||||
return persons;
|
||||
}
|
||||
|
||||
public String input() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
public void setPersons(List<Person> persons) {
|
||||
this.persons = persons;
|
||||
}
|
||||
|
||||
public String submit() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,58 +20,59 @@
|
||||
*/
|
||||
package org.apache.struts2.showcase.dao;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.apache.struts2.showcase.application.Storage;
|
||||
import org.apache.struts2.showcase.exception.CreateException;
|
||||
import org.apache.struts2.showcase.exception.StorageException;
|
||||
import org.apache.struts2.showcase.exception.UpdateException;
|
||||
import org.apache.struts2.showcase.model.IdEntity;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* AbstractDao.
|
||||
*
|
||||
*/
|
||||
|
||||
public abstract class AbstractDao implements Serializable, Dao {
|
||||
|
||||
private Storage storage;
|
||||
@Autowired
|
||||
private Storage storage;
|
||||
|
||||
public Storage getStorage() {
|
||||
return storage;
|
||||
}
|
||||
public Storage getStorage() {
|
||||
return storage;
|
||||
}
|
||||
|
||||
public void setStorage(Storage storage) {
|
||||
this.storage = storage;
|
||||
}
|
||||
public void setStorage(Storage storage) {
|
||||
this.storage = storage;
|
||||
}
|
||||
|
||||
public IdEntity get(Serializable id) {
|
||||
return getStorage().get(getFeaturedClass(), id);
|
||||
}
|
||||
public IdEntity get(Serializable id) {
|
||||
return getStorage().get(getFeaturedClass(), id);
|
||||
}
|
||||
|
||||
public Serializable create(IdEntity object) throws CreateException {
|
||||
return getStorage().create(object);
|
||||
}
|
||||
public Serializable create(IdEntity object) throws CreateException {
|
||||
return getStorage().create(object);
|
||||
}
|
||||
|
||||
public IdEntity update(IdEntity object) throws UpdateException {
|
||||
return getStorage().update(object);
|
||||
}
|
||||
public IdEntity update(IdEntity object) throws UpdateException {
|
||||
return getStorage().update(object);
|
||||
}
|
||||
|
||||
public Serializable merge(IdEntity object) throws StorageException {
|
||||
return getStorage().merge(object);
|
||||
}
|
||||
public Serializable merge(IdEntity object) throws StorageException {
|
||||
return getStorage().merge(object);
|
||||
}
|
||||
|
||||
public int delete(Serializable id) throws CreateException {
|
||||
return getStorage().delete(getFeaturedClass(), id);
|
||||
}
|
||||
public int delete(Serializable id) throws CreateException {
|
||||
return getStorage().delete(getFeaturedClass(), id);
|
||||
}
|
||||
|
||||
public int delete(IdEntity object) throws CreateException {
|
||||
return getStorage().delete(object);
|
||||
}
|
||||
public int delete(IdEntity object) throws CreateException {
|
||||
return getStorage().delete(object);
|
||||
}
|
||||
|
||||
public Collection findAll() {
|
||||
return getStorage().findAll(getFeaturedClass());
|
||||
}
|
||||
public Collection findAll() {
|
||||
return getStorage().findAll(getFeaturedClass());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,34 +20,33 @@
|
||||
*/
|
||||
package org.apache.struts2.showcase.dao;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.apache.struts2.showcase.exception.CreateException;
|
||||
import org.apache.struts2.showcase.exception.StorageException;
|
||||
import org.apache.struts2.showcase.exception.UpdateException;
|
||||
import org.apache.struts2.showcase.model.IdEntity;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Dao. Interface.
|
||||
*
|
||||
*/
|
||||
|
||||
public interface Dao {
|
||||
|
||||
Class getFeaturedClass();
|
||||
Class getFeaturedClass();
|
||||
|
||||
IdEntity get(Serializable id);
|
||||
IdEntity get(Serializable id);
|
||||
|
||||
Serializable create(IdEntity object) throws CreateException;
|
||||
Serializable create(IdEntity object) throws CreateException;
|
||||
|
||||
IdEntity update(IdEntity object) throws UpdateException;
|
||||
IdEntity update(IdEntity object) throws UpdateException;
|
||||
|
||||
Serializable merge(IdEntity object) throws StorageException;
|
||||
Serializable merge(IdEntity object) throws StorageException;
|
||||
|
||||
int delete(Serializable id) throws CreateException;
|
||||
int delete(Serializable id) throws CreateException;
|
||||
|
||||
int delete(IdEntity object) throws CreateException;
|
||||
int delete(IdEntity object) throws CreateException;
|
||||
|
||||
Collection findAll();
|
||||
Collection findAll();
|
||||
}
|
||||
|
||||
@@ -20,48 +20,50 @@
|
||||
*/
|
||||
package org.apache.struts2.showcase.dao;
|
||||
|
||||
import org.apache.struts2.showcase.model.Employee;
|
||||
import org.apache.struts2.showcase.model.Skill;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.struts2.showcase.model.Employee;
|
||||
import org.apache.struts2.showcase.model.Skill;
|
||||
|
||||
/**
|
||||
* EmployeeDao.
|
||||
*
|
||||
*/
|
||||
|
||||
@Repository
|
||||
public class EmployeeDao extends AbstractDao {
|
||||
|
||||
private static final long serialVersionUID = -6615310540042830594L;
|
||||
private static final long serialVersionUID = -6615310540042830594L;
|
||||
|
||||
protected SkillDao skillDao;
|
||||
@Autowired
|
||||
protected SkillDao skillDao;
|
||||
|
||||
public void setSkillDao(SkillDao skillDao) {
|
||||
this.skillDao = skillDao;
|
||||
}
|
||||
public void setSkillDao(SkillDao skillDao) {
|
||||
this.skillDao = skillDao;
|
||||
}
|
||||
|
||||
public Class getFeaturedClass() {
|
||||
return Employee.class;
|
||||
}
|
||||
public Class getFeaturedClass() {
|
||||
return Employee.class;
|
||||
}
|
||||
|
||||
public Employee getEmployee( Long id ) {
|
||||
return (Employee) get(id);
|
||||
}
|
||||
public Employee getEmployee(Long id) {
|
||||
return (Employee) get(id);
|
||||
}
|
||||
|
||||
public Employee setSkills(Employee employee, List skillNames) {
|
||||
if (employee!= null && skillNames != null) {
|
||||
employee.setOtherSkills(new ArrayList());
|
||||
for (int i = 0, j = skillNames.size(); i < j; i++) {
|
||||
Skill skill = (Skill) skillDao.get((String) skillNames.get(i));
|
||||
employee.getOtherSkills().add(skill);
|
||||
}
|
||||
}
|
||||
return employee;
|
||||
}
|
||||
public Employee setSkills(Employee employee, List<String> skillNames) {
|
||||
if (employee != null && skillNames != null) {
|
||||
employee.setOtherSkills(new ArrayList());
|
||||
for (int i = 0, j = skillNames.size(); i < j; i++) {
|
||||
Skill skill = (Skill) skillDao.get(skillNames.get(i));
|
||||
employee.getOtherSkills().add(skill);
|
||||
}
|
||||
}
|
||||
return employee;
|
||||
}
|
||||
|
||||
public Employee setSkills(Long empId, List skillNames) {
|
||||
return setSkills((Employee) get(empId), skillNames);
|
||||
}
|
||||
public Employee setSkills(Long empId, List skillNames) {
|
||||
return setSkills((Employee) get(empId), skillNames);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,21 +21,22 @@
|
||||
package org.apache.struts2.showcase.dao;
|
||||
|
||||
import org.apache.struts2.showcase.model.Skill;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* SkillDao.
|
||||
*
|
||||
*/
|
||||
|
||||
@Repository
|
||||
public class SkillDao extends AbstractDao {
|
||||
|
||||
private static final long serialVersionUID = -8160406514074630866L;
|
||||
private static final long serialVersionUID = -8160406514074630866L;
|
||||
|
||||
public Class getFeaturedClass() {
|
||||
return Skill.class;
|
||||
}
|
||||
public Class getFeaturedClass() {
|
||||
return Skill.class;
|
||||
}
|
||||
|
||||
public Skill getSkill( String name ) {
|
||||
return (Skill) get(name);
|
||||
}
|
||||
public Skill getSkill(String name) {
|
||||
return (Skill) get(name);
|
||||
}
|
||||
}
|
||||
|
||||
+10
-11
@@ -22,22 +22,21 @@ package org.apache.struts2.showcase.exception;
|
||||
|
||||
/**
|
||||
* CreateException.
|
||||
*
|
||||
*/
|
||||
|
||||
public class CreateException extends StorageException {
|
||||
|
||||
private static final long serialVersionUID = 6734349565111633783L;
|
||||
private static final long serialVersionUID = 6734349565111633783L;
|
||||
|
||||
public CreateException(String message) {
|
||||
super(message);
|
||||
}
|
||||
public CreateException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public CreateException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
public CreateException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public CreateException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
public CreateException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
|
||||
+10
-11
@@ -22,23 +22,22 @@ package org.apache.struts2.showcase.exception;
|
||||
|
||||
/**
|
||||
* DeleteException.
|
||||
*
|
||||
*/
|
||||
|
||||
public class DeleteException extends StorageException {
|
||||
|
||||
private static final long serialVersionUID = -5286362812955627352L;
|
||||
private static final long serialVersionUID = -5286362812955627352L;
|
||||
|
||||
public DeleteException(String message) {
|
||||
super(message);
|
||||
}
|
||||
public DeleteException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public DeleteException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
public DeleteException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public DeleteException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
public DeleteException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+10
-11
@@ -22,23 +22,22 @@ package org.apache.struts2.showcase.exception;
|
||||
|
||||
/**
|
||||
* DuplicateKeyException.
|
||||
*
|
||||
*/
|
||||
|
||||
public class DuplicateKeyException extends CreateException {
|
||||
|
||||
private static final long serialVersionUID = 989620752592415898L;
|
||||
private static final long serialVersionUID = 989620752592415898L;
|
||||
|
||||
public DuplicateKeyException(String message) {
|
||||
super(message);
|
||||
}
|
||||
public DuplicateKeyException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public DuplicateKeyException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
public DuplicateKeyException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public DuplicateKeyException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
public DuplicateKeyException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+10
-11
@@ -22,23 +22,22 @@ package org.apache.struts2.showcase.exception;
|
||||
|
||||
/**
|
||||
* StorageException.
|
||||
*
|
||||
*/
|
||||
|
||||
public class StorageException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = -2528721270540362905L;
|
||||
private static final long serialVersionUID = -2528721270540362905L;
|
||||
|
||||
public StorageException(String message) {
|
||||
super(message);
|
||||
}
|
||||
public StorageException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public StorageException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
public StorageException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public StorageException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
public StorageException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+10
-11
@@ -23,23 +23,22 @@ package org.apache.struts2.showcase.exception;
|
||||
|
||||
/**
|
||||
* UpdateException.
|
||||
*
|
||||
*/
|
||||
|
||||
public class UpdateException extends StorageException {
|
||||
|
||||
private static final long serialVersionUID = -4728238600375630452L;
|
||||
private static final long serialVersionUID = -4728238600375630452L;
|
||||
|
||||
|
||||
public UpdateException(String message) {
|
||||
super(message);
|
||||
}
|
||||
public UpdateException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public UpdateException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
public UpdateException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public UpdateException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
public UpdateException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
||||
|
||||
+12
-14
@@ -20,31 +20,29 @@
|
||||
*/
|
||||
package org.apache.struts2.showcase.filedownload;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import com.opensymphony.xwork2.Action;
|
||||
import org.apache.struts2.ServletActionContext;
|
||||
|
||||
import com.opensymphony.xwork2.Action;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* Demonstrates file resource download.
|
||||
* Set filePath to the local file resource to download,
|
||||
* relative to the application root ("/images/struts.gif").
|
||||
*
|
||||
*/
|
||||
public class FileDownloadAction implements Action {
|
||||
|
||||
private String inputPath;
|
||||
public void setInputPath(String value) {
|
||||
inputPath = value;
|
||||
}
|
||||
private String inputPath;
|
||||
|
||||
public InputStream getInputStream() throws Exception {
|
||||
return ServletActionContext.getServletContext().getResourceAsStream(inputPath);
|
||||
}
|
||||
public String execute() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
public String execute() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
public void setInputPath(String value) {
|
||||
inputPath = value;
|
||||
}
|
||||
|
||||
public InputStream getInputStream() throws Exception {
|
||||
return ServletActionContext.getServletContext().getResourceAsStream(inputPath);
|
||||
}
|
||||
}
|
||||
|
||||
+48
-46
@@ -20,66 +20,68 @@
|
||||
*/
|
||||
package org.apache.struts2.showcase.fileupload;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Show case File Upload example's action. <code>FileUploadAction</code>
|
||||
*
|
||||
*/
|
||||
public class FileUploadAction extends ActionSupport {
|
||||
|
||||
private static final long serialVersionUID = 5156288255337069381L;
|
||||
private static final long serialVersionUID = 5156288255337069381L;
|
||||
|
||||
private String contentType;
|
||||
private File upload;
|
||||
private String fileName;
|
||||
private String caption;
|
||||
private String contentType;
|
||||
private File upload;
|
||||
private String fileName;
|
||||
private String caption;
|
||||
|
||||
// since we are using <s:file name="upload" .../> the file name will be
|
||||
// obtained through getter/setter of <file-tag-name>FileName
|
||||
public String getUploadFileName() {
|
||||
return fileName;
|
||||
}
|
||||
public void setUploadFileName(String fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
public String input() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
public String upload() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
// since we are using <s:file name="upload" .../> the file name will be
|
||||
// obtained through getter/setter of <file-tag-name>FileName
|
||||
public String getUploadFileName() {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
public void setUploadFileName(String fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
|
||||
// since we are using <s:file name="upload" ... /> the content type will be
|
||||
// obtained through getter/setter of <file-tag-name>ContentType
|
||||
public String getUploadContentType() {
|
||||
return contentType;
|
||||
}
|
||||
public void setUploadContentType(String contentType) {
|
||||
this.contentType = contentType;
|
||||
}
|
||||
// since we are using <s:file name="upload" ... /> the content type will be
|
||||
// obtained through getter/setter of <file-tag-name>ContentType
|
||||
public String getUploadContentType() {
|
||||
return contentType;
|
||||
}
|
||||
|
||||
public void setUploadContentType(String contentType) {
|
||||
this.contentType = contentType;
|
||||
}
|
||||
|
||||
|
||||
// since we are using <s:file name="upload" ... /> the File itself will be
|
||||
// obtained through getter/setter of <file-tag-name>
|
||||
public File getUpload() {
|
||||
return upload;
|
||||
}
|
||||
public void setUpload(File upload) {
|
||||
this.upload = upload;
|
||||
}
|
||||
// since we are using <s:file name="upload" ... /> the File itself will be
|
||||
// obtained through getter/setter of <file-tag-name>
|
||||
public File getUpload() {
|
||||
return upload;
|
||||
}
|
||||
|
||||
public void setUpload(File upload) {
|
||||
this.upload = upload;
|
||||
}
|
||||
|
||||
|
||||
public String getCaption() {
|
||||
return caption;
|
||||
}
|
||||
public void setCaption(String caption) {
|
||||
this.caption = caption;
|
||||
}
|
||||
|
||||
public String input() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
public String upload() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
public String getCaption() {
|
||||
return caption;
|
||||
}
|
||||
|
||||
public void setCaption(String caption) {
|
||||
this.caption = caption;
|
||||
}
|
||||
}
|
||||
|
||||
+44
-28
@@ -21,10 +21,10 @@
|
||||
// START SNIPPET: entire-file
|
||||
package org.apache.struts2.showcase.fileupload;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Showcase action - mutiple file upload using array.
|
||||
*
|
||||
@@ -32,35 +32,51 @@ import com.opensymphony.xwork2.ActionSupport;
|
||||
*/
|
||||
public class MultipleFileUploadUsingArrayAction extends ActionSupport {
|
||||
|
||||
private File[] uploads;
|
||||
private String[] uploadFileNames;
|
||||
private String[] uploadContentTypes;
|
||||
private File[] uploads;
|
||||
private String[] uploadFileNames;
|
||||
private String[] uploadContentTypes;
|
||||
|
||||
public File[] getUpload() { return this.uploads; }
|
||||
public void setUpload(File[] upload) { this.uploads = upload; }
|
||||
|
||||
public String[] getUploadFileName() { return this.uploadFileNames; }
|
||||
public void setUploadFileName(String[] uploadFileName) { this.uploadFileNames = uploadFileName; }
|
||||
public String upload() throws Exception {
|
||||
System.out.println("\n\n upload2");
|
||||
System.out.println("files:");
|
||||
for (File u : uploads) {
|
||||
System.out.println("*** " + u + "\t" + u.length());
|
||||
}
|
||||
System.out.println("filenames:");
|
||||
for (String n : uploadFileNames) {
|
||||
System.out.println("*** " + n);
|
||||
}
|
||||
System.out.println("content types:");
|
||||
for (String c : uploadContentTypes) {
|
||||
System.out.println("*** " + c);
|
||||
}
|
||||
System.out.println("\n\n");
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
public String[] getUploadContentType() { return this.uploadContentTypes; }
|
||||
public void setUploadContentType(String[] uploadContentType) { this.uploadContentTypes = uploadContentType; }
|
||||
public File[] getUpload() {
|
||||
return this.uploads;
|
||||
}
|
||||
|
||||
public String upload() throws Exception {
|
||||
System.out.println("\n\n upload2");
|
||||
System.out.println("files:");
|
||||
for (File u: uploads) {
|
||||
System.out.println("*** "+u+"\t"+u.length());
|
||||
}
|
||||
System.out.println("filenames:");
|
||||
for (String n: uploadFileNames) {
|
||||
System.out.println("*** "+n);
|
||||
}
|
||||
System.out.println("content types:");
|
||||
for (String c: uploadContentTypes) {
|
||||
System.out.println("*** "+c);
|
||||
}
|
||||
System.out.println("\n\n");
|
||||
return SUCCESS;
|
||||
}
|
||||
public void setUpload(File[] upload) {
|
||||
this.uploads = upload;
|
||||
}
|
||||
|
||||
public String[] getUploadFileName() {
|
||||
return this.uploadFileNames;
|
||||
}
|
||||
|
||||
public void setUploadFileName(String[] uploadFileName) {
|
||||
this.uploadFileNames = uploadFileName;
|
||||
}
|
||||
|
||||
public String[] getUploadContentType() {
|
||||
return this.uploadContentTypes;
|
||||
}
|
||||
|
||||
public void setUploadContentType(String[] uploadContentType) {
|
||||
this.uploadContentTypes = uploadContentType;
|
||||
}
|
||||
}
|
||||
// END SNIPPET: entire-file
|
||||
+45
-40
@@ -20,61 +20,66 @@
|
||||
*/
|
||||
// START SNIPPET: entire-file
|
||||
package org.apache.struts2.showcase.fileupload;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
|
||||
/**
|
||||
* Showcase action - multiple file upload using List
|
||||
*
|
||||
* @version $Date$ $Id$
|
||||
*/
|
||||
public class MultipleFileUploadUsingListAction extends ActionSupport {
|
||||
|
||||
private List<File> uploads = new ArrayList<File>();
|
||||
private List<String> uploadFileNames = new ArrayList<String>();
|
||||
private List<String> uploadContentTypes = new ArrayList<String>();
|
||||
private List<File> uploads = new ArrayList<File>();
|
||||
private List<String> uploadFileNames = new ArrayList<String>();
|
||||
private List<String> uploadContentTypes = new ArrayList<String>();
|
||||
|
||||
|
||||
public List<File> getUpload() {
|
||||
return this.uploads;
|
||||
}
|
||||
public void setUpload(List<File> uploads) {
|
||||
this.uploads = uploads;
|
||||
}
|
||||
public List<File> getUpload() {
|
||||
return this.uploads;
|
||||
}
|
||||
|
||||
public List<String> getUploadFileName() {
|
||||
return this.uploadFileNames;
|
||||
}
|
||||
public void setUploadFileName(List<String> uploadFileNames) {
|
||||
this.uploadFileNames = uploadFileNames;
|
||||
}
|
||||
public void setUpload(List<File> uploads) {
|
||||
this.uploads = uploads;
|
||||
}
|
||||
|
||||
public List<String> getUploadContentType() {
|
||||
return this.uploadContentTypes;
|
||||
}
|
||||
public void setUploadContentType(List<String> contentTypes) {
|
||||
this.uploadContentTypes = contentTypes;
|
||||
}
|
||||
public List<String> getUploadFileName() {
|
||||
return this.uploadFileNames;
|
||||
}
|
||||
|
||||
public String upload() throws Exception {
|
||||
public void setUploadFileName(List<String> uploadFileNames) {
|
||||
this.uploadFileNames = uploadFileNames;
|
||||
}
|
||||
|
||||
System.out.println("\n\n upload1");
|
||||
System.out.println("files:");
|
||||
for (File u: uploads) {
|
||||
System.out.println("*** "+u+"\t"+u.length());
|
||||
}
|
||||
System.out.println("filenames:");
|
||||
for (String n: uploadFileNames) {
|
||||
System.out.println("*** "+n);
|
||||
}
|
||||
System.out.println("content types:");
|
||||
for (String c: uploadContentTypes) {
|
||||
System.out.println("*** "+c);
|
||||
}
|
||||
System.out.println("\n\n");
|
||||
return SUCCESS;
|
||||
}
|
||||
public List<String> getUploadContentType() {
|
||||
return this.uploadContentTypes;
|
||||
}
|
||||
|
||||
public void setUploadContentType(List<String> contentTypes) {
|
||||
this.uploadContentTypes = contentTypes;
|
||||
}
|
||||
|
||||
public String upload() throws Exception {
|
||||
|
||||
System.out.println("\n\n upload1");
|
||||
System.out.println("files:");
|
||||
for (File u : uploads) {
|
||||
System.out.println("*** " + u + "\t" + u.length());
|
||||
}
|
||||
System.out.println("filenames:");
|
||||
for (String n : uploadFileNames) {
|
||||
System.out.println("*** " + n);
|
||||
}
|
||||
System.out.println("content types:");
|
||||
for (String c : uploadContentTypes) {
|
||||
System.out.println("*** " + c);
|
||||
}
|
||||
System.out.println("\n\n");
|
||||
return SUCCESS;
|
||||
}
|
||||
}
|
||||
// END SNIPPET: entire-file
|
||||
+13
-15
@@ -20,39 +20,37 @@
|
||||
*/
|
||||
package org.apache.struts2.showcase.freemarker;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.opensymphony.xwork2.util.ValueStack;
|
||||
import org.apache.struts2.views.freemarker.FreemarkerManager;
|
||||
import org.apache.struts2.views.freemarker.ScopesHashModel;
|
||||
|
||||
import com.opensymphony.xwork2.ognl.OgnlValueStack;
|
||||
import com.opensymphony.xwork2.util.ValueStack;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* This is an example of a custom FreemarkerManager, mean to be
|
||||
* instantiated through Spring.
|
||||
* <p/>
|
||||
*
|
||||
* <p/>
|
||||
* It will add into Freemarker's model
|
||||
* an utility class called {@link CustomFreemarkerManagerUtil} as a simple
|
||||
* example demonstrating how to extends FreemarkerManager.
|
||||
* <p/>
|
||||
*
|
||||
* <p/>
|
||||
* The {@link CustomFreemarkerManagerUtil} will be created by Spring and
|
||||
* injected through constructor injection.
|
||||
* <p/>
|
||||
*/
|
||||
public class CustomFreemarkerManager extends FreemarkerManager {
|
||||
|
||||
private CustomFreemarkerManagerUtil util;
|
||||
private CustomFreemarkerManagerUtil util;
|
||||
|
||||
public CustomFreemarkerManager(CustomFreemarkerManagerUtil util) {
|
||||
this.util = util;
|
||||
}
|
||||
public CustomFreemarkerManager(CustomFreemarkerManagerUtil util) {
|
||||
this.util = util;
|
||||
}
|
||||
|
||||
protected void populateContext(ScopesHashModel model, ValueStack stack, Object action, HttpServletRequest request, HttpServletResponse response) {
|
||||
super.populateContext(model, stack, action, request, response);
|
||||
model.put("customFreemarkerManagerUtil", util);
|
||||
}
|
||||
protected void populateContext(ScopesHashModel model, ValueStack stack, Object action, HttpServletRequest request, HttpServletResponse response) {
|
||||
super.populateContext(model, stack, action, request, response);
|
||||
model.put("customFreemarkerManagerUtil", util);
|
||||
}
|
||||
}
|
||||
|
||||
+8
-8
@@ -30,13 +30,13 @@ import java.util.Date;
|
||||
*/
|
||||
public class CustomFreemarkerManagerUtil {
|
||||
|
||||
public String getTodayDate() {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
|
||||
return sdf.format(new Date());
|
||||
}
|
||||
public String getTodayDate() {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
|
||||
return sdf.format(new Date());
|
||||
}
|
||||
|
||||
public String getTimeNow() {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss");
|
||||
return sdf.format(new Date());
|
||||
}
|
||||
public String getTimeNow() {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss");
|
||||
return sdf.format(new Date());
|
||||
}
|
||||
}
|
||||
|
||||
+26
-26
@@ -30,38 +30,38 @@ import java.text.DateFormatSymbols;
|
||||
*/
|
||||
public class StandardTagsAction extends ActionSupport implements Preparable {
|
||||
|
||||
private String name;
|
||||
private String[] gender;
|
||||
private String[] months;
|
||||
private String name;
|
||||
private String[] gender;
|
||||
private String[] months;
|
||||
|
||||
public void prepare() {
|
||||
months = new DateFormatSymbols().getMonths();
|
||||
name = StandardTagsAction.class.getName().substring(StandardTagsAction.class.getName().lastIndexOf(".")+1);
|
||||
gender = new String[] { "Male", "Femal" };
|
||||
}
|
||||
public void prepare() {
|
||||
months = new DateFormatSymbols().getMonths();
|
||||
name = StandardTagsAction.class.getName().substring(StandardTagsAction.class.getName().lastIndexOf(".") + 1);
|
||||
gender = new String[]{"Male", "Femal"};
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String[] getMonths() {
|
||||
return months;
|
||||
}
|
||||
public String[] getMonths() {
|
||||
return months;
|
||||
}
|
||||
|
||||
public void setMonths(String[] months) {
|
||||
this.months = months;
|
||||
}
|
||||
public void setMonths(String[] months) {
|
||||
this.months = months;
|
||||
}
|
||||
|
||||
|
||||
public String[] getGender() {
|
||||
return gender;
|
||||
}
|
||||
public String[] getGender() {
|
||||
return gender;
|
||||
}
|
||||
|
||||
public void setGender(String[] gender) {
|
||||
this.gender = gender;
|
||||
}
|
||||
public void setGender(String[] gender) {
|
||||
this.gender = gender;
|
||||
}
|
||||
}
|
||||
|
||||
+24
-24
@@ -20,40 +20,40 @@
|
||||
*/
|
||||
package org.apache.struts2.showcase.hangman;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
import org.apache.struts2.interceptor.SessionAware;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
import java.util.Map;
|
||||
|
||||
public class GetUpdatedHangmanAction extends ActionSupport implements SessionAware {
|
||||
|
||||
private static final long serialVersionUID = 5506025785406043027L;
|
||||
private static final long serialVersionUID = 5506025785406043027L;
|
||||
|
||||
private Map session;
|
||||
private Hangman hangman;
|
||||
private Map session;
|
||||
private Hangman hangman;
|
||||
|
||||
|
||||
public String execute() throws Exception {
|
||||
hangman = (Hangman) session.get(HangmanConstants.HANGMAN_SESSION_KEY);
|
||||
public String execute() throws Exception {
|
||||
hangman = (Hangman) session.get(HangmanConstants.HANGMAN_SESSION_KEY);
|
||||
|
||||
System.out.println("\n\n\n");
|
||||
System.out.println("hangman="+hangman);
|
||||
System.out.println("available = "+hangman.getCharactersAvailable().size());
|
||||
System.out.println("guess left="+hangman.guessLeft());
|
||||
System.out.println("\n\n\n");
|
||||
System.out.println("\n\n\n");
|
||||
System.out.println("hangman=" + hangman);
|
||||
System.out.println("available = " + hangman.getCharactersAvailable().size());
|
||||
System.out.println("guess left=" + hangman.guessLeft());
|
||||
System.out.println("\n\n\n");
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
public void setSession(Map session) {
|
||||
this.session = session;
|
||||
}
|
||||
public void setSession(Map session) {
|
||||
this.session = session;
|
||||
}
|
||||
|
||||
public Hangman getHangman() {
|
||||
return hangman;
|
||||
}
|
||||
public void setHangman(Hangman hangman) {
|
||||
this.hangman = hangman;
|
||||
}
|
||||
public Hangman getHangman() {
|
||||
return hangman;
|
||||
}
|
||||
|
||||
public void setHangman(Hangman hangman) {
|
||||
this.hangman = hangman;
|
||||
}
|
||||
}
|
||||
|
||||
+23
-24
@@ -20,40 +20,39 @@
|
||||
*/
|
||||
package org.apache.struts2.showcase.hangman;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
import org.apache.struts2.interceptor.SessionAware;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
import java.util.Map;
|
||||
|
||||
public class GuessCharacterAction extends ActionSupport implements SessionAware {
|
||||
|
||||
private static final long serialVersionUID = 9050915577007590674L;
|
||||
private static final long serialVersionUID = 9050915577007590674L;
|
||||
|
||||
private Map session;
|
||||
private Character character;
|
||||
private Hangman hangman;
|
||||
private Map session;
|
||||
private Character character;
|
||||
private Hangman hangman;
|
||||
|
||||
public String execute() throws Exception {
|
||||
hangman = (Hangman) session.get(HangmanConstants.HANGMAN_SESSION_KEY);
|
||||
hangman.guess(character);
|
||||
public String execute() throws Exception {
|
||||
hangman = (Hangman) session.get(HangmanConstants.HANGMAN_SESSION_KEY);
|
||||
hangman.guess(character);
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
public Hangman getHangman() {
|
||||
return hangman;
|
||||
}
|
||||
public Hangman getHangman() {
|
||||
return hangman;
|
||||
}
|
||||
|
||||
public void setSession(Map session) {
|
||||
this.session = session;
|
||||
}
|
||||
public void setSession(Map session) {
|
||||
this.session = session;
|
||||
}
|
||||
|
||||
public void setCharacter(Character character) {
|
||||
this.character = character;
|
||||
}
|
||||
public void setCharacter(Character character) {
|
||||
this.character = character;
|
||||
}
|
||||
|
||||
public Character getCharacter() {
|
||||
return this.character;
|
||||
}
|
||||
public Character getCharacter() {
|
||||
return this.character;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,83 +27,83 @@ import java.util.List;
|
||||
|
||||
public class Hangman implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 8566954355839652509L;
|
||||
private static final long serialVersionUID = 8566954355839652509L;
|
||||
|
||||
private Vocab vocab;
|
||||
private Vocab vocab;
|
||||
|
||||
private Boolean win = false;
|
||||
private Boolean win = false;
|
||||
|
||||
private int guessLeft = 5;
|
||||
public List<Character> charactersAvailable;
|
||||
public List<Character> charactersGuessed;
|
||||
private int guessLeft = 5;
|
||||
public List<Character> charactersAvailable;
|
||||
public List<Character> charactersGuessed;
|
||||
|
||||
public Hangman(Vocab vocab) {
|
||||
// Arrays.asList(...) returns List that doesn't support remove(), hence
|
||||
// we wrap it with an ArrayList to avoid UnsupportedOperationException
|
||||
// when doing a remove()
|
||||
charactersAvailable = new ArrayList<Character>(Arrays.asList(
|
||||
new Character[] {
|
||||
Character.valueOf('A'), Character.valueOf('B'), Character.valueOf('C'),
|
||||
Character.valueOf('D'), Character.valueOf('E'), Character.valueOf('F'),
|
||||
Character.valueOf('G'), Character.valueOf('H'), Character.valueOf('I'),
|
||||
Character.valueOf('J'), Character.valueOf('K'), Character.valueOf('L'),
|
||||
Character.valueOf('M'), Character.valueOf('N'), Character.valueOf('O'),
|
||||
Character.valueOf('P'), Character.valueOf('Q'), Character.valueOf('R'),
|
||||
Character.valueOf('S'), Character.valueOf('T'), Character.valueOf('U'),
|
||||
Character.valueOf('V'), Character.valueOf('W'), Character.valueOf('X'),
|
||||
Character.valueOf('Y'), Character.valueOf('Z')
|
||||
}));
|
||||
charactersGuessed = new ArrayList<Character>();
|
||||
this.vocab = vocab;
|
||||
}
|
||||
public Hangman(Vocab vocab) {
|
||||
// Arrays.asList(...) returns List that doesn't support remove(), hence
|
||||
// we wrap it with an ArrayList to avoid UnsupportedOperationException
|
||||
// when doing a remove()
|
||||
charactersAvailable = new ArrayList<Character>(Arrays.asList(
|
||||
new Character[]{
|
||||
Character.valueOf('A'), Character.valueOf('B'), Character.valueOf('C'),
|
||||
Character.valueOf('D'), Character.valueOf('E'), Character.valueOf('F'),
|
||||
Character.valueOf('G'), Character.valueOf('H'), Character.valueOf('I'),
|
||||
Character.valueOf('J'), Character.valueOf('K'), Character.valueOf('L'),
|
||||
Character.valueOf('M'), Character.valueOf('N'), Character.valueOf('O'),
|
||||
Character.valueOf('P'), Character.valueOf('Q'), Character.valueOf('R'),
|
||||
Character.valueOf('S'), Character.valueOf('T'), Character.valueOf('U'),
|
||||
Character.valueOf('V'), Character.valueOf('W'), Character.valueOf('X'),
|
||||
Character.valueOf('Y'), Character.valueOf('Z')
|
||||
}));
|
||||
charactersGuessed = new ArrayList<Character>();
|
||||
this.vocab = vocab;
|
||||
}
|
||||
|
||||
public void guess(Character character) {
|
||||
assert(character != null);
|
||||
public void guess(Character character) {
|
||||
assert (character != null);
|
||||
|
||||
synchronized(charactersAvailable) {
|
||||
if (guessLeft < 0) {
|
||||
throw new HangmanException(
|
||||
HangmanException.Type.valueOf("GAME_ENDED"), "Game already eneded");
|
||||
}
|
||||
Character characterInUpperCase = Character.toUpperCase(character);
|
||||
boolean ok = charactersAvailable.remove(characterInUpperCase);
|
||||
if (ok) {
|
||||
charactersGuessed.add(characterInUpperCase);
|
||||
if (! vocab.containCharacter(characterInUpperCase)) {
|
||||
guessLeft = guessLeft - 1;
|
||||
}
|
||||
}
|
||||
if (vocab.containsAllCharacter(charactersGuessed)) {
|
||||
win = true;
|
||||
}
|
||||
System.out.println(" *********************************** "+win);
|
||||
}
|
||||
}
|
||||
synchronized (charactersAvailable) {
|
||||
if (guessLeft < 0) {
|
||||
throw new HangmanException(
|
||||
HangmanException.Type.valueOf("GAME_ENDED"), "Game already eneded");
|
||||
}
|
||||
Character characterInUpperCase = Character.toUpperCase(character);
|
||||
boolean ok = charactersAvailable.remove(characterInUpperCase);
|
||||
if (ok) {
|
||||
charactersGuessed.add(characterInUpperCase);
|
||||
if (!vocab.containCharacter(characterInUpperCase)) {
|
||||
guessLeft = guessLeft - 1;
|
||||
}
|
||||
}
|
||||
if (vocab.containsAllCharacter(charactersGuessed)) {
|
||||
win = true;
|
||||
}
|
||||
System.out.println(" *********************************** " + win);
|
||||
}
|
||||
}
|
||||
|
||||
public Boolean isWin() {
|
||||
return this.win;
|
||||
}
|
||||
public Boolean isWin() {
|
||||
return this.win;
|
||||
}
|
||||
|
||||
public Vocab getVocab() {
|
||||
return vocab;
|
||||
}
|
||||
public Vocab getVocab() {
|
||||
return vocab;
|
||||
}
|
||||
|
||||
public Boolean gameEnded() {
|
||||
return ((guessLeft < 0) || win);
|
||||
}
|
||||
public Boolean gameEnded() {
|
||||
return ((guessLeft < 0) || win);
|
||||
}
|
||||
|
||||
public Integer guessLeft() {
|
||||
return guessLeft;
|
||||
}
|
||||
public Integer guessLeft() {
|
||||
return guessLeft;
|
||||
}
|
||||
|
||||
public List<Character> getCharactersAvailable() {
|
||||
synchronized(charactersAvailable) {
|
||||
return new ArrayList<Character>(charactersAvailable);
|
||||
//return charactersAvailable;
|
||||
}
|
||||
}
|
||||
public List<Character> getCharactersAvailable() {
|
||||
synchronized (charactersAvailable) {
|
||||
return new ArrayList<Character>(charactersAvailable);
|
||||
//return charactersAvailable;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean characterGuessedBefore(Character character) {
|
||||
return charactersGuessed.contains(character);
|
||||
}
|
||||
public boolean characterGuessedBefore(Character character) {
|
||||
return charactersGuessed.contains(character);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -21,6 +21,6 @@
|
||||
package org.apache.struts2.showcase.hangman;
|
||||
|
||||
public class HangmanConstants {
|
||||
// keeps a Hangman object in HttpSession
|
||||
public static final String HANGMAN_SESSION_KEY = "Hangman_Session_Key";
|
||||
// keeps a Hangman object in HttpSession
|
||||
public static final String HANGMAN_SESSION_KEY = "Hangman_Session_Key";
|
||||
}
|
||||
|
||||
+14
-14
@@ -22,23 +22,23 @@ package org.apache.struts2.showcase.hangman;
|
||||
|
||||
public class HangmanException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = -8500292863595941335L;
|
||||
private static final long serialVersionUID = -8500292863595941335L;
|
||||
|
||||
enum Type {
|
||||
GAME_ENDED,
|
||||
NO_VOCAB,
|
||||
NO_VOCAB_SOURCE;
|
||||
}
|
||||
enum Type {
|
||||
GAME_ENDED,
|
||||
NO_VOCAB,
|
||||
NO_VOCAB_SOURCE;
|
||||
}
|
||||
|
||||
|
||||
private Type type;
|
||||
private Type type;
|
||||
|
||||
public HangmanException (Type type, String reason) {
|
||||
super(reason);
|
||||
this.type = type;
|
||||
}
|
||||
public HangmanException(Type type, String reason) {
|
||||
super(reason);
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Type getType() {
|
||||
return type;
|
||||
}
|
||||
public Type getType() {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,13 +22,13 @@ package org.apache.struts2.showcase.hangman;
|
||||
|
||||
public class HangmanService {
|
||||
|
||||
public VocabSource vocabSource;
|
||||
public VocabSource vocabSource;
|
||||
|
||||
public HangmanService(VocabSource vocabSource) {
|
||||
this.vocabSource = vocabSource;
|
||||
}
|
||||
public HangmanService(VocabSource vocabSource) {
|
||||
this.vocabSource = vocabSource;
|
||||
}
|
||||
|
||||
public Hangman startNewGame() {
|
||||
return new Hangman(vocabSource.getRandomVocab());
|
||||
}
|
||||
public Hangman startNewGame() {
|
||||
return new Hangman(vocabSource.getRandomVocab());
|
||||
}
|
||||
}
|
||||
|
||||
+34
-34
@@ -27,45 +27,45 @@ import java.util.Properties;
|
||||
|
||||
public class PropertiesVocabSource implements VocabSource {
|
||||
|
||||
private Properties prop;
|
||||
private List<Vocab> vocabs;
|
||||
private Properties prop;
|
||||
private List<Vocab> vocabs;
|
||||
|
||||
public PropertiesVocabSource() {
|
||||
}
|
||||
public PropertiesVocabSource() {
|
||||
}
|
||||
|
||||
public PropertiesVocabSource(Properties prop) {
|
||||
assert(prop != null);
|
||||
this.prop = prop;
|
||||
vocabs = readVocab(prop);
|
||||
}
|
||||
public PropertiesVocabSource(Properties prop) {
|
||||
assert (prop != null);
|
||||
this.prop = prop;
|
||||
vocabs = readVocab(prop);
|
||||
}
|
||||
|
||||
public void setVocabProperties(Properties prop) {
|
||||
assert(prop != null);
|
||||
this.prop = prop;
|
||||
vocabs = readVocab(prop);
|
||||
}
|
||||
public void setVocabProperties(Properties prop) {
|
||||
assert (prop != null);
|
||||
this.prop = prop;
|
||||
vocabs = readVocab(prop);
|
||||
}
|
||||
|
||||
public Vocab getRandomVocab() {
|
||||
if (vocabs == null) {
|
||||
throw new HangmanException(HangmanException.Type.valueOf("NO_VOCAB_SOURCE"), "No vocab source");
|
||||
}
|
||||
if (vocabs.size() <= 0) {
|
||||
throw new HangmanException(HangmanException.Type.valueOf("NO_VOCAB"), "No vocab");
|
||||
}
|
||||
long vocabIndex = Math.round((Math.random() * (double)prop.size()));
|
||||
vocabIndex = vocabIndex == vocabs.size() ? vocabs.size() - 1 : vocabIndex;
|
||||
return vocabs.get((int)vocabIndex);
|
||||
}
|
||||
public Vocab getRandomVocab() {
|
||||
if (vocabs == null) {
|
||||
throw new HangmanException(HangmanException.Type.valueOf("NO_VOCAB_SOURCE"), "No vocab source");
|
||||
}
|
||||
if (vocabs.size() <= 0) {
|
||||
throw new HangmanException(HangmanException.Type.valueOf("NO_VOCAB"), "No vocab");
|
||||
}
|
||||
long vocabIndex = Math.round((Math.random() * (double) prop.size()));
|
||||
vocabIndex = vocabIndex == vocabs.size() ? vocabs.size() - 1 : vocabIndex;
|
||||
return vocabs.get((int) vocabIndex);
|
||||
}
|
||||
|
||||
protected List<Vocab> readVocab(Properties prop) {
|
||||
List<Vocab> vocabList = new ArrayList<Vocab>();
|
||||
protected List<Vocab> readVocab(Properties prop) {
|
||||
List<Vocab> vocabList = new ArrayList<Vocab>();
|
||||
|
||||
for (Map.Entry e : prop.entrySet()) {
|
||||
String vocab = (String) e.getKey();
|
||||
String hint = (String) e.getValue();
|
||||
for (Map.Entry e : prop.entrySet()) {
|
||||
String vocab = (String) e.getKey();
|
||||
String hint = (String) e.getValue();
|
||||
|
||||
vocabList.add(new Vocab(vocab, hint));
|
||||
}
|
||||
return vocabList;
|
||||
}
|
||||
vocabList.add(new Vocab(vocab, hint));
|
||||
}
|
||||
return vocabList;
|
||||
}
|
||||
}
|
||||
|
||||
+22
-23
@@ -20,42 +20,41 @@
|
||||
*/
|
||||
package org.apache.struts2.showcase.hangman;
|
||||
|
||||
import static org.apache.struts2.showcase.hangman.HangmanConstants.HANGMAN_SESSION_KEY;
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
import org.apache.struts2.interceptor.SessionAware;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.struts2.interceptor.SessionAware;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
import static org.apache.struts2.showcase.hangman.HangmanConstants.HANGMAN_SESSION_KEY;
|
||||
|
||||
public class StartHangmanAction extends ActionSupport implements SessionAware {
|
||||
|
||||
private static final long serialVersionUID = 2333463075324892521L;
|
||||
private static final long serialVersionUID = 2333463075324892521L;
|
||||
|
||||
private HangmanService service;
|
||||
private Hangman hangman;
|
||||
private Map session;
|
||||
private HangmanService service;
|
||||
private Hangman hangman;
|
||||
private Map session;
|
||||
|
||||
|
||||
public StartHangmanAction(HangmanService service) {
|
||||
this.service = service;
|
||||
}
|
||||
public StartHangmanAction(HangmanService service) {
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
public String execute() throws Exception {
|
||||
public String execute() throws Exception {
|
||||
|
||||
hangman = service.startNewGame();
|
||||
session.put(HANGMAN_SESSION_KEY, hangman);
|
||||
hangman = service.startNewGame();
|
||||
session.put(HANGMAN_SESSION_KEY, hangman);
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
public Hangman getHangman() {
|
||||
return hangman;
|
||||
}
|
||||
public Hangman getHangman() {
|
||||
return hangman;
|
||||
}
|
||||
|
||||
|
||||
// === SessionAware ===
|
||||
public void setSession(Map session) {
|
||||
this.session = session;
|
||||
}
|
||||
// === SessionAware ===
|
||||
public void setSession(Map session) {
|
||||
this.session = session;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,60 +27,65 @@ import java.util.List;
|
||||
|
||||
public class Vocab implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String vocab;
|
||||
private String hint;
|
||||
private Character[] characters; // character this vocab is made up of
|
||||
private String vocab;
|
||||
private String hint;
|
||||
private Character[] characters; // character this vocab is made up of
|
||||
|
||||
public Vocab(String vocab, String hint) {
|
||||
assert(vocab != null);
|
||||
assert(hint != null);
|
||||
public Vocab(String vocab, String hint) {
|
||||
assert (vocab != null);
|
||||
assert (hint != null);
|
||||
|
||||
this.vocab = vocab.toUpperCase();
|
||||
this.hint = hint;
|
||||
}
|
||||
this.vocab = vocab.toUpperCase();
|
||||
this.hint = hint;
|
||||
}
|
||||
|
||||
public String getVocab() { return this.vocab; }
|
||||
public String getHint() { return this.hint; }
|
||||
public String getVocab() {
|
||||
return this.vocab;
|
||||
}
|
||||
|
||||
public Boolean containCharacter(Character character) {
|
||||
assert(character != null);
|
||||
public String getHint() {
|
||||
return this.hint;
|
||||
}
|
||||
|
||||
return (vocab.contains(character.toString())) ? true : false;
|
||||
}
|
||||
public Boolean containCharacter(Character character) {
|
||||
assert (character != null);
|
||||
|
||||
public Character[] inCharacters() {
|
||||
if (characters == null) {
|
||||
char[] c = vocab.toCharArray();
|
||||
characters = new Character[c.length];
|
||||
for (int a=0; a< c.length; a++) {
|
||||
characters[a] = Character.valueOf(c[a]);
|
||||
}
|
||||
}
|
||||
return characters;
|
||||
}
|
||||
return (vocab.contains(character.toString())) ? true : false;
|
||||
}
|
||||
|
||||
public boolean containsAllCharacter(List<Character> charactersGuessed) {
|
||||
Character[] chars = inCharacters();
|
||||
List<Character> tmpChars = Arrays.asList(chars);
|
||||
return charactersGuessed.containsAll(tmpChars);
|
||||
}
|
||||
public Character[] inCharacters() {
|
||||
if (characters == null) {
|
||||
char[] c = vocab.toCharArray();
|
||||
characters = new Character[c.length];
|
||||
for (int a = 0; a < c.length; a++) {
|
||||
characters[a] = Character.valueOf(c[a]);
|
||||
}
|
||||
}
|
||||
return characters;
|
||||
}
|
||||
|
||||
public static void main(String args[]) throws Exception {
|
||||
Vocab v = new Vocab("JAVA", "a java word");
|
||||
public boolean containsAllCharacter(List<Character> charactersGuessed) {
|
||||
Character[] chars = inCharacters();
|
||||
List<Character> tmpChars = Arrays.asList(chars);
|
||||
return charactersGuessed.containsAll(tmpChars);
|
||||
}
|
||||
|
||||
List<Character> list1= new ArrayList<Character>();
|
||||
list1.add(new Character('J'));
|
||||
list1.add(new Character('V'));
|
||||
public static void main(String args[]) throws Exception {
|
||||
Vocab v = new Vocab("JAVA", "a java word");
|
||||
|
||||
List<Character> list2 = new ArrayList<Character>();
|
||||
list2.add(new Character('J'));
|
||||
list2.add(new Character('V'));
|
||||
list2.add(new Character('A'));
|
||||
List<Character> list1 = new ArrayList<Character>();
|
||||
list1.add(new Character('J'));
|
||||
list1.add(new Character('V'));
|
||||
|
||||
System.out.println(v.containsAllCharacter(list1));
|
||||
System.out.println(v.containsAllCharacter(list2));
|
||||
List<Character> list2 = new ArrayList<Character>();
|
||||
list2.add(new Character('J'));
|
||||
list2.add(new Character('V'));
|
||||
list2.add(new Character('A'));
|
||||
|
||||
}
|
||||
System.out.println(v.containsAllCharacter(list1));
|
||||
System.out.println(v.containsAllCharacter(list2));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,5 +21,5 @@
|
||||
package org.apache.struts2.showcase.hangman;
|
||||
|
||||
public interface VocabSource {
|
||||
Vocab getRandomVocab();
|
||||
Vocab getRandomVocab();
|
||||
}
|
||||
|
||||
+11
-11
@@ -20,25 +20,25 @@
|
||||
*/
|
||||
package org.apache.struts2.showcase.integration;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.struts.action.Action;
|
||||
import org.apache.struts.action.ActionForm;
|
||||
import org.apache.struts.action.ActionForward;
|
||||
import org.apache.struts.action.ActionMapping;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
public class EditGangsterAction extends Action {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
|
||||
*/
|
||||
@Override
|
||||
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||
// Some code to load the gangster from the db as necessary
|
||||
/* (non-Javadoc)
|
||||
* @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
|
||||
*/
|
||||
@Override
|
||||
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||
// Some code to load the gangster from the db as necessary
|
||||
|
||||
return mapping.findForward("success");
|
||||
}
|
||||
return mapping.findForward("success");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
+79
-72
@@ -20,89 +20,96 @@
|
||||
*/
|
||||
package org.apache.struts2.showcase.integration;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.struts.action.ActionErrors;
|
||||
import org.apache.struts.action.ActionMapping;
|
||||
import org.apache.struts.action.ActionMessage;
|
||||
import org.apache.struts.validator.ValidatorForm;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
public class GangsterForm extends ValidatorForm {
|
||||
|
||||
private String name;
|
||||
private String age;
|
||||
private String description;
|
||||
private boolean bustedBefore;
|
||||
private String name;
|
||||
private String age;
|
||||
private String description;
|
||||
private boolean bustedBefore;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.apache.struts.action.ActionForm#reset(org.apache.struts.action.ActionMapping, javax.servlet.http.HttpServletRequest)
|
||||
*/
|
||||
@Override
|
||||
public void reset(ActionMapping arg0, HttpServletRequest arg1) {
|
||||
bustedBefore = false;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.apache.struts.action.ActionForm#reset(org.apache.struts.action.ActionMapping, javax.servlet.http.HttpServletRequest)
|
||||
*/
|
||||
@Override
|
||||
public void reset(ActionMapping arg0, HttpServletRequest arg1) {
|
||||
bustedBefore = false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.apache.struts.action.ActionForm#validate(org.apache.struts.action.ActionMapping, javax.servlet.http.HttpServletRequest)
|
||||
*/
|
||||
@Override
|
||||
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
|
||||
ActionErrors errors = super.validate(mapping, request);
|
||||
if (name == null || name.length() == 0) {
|
||||
errors.add("name", new ActionMessage("The name must not be blank"));
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.apache.struts.action.ActionForm#validate(org.apache.struts.action.ActionMapping, javax.servlet.http.HttpServletRequest)
|
||||
*/
|
||||
@Override
|
||||
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
|
||||
ActionErrors errors = super.validate(mapping, request);
|
||||
if (name == null || name.length() == 0) {
|
||||
errors.add("name", new ActionMessage("The name must not be blank"));
|
||||
}
|
||||
|
||||
return errors;
|
||||
}
|
||||
return errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the age
|
||||
*/
|
||||
public String getAge() {
|
||||
return age;
|
||||
}
|
||||
/**
|
||||
* @param age the age to set
|
||||
*/
|
||||
public void setAge(String age) {
|
||||
this.age = age;
|
||||
}
|
||||
/**
|
||||
* @return the bustedBefore
|
||||
*/
|
||||
public boolean isBustedBefore() {
|
||||
return bustedBefore;
|
||||
}
|
||||
/**
|
||||
* @param bustedBefore the bustedBefore to set
|
||||
*/
|
||||
public void setBustedBefore(boolean bustedBefore) {
|
||||
this.bustedBefore = bustedBefore;
|
||||
}
|
||||
/**
|
||||
* @return the description
|
||||
*/
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
/**
|
||||
* @param description the description to set
|
||||
*/
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
/**
|
||||
* @return the name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
/**
|
||||
* @param name the name to set
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
/**
|
||||
* @return the age
|
||||
*/
|
||||
public String getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param age the age to set
|
||||
*/
|
||||
public void setAge(String age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the bustedBefore
|
||||
*/
|
||||
public boolean isBustedBefore() {
|
||||
return bustedBefore;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bustedBefore the bustedBefore to set
|
||||
*/
|
||||
public void setBustedBefore(boolean bustedBefore) {
|
||||
this.bustedBefore = bustedBefore;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the description
|
||||
*/
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param description the description to set
|
||||
*/
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name the name to set
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
+14
-19
@@ -20,32 +20,27 @@
|
||||
*/
|
||||
package org.apache.struts2.showcase.integration;
|
||||
|
||||
import org.apache.struts.action.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.struts.action.Action;
|
||||
import org.apache.struts.action.ActionForm;
|
||||
import org.apache.struts.action.ActionForward;
|
||||
import org.apache.struts.action.ActionMapping;
|
||||
import org.apache.struts.action.ActionMessage;
|
||||
import org.apache.struts.action.ActionMessages;
|
||||
|
||||
public class SaveGangsterAction extends Action {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
|
||||
*/
|
||||
@Override
|
||||
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||
/* (non-Javadoc)
|
||||
* @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
|
||||
*/
|
||||
@Override
|
||||
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||
|
||||
// Some code to save the gangster to the db as necessary
|
||||
GangsterForm gform = (GangsterForm) form;
|
||||
ActionMessages messages = new ActionMessages();
|
||||
messages.add("msg", new ActionMessage("Gangster "+gform.getName()+" added successfully"));
|
||||
addMessages(request, messages);
|
||||
// Some code to save the gangster to the db as necessary
|
||||
GangsterForm gform = (GangsterForm) form;
|
||||
ActionMessages messages = new ActionMessages();
|
||||
messages.add("msg", new ActionMessage("Gangster " + gform.getName() + " added successfully"));
|
||||
addMessages(request, messages);
|
||||
|
||||
return mapping.findForward("success");
|
||||
}
|
||||
return mapping.findForward("success");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
+73
-80
@@ -20,17 +20,13 @@
|
||||
*/
|
||||
package org.apache.struts2.showcase.jsf;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.struts2.showcase.action.EmployeeAction;
|
||||
import org.apache.struts2.showcase.dao.SkillDao;
|
||||
import org.apache.struts2.showcase.model.Employee;
|
||||
import org.apache.struts2.showcase.model.Skill;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Overriding the EmployeeAction to main provide getters returning the data in
|
||||
@@ -38,85 +34,82 @@ import org.apache.struts2.showcase.model.Skill;
|
||||
*/
|
||||
public class JsfEmployeeAction extends EmployeeAction {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* Creating a default employee and main skill, since the JSF EL can't handle
|
||||
* creating new objects as necessary
|
||||
*
|
||||
*/
|
||||
public JsfEmployeeAction() {
|
||||
Employee e = new Employee();
|
||||
e.setMainSkill(new Skill());
|
||||
setCurrentEmployee(e);
|
||||
}
|
||||
@Autowired
|
||||
private SkillDao skillDao;
|
||||
|
||||
private SkillDao skillDao;
|
||||
/**
|
||||
* Creating a default employee and main skill, since the JSF EL can't handle
|
||||
* creating new objects as necessary
|
||||
*/
|
||||
public JsfEmployeeAction() {
|
||||
Employee e = new Employee();
|
||||
e.setMainSkill(new Skill());
|
||||
setCurrentEmployee(e);
|
||||
}
|
||||
|
||||
public void setSkillDao(SkillDao skillDao) {
|
||||
this.skillDao = skillDao;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returning a List because the JSF dataGrid can't handle a Set for some
|
||||
* reason
|
||||
*/
|
||||
@Override
|
||||
public Collection getAvailableItems() {
|
||||
return new ArrayList(super.getAvailableItems());
|
||||
}
|
||||
/**
|
||||
* Returning a List because the JSF dataGrid can't handle a Set for some
|
||||
* reason
|
||||
*/
|
||||
@Override
|
||||
public Collection getAvailableItems() {
|
||||
return new ArrayList(super.getAvailableItems());
|
||||
}
|
||||
|
||||
/**
|
||||
* Changing the String array into a Map
|
||||
*/
|
||||
public Map<String, String> getAvailablePositionsAsMap() {
|
||||
Map<String, String> map = new LinkedHashMap<String, String>();
|
||||
for (String val : super.getAvailablePositions()) {
|
||||
map.put(val, val);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
/**
|
||||
* Changing the String array into a Map
|
||||
*/
|
||||
public Map<String, String> getAvailablePositionsAsMap() {
|
||||
Map<String, String> map = new LinkedHashMap<String, String>();
|
||||
for (String val : super.getAvailablePositions()) {
|
||||
map.put(val, val);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converting the list into a map
|
||||
*/
|
||||
public Map getAvailableLevelsAsMap() {
|
||||
Map map = new LinkedHashMap();
|
||||
for (Object val : super.getAvailableLevels()) {
|
||||
map.put(val, val);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
/**
|
||||
* Converting the list into a map
|
||||
*/
|
||||
public Map getAvailableLevelsAsMap() {
|
||||
Map map = new LinkedHashMap();
|
||||
for (Object val : super.getAvailableLevels()) {
|
||||
map.put(val, val);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converting the Skill object list into a map
|
||||
*/
|
||||
public Map<String, String> getAvailableSkills() {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
for (Object val : skillDao.findAll()) {
|
||||
Skill skill = (Skill) val;
|
||||
map.put(skill.getDescription(), skill.getName());
|
||||
}
|
||||
return map;
|
||||
}
|
||||
/**
|
||||
* Converting the Skill object list into a map
|
||||
*/
|
||||
public Map<String, String> getAvailableSkills() {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
for (Object val : skillDao.findAll()) {
|
||||
Skill skill = (Skill) val;
|
||||
map.put(skill.getDescription(), skill.getName());
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the selected Skill objects as a list
|
||||
*/
|
||||
public List<String> getSelectedSkillsAsList() {
|
||||
System.out.println("asked for skills");
|
||||
List<String> list = new ArrayList<String>();
|
||||
List skills = super.getSelectedSkills();
|
||||
if (skills != null) {
|
||||
for (Object val : skills) {
|
||||
if (val instanceof Skill) {
|
||||
list.add(((Skill) val).getDescription());
|
||||
} else {
|
||||
Skill skill = skillDao.getSkill((String) val);
|
||||
list.add(skill.getDescription());
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
/**
|
||||
* Gets the selected Skill objects as a list
|
||||
*/
|
||||
public List<String> getSelectedSkillsAsList() {
|
||||
System.out.println("asked for skills");
|
||||
List<String> list = new ArrayList<String>();
|
||||
List skills = super.getSelectedSkills();
|
||||
if (skills != null) {
|
||||
for (Object val : skills) {
|
||||
if (val instanceof Skill) {
|
||||
list.add(((Skill) val).getDescription());
|
||||
} else {
|
||||
Skill skill = skillDao.getSkill((String) val);
|
||||
list.add(skill.getDescription());
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,151 +26,150 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* Employee.
|
||||
*
|
||||
*/
|
||||
|
||||
public class Employee implements IdEntity {
|
||||
|
||||
private static final long serialVersionUID = -6226845151026823748L;
|
||||
private static final long serialVersionUID = -6226845151026823748L;
|
||||
|
||||
private Long empId; //textfield w/ conversion
|
||||
private String firstName;
|
||||
private String lastName;
|
||||
private Date birthDate; //datepicker
|
||||
private Float salary; //textfield w/ conversion
|
||||
private boolean married; //checkbox
|
||||
private String position; //combobox
|
||||
private Skill mainSkill; //select
|
||||
private List otherSkills; //doubleSelect
|
||||
private String password; //password
|
||||
private String level; //radio
|
||||
private String comment; //textarea
|
||||
private Long empId; //textfield w/ conversion
|
||||
private String firstName;
|
||||
private String lastName;
|
||||
private Date birthDate; //datepicker
|
||||
private Float salary; //textfield w/ conversion
|
||||
private boolean married; //checkbox
|
||||
private String position; //combobox
|
||||
private Skill mainSkill; //select
|
||||
private List otherSkills; //doubleSelect
|
||||
private String password; //password
|
||||
private String level; //radio
|
||||
private String comment; //textarea
|
||||
|
||||
public Employee() {
|
||||
}
|
||||
public Employee() {
|
||||
}
|
||||
|
||||
public Employee(Long empId, String firstName, String lastName) {
|
||||
this.empId = empId;
|
||||
this.firstName = firstName;
|
||||
this.lastName = lastName;
|
||||
}
|
||||
public Employee(Long empId, String firstName, String lastName) {
|
||||
this.empId = empId;
|
||||
this.firstName = firstName;
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
public Employee(Long empId, String firstName, String lastName, Date birthDate, Float salary, boolean married, String position, Skill mainSkill, List otherSkills, String password, String level, String comment) {
|
||||
this.empId = empId;
|
||||
this.firstName = firstName;
|
||||
this.lastName = lastName;
|
||||
this.birthDate = birthDate;
|
||||
this.salary = salary;
|
||||
this.married = married;
|
||||
this.position = position;
|
||||
this.mainSkill = mainSkill;
|
||||
this.otherSkills = otherSkills;
|
||||
this.password = password;
|
||||
this.level = level;
|
||||
this.comment = comment;
|
||||
}
|
||||
public Employee(Long empId, String firstName, String lastName, Date birthDate, Float salary, boolean married, String position, Skill mainSkill, List otherSkills, String password, String level, String comment) {
|
||||
this.empId = empId;
|
||||
this.firstName = firstName;
|
||||
this.lastName = lastName;
|
||||
this.birthDate = birthDate;
|
||||
this.salary = salary;
|
||||
this.married = married;
|
||||
this.position = position;
|
||||
this.mainSkill = mainSkill;
|
||||
this.otherSkills = otherSkills;
|
||||
this.password = password;
|
||||
this.level = level;
|
||||
this.comment = comment;
|
||||
}
|
||||
|
||||
public Long getEmpId() {
|
||||
return empId;
|
||||
}
|
||||
public Long getEmpId() {
|
||||
return empId;
|
||||
}
|
||||
|
||||
public void setEmpId(Long empId) {
|
||||
this.empId = empId;
|
||||
}
|
||||
public void setEmpId(Long empId) {
|
||||
this.empId = empId;
|
||||
}
|
||||
|
||||
public Serializable getId() {
|
||||
return getEmpId();
|
||||
}
|
||||
public Serializable getId() {
|
||||
return getEmpId();
|
||||
}
|
||||
|
||||
public void setId(Serializable id) {
|
||||
setEmpId((Long) id);
|
||||
}
|
||||
public void setId(Serializable id) {
|
||||
setEmpId((Long) id);
|
||||
}
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
public void setFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
public void setFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
|
||||
public void setLastName(String lastName) {
|
||||
this.lastName = lastName;
|
||||
}
|
||||
public void setLastName(String lastName) {
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
public Date getBirthDate() {
|
||||
return birthDate;
|
||||
}
|
||||
public Date getBirthDate() {
|
||||
return birthDate;
|
||||
}
|
||||
|
||||
public void setBirthDate(Date birthDate) {
|
||||
this.birthDate = birthDate;
|
||||
}
|
||||
public void setBirthDate(Date birthDate) {
|
||||
this.birthDate = birthDate;
|
||||
}
|
||||
|
||||
public Float getSalary() {
|
||||
return salary;
|
||||
}
|
||||
public Float getSalary() {
|
||||
return salary;
|
||||
}
|
||||
|
||||
public void setSalary(Float salary) {
|
||||
this.salary = salary;
|
||||
}
|
||||
public void setSalary(Float salary) {
|
||||
this.salary = salary;
|
||||
}
|
||||
|
||||
public boolean isMarried() {
|
||||
return married;
|
||||
}
|
||||
public boolean isMarried() {
|
||||
return married;
|
||||
}
|
||||
|
||||
public void setMarried(boolean married) {
|
||||
this.married = married;
|
||||
}
|
||||
public void setMarried(boolean married) {
|
||||
this.married = married;
|
||||
}
|
||||
|
||||
public String getPosition() {
|
||||
return position;
|
||||
}
|
||||
public String getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public void setPosition(String position) {
|
||||
this.position = position;
|
||||
}
|
||||
public void setPosition(String position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
public Skill getMainSkill() {
|
||||
return mainSkill;
|
||||
}
|
||||
public Skill getMainSkill() {
|
||||
return mainSkill;
|
||||
}
|
||||
|
||||
public void setMainSkill(Skill mainSkill) {
|
||||
this.mainSkill = mainSkill;
|
||||
}
|
||||
public void setMainSkill(Skill mainSkill) {
|
||||
this.mainSkill = mainSkill;
|
||||
}
|
||||
|
||||
public List getOtherSkills() {
|
||||
return otherSkills;
|
||||
}
|
||||
public List getOtherSkills() {
|
||||
return otherSkills;
|
||||
}
|
||||
|
||||
public void setOtherSkills(List otherSkills) {
|
||||
this.otherSkills = otherSkills;
|
||||
}
|
||||
public void setOtherSkills(List otherSkills) {
|
||||
this.otherSkills = otherSkills;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getLevel() {
|
||||
return level;
|
||||
}
|
||||
public String getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public void setLevel(String level) {
|
||||
this.level = level;
|
||||
}
|
||||
public void setLevel(String level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
public String getComment() {
|
||||
return comment;
|
||||
}
|
||||
public String getComment() {
|
||||
return comment;
|
||||
}
|
||||
|
||||
public void setComment(String comment) {
|
||||
this.comment = comment;
|
||||
}
|
||||
public void setComment(String comment) {
|
||||
this.comment = comment;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,13 +24,12 @@ import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* IdEntity. Interface.
|
||||
*
|
||||
*/
|
||||
|
||||
public interface IdEntity extends Serializable {
|
||||
|
||||
Serializable getId ();
|
||||
Serializable getId();
|
||||
|
||||
void setId ( Serializable id );
|
||||
void setId(Serializable id);
|
||||
|
||||
}
|
||||
|
||||
@@ -26,49 +26,48 @@ import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Skill.
|
||||
*
|
||||
*/
|
||||
|
||||
public class Skill implements IdEntity {
|
||||
|
||||
private static final long serialVersionUID = -4150317722693212439L;
|
||||
private static final long serialVersionUID = -4150317722693212439L;
|
||||
|
||||
private String name;
|
||||
private String description;
|
||||
private String name;
|
||||
private String description;
|
||||
|
||||
public Skill() {
|
||||
}
|
||||
public Skill() {
|
||||
}
|
||||
|
||||
public Skill(String name, String description) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
}
|
||||
public Skill(String name, String description) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = StringEscapeUtils.escapeEcmaScript(StringEscapeUtils.escapeHtml4(name));
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = StringEscapeUtils.escapeEcmaScript(StringEscapeUtils.escapeHtml4(name));
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = StringEscapeUtils.escapeEcmaScript(StringEscapeUtils.escapeHtml4(description));
|
||||
}
|
||||
public void setDescription(String description) {
|
||||
this.description = StringEscapeUtils.escapeEcmaScript(StringEscapeUtils.escapeHtml4(description));
|
||||
}
|
||||
|
||||
public Serializable getId() {
|
||||
return getName();
|
||||
}
|
||||
public Serializable getId() {
|
||||
return getName();
|
||||
}
|
||||
|
||||
public void setId(Serializable id) {
|
||||
setName((String) id);
|
||||
}
|
||||
public void setId(Serializable id) {
|
||||
setName((String) id);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return getName();
|
||||
}
|
||||
public String toString() {
|
||||
return getName();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,39 +24,45 @@ import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* A model class to be used by the simple Model-Driven example.
|
||||
*
|
||||
*/
|
||||
public class Gangster implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 3688389475320294992L;
|
||||
private static final long serialVersionUID = 3688389475320294992L;
|
||||
|
||||
private String name;
|
||||
private int age;
|
||||
private String description;
|
||||
private boolean bustedBefore;
|
||||
private String name;
|
||||
private int age;
|
||||
private String description;
|
||||
private boolean bustedBefore;
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
public boolean isBustedBefore() {
|
||||
return bustedBefore;
|
||||
}
|
||||
public void setBustedBefore(boolean bustedBefore) {
|
||||
this.bustedBefore = bustedBefore;
|
||||
}
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public boolean isBustedBefore() {
|
||||
return bustedBefore;
|
||||
}
|
||||
|
||||
public void setBustedBefore(boolean bustedBefore) {
|
||||
this.bustedBefore = bustedBefore;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
+10
-11
@@ -25,21 +25,20 @@ import com.opensymphony.xwork2.ModelDriven;
|
||||
|
||||
/**
|
||||
* Action to demonstrate simple model-driven feature of the framework.
|
||||
*
|
||||
*/
|
||||
public class ModelDrivenAction extends ActionSupport implements ModelDriven {
|
||||
|
||||
private static final long serialVersionUID = 1271130427666936592L;
|
||||
private static final long serialVersionUID = 1271130427666936592L;
|
||||
|
||||
public String input() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
public String input() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
public String execute() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
public String execute() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
public Object getModel() {
|
||||
return new Gangster();
|
||||
}
|
||||
public Object getModel() {
|
||||
return new Gangster();
|
||||
}
|
||||
}
|
||||
|
||||
+38
-47
@@ -20,68 +20,59 @@
|
||||
*/
|
||||
package org.apache.struts2.showcase.person;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
import org.apache.struts2.convention.annotation.Result;
|
||||
import org.apache.struts2.convention.annotation.Results;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.struts2.convention.annotation.ParentPackage;
|
||||
import org.apache.struts2.convention.annotation.Result;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
import org.apache.struts2.convention.annotation.Results;
|
||||
|
||||
/**
|
||||
* <code>EditPerson</code>
|
||||
*
|
||||
*/
|
||||
@Results({
|
||||
@Result(name="list", location="list-people.action", type="redirect"),
|
||||
@Result(name="input", location="new-person.ftl", type="freemarker")
|
||||
@Result(name = "list", location = "list-people.action", type = "redirect"),
|
||||
@Result(name = "input", location = "edit-person.jsp")
|
||||
})
|
||||
public class EditPersonAction extends ActionSupport {
|
||||
|
||||
private static final long serialVersionUID = 7699491775215130850L;
|
||||
private static final long serialVersionUID = 7699491775215130850L;
|
||||
|
||||
PersonManager personManager;
|
||||
List persons = new ArrayList();
|
||||
@Autowired
|
||||
private PersonManager personManager;
|
||||
private List<Person> persons = new ArrayList<Person>();
|
||||
|
||||
public void setPersonManager(PersonManager personManager) {
|
||||
this.personManager = personManager;
|
||||
}
|
||||
/**
|
||||
* A default implementation that does nothing an returns "success".
|
||||
*
|
||||
* @return {@link #INPUT}
|
||||
*/
|
||||
public String execute() throws Exception {
|
||||
persons.addAll(personManager.getPeople());
|
||||
return INPUT;
|
||||
}
|
||||
|
||||
public List getPersons() {
|
||||
return persons;
|
||||
}
|
||||
/**
|
||||
* A default implementation that does nothing an returns "success".
|
||||
*
|
||||
* @return {@link #SUCCESS}
|
||||
*/
|
||||
public String save() throws Exception {
|
||||
|
||||
public void setPersons(List persons) {
|
||||
this.persons = persons;
|
||||
}
|
||||
for (Person p : persons) {
|
||||
personManager.getPeople().remove(p);
|
||||
personManager.getPeople().add(p);
|
||||
}
|
||||
return "list";
|
||||
}
|
||||
|
||||
/**
|
||||
* A default implementation that does nothing an returns "success".
|
||||
*
|
||||
* @return {@link #SUCCESS}
|
||||
*/
|
||||
public String execute() throws Exception {
|
||||
persons.addAll(personManager.getPeople());
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* A default implementation that does nothing an returns "success".
|
||||
*
|
||||
* @return {@link #SUCCESS}
|
||||
*/
|
||||
public String save() throws Exception {
|
||||
|
||||
// Set people = personManager.getPeople();
|
||||
|
||||
for ( Iterator iter = persons.iterator(); iter.hasNext();) {
|
||||
Person p = (Person) iter.next();
|
||||
personManager.getPeople().remove(p);
|
||||
personManager.getPeople().add(p);
|
||||
}
|
||||
return "list";
|
||||
}
|
||||
public List<Person> getPersons() {
|
||||
return persons;
|
||||
}
|
||||
|
||||
public void setPersons(List<Person> persons) {
|
||||
this.persons = persons;
|
||||
}
|
||||
}
|
||||
|
||||
+19
-21
@@ -20,37 +20,35 @@
|
||||
*/
|
||||
package org.apache.struts2.showcase.person;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
import org.apache.struts2.convention.annotation.Result;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
import org.apache.struts2.convention.annotation.ParentPackage;
|
||||
import org.apache.struts2.convention.annotation.Result;
|
||||
|
||||
@Result(location="list-people.ftl", type="freemarker")
|
||||
@Result(location = "list-people.ftl", type = "freemarker")
|
||||
public class ListPeopleAction extends ActionSupport {
|
||||
|
||||
private static final long serialVersionUID = 3608017189783645371L;
|
||||
private static final long serialVersionUID = 3608017189783645371L;
|
||||
|
||||
PersonManager personManager;
|
||||
List people = new ArrayList();
|
||||
@Autowired
|
||||
private PersonManager personManager;
|
||||
|
||||
public void setPersonManager(PersonManager personManager) {
|
||||
this.personManager = personManager;
|
||||
}
|
||||
private List<Person> people = new ArrayList<Person>();
|
||||
|
||||
public String execute() {
|
||||
people.addAll(personManager.getPeople());
|
||||
public String execute() {
|
||||
people.addAll(personManager.getPeople());
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
public List getPeople() {
|
||||
return people;
|
||||
}
|
||||
public List<Person> getPeople() {
|
||||
return people;
|
||||
}
|
||||
|
||||
public int getPeopleCount() {
|
||||
return people.size();
|
||||
}
|
||||
public int getPeopleCount() {
|
||||
return people.size();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+22
-22
@@ -20,35 +20,35 @@
|
||||
*/
|
||||
package org.apache.struts2.showcase.person;
|
||||
|
||||
import org.apache.struts2.convention.annotation.ParentPackage;
|
||||
import org.apache.struts2.convention.annotation.Result;
|
||||
import org.apache.struts2.views.freemarker.FreemarkerResult;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
import org.apache.struts2.convention.annotation.Result;
|
||||
import org.apache.struts2.convention.annotation.Results;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
@Result(name="input", location="new-person.ftl", type="freemarker")
|
||||
|
||||
@Results({
|
||||
@Result(name = "list", location = "list-people.action", type = "redirect"),
|
||||
@Result(name = "input", location = "new-person.ftl", type = "freemarker")
|
||||
})
|
||||
public class NewPersonAction extends ActionSupport {
|
||||
|
||||
private static final long serialVersionUID = 200410824352645515L;
|
||||
private static final long serialVersionUID = 200410824352645515L;
|
||||
|
||||
PersonManager personManager;
|
||||
Person person;
|
||||
@Autowired
|
||||
private PersonManager personManager;
|
||||
private Person person;
|
||||
|
||||
public void setPersonManager(PersonManager personManager) {
|
||||
this.personManager = personManager;
|
||||
}
|
||||
public String execute() {
|
||||
personManager.createPerson(person);
|
||||
|
||||
public String execute() {
|
||||
personManager.createPerson(person);
|
||||
return "list";
|
||||
}
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
public Person getPerson() {
|
||||
return person;
|
||||
}
|
||||
|
||||
public Person getPerson() {
|
||||
return person;
|
||||
}
|
||||
|
||||
public void setPerson(Person person) {
|
||||
this.person = person;
|
||||
}
|
||||
public void setPerson(Person person) {
|
||||
this.person = person;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,67 +20,65 @@
|
||||
*/
|
||||
package org.apache.struts2.showcase.person;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class Person {
|
||||
Long id;
|
||||
String name;
|
||||
String lastName;
|
||||
private Long id;
|
||||
private String name;
|
||||
private String lastName;
|
||||
|
||||
public Person() {
|
||||
}
|
||||
public Person() {
|
||||
}
|
||||
|
||||
public Person(Long id, String name, String lastName) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.lastName = lastName;
|
||||
}
|
||||
public Person(Long id, String name, String lastName) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
|
||||
public void setLastName(String lastName) {
|
||||
this.lastName = lastName;
|
||||
}
|
||||
public void setLastName(String lastName) {
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
final Person person = (Person) o;
|
||||
final Person person = (Person) o;
|
||||
|
||||
if (id != null ? !id.equals(person.id) : person.id != null) return false;
|
||||
if (id != null ? !id.equals(person.id) : person.id != null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return (id != null ? id.hashCode() : 0);
|
||||
}
|
||||
public int hashCode() {
|
||||
return (id != null ? id.hashCode() : 0);
|
||||
}
|
||||
|
||||
|
||||
public String toString() {
|
||||
return "Person{" +
|
||||
"id=" + id +
|
||||
", name='" + name + '\'' +
|
||||
", lastName='" + lastName + '\'' +
|
||||
'}';
|
||||
}
|
||||
public String toString() {
|
||||
return "Person{" +
|
||||
"id=" + id +
|
||||
", name='" + name + '\'' +
|
||||
", lastName='" + lastName + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,39 +20,40 @@
|
||||
*/
|
||||
package org.apache.struts2.showcase.person;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
*/
|
||||
@Service
|
||||
public class PersonManager {
|
||||
private static Set people = new HashSet(5);
|
||||
private static long COUNT = 5;
|
||||
private static Set<Person> people = new HashSet<Person>(5);
|
||||
private static long COUNT = 5;
|
||||
|
||||
static {
|
||||
// create some imaginary persons
|
||||
Person p1 = new Person(new Long(1), "Patrick", "Lightbuddie");
|
||||
Person p2 = new Person(new Long(2), "Jason", "Carrora");
|
||||
Person p3 = new Person(new Long(3), "Alexandru", "Papesco");
|
||||
Person p4 = new Person(new Long(4), "Jay", "Boss");
|
||||
Person p5 = new Person(new Long(5), "Rainer", "Hermanos");
|
||||
people.add(p1);
|
||||
people.add(p2);
|
||||
people.add(p3);
|
||||
people.add(p4);
|
||||
people.add(p5);
|
||||
}
|
||||
static {
|
||||
// create some imaginary persons
|
||||
Person p1 = new Person(new Long(1), "Patrick", "Lightbuddie");
|
||||
Person p2 = new Person(new Long(2), "Jason", "Carrora");
|
||||
Person p3 = new Person(new Long(3), "Alexandru", "Papesco");
|
||||
Person p4 = new Person(new Long(4), "Jay", "Boss");
|
||||
Person p5 = new Person(new Long(5), "Rainer", "Hermanos");
|
||||
people.add(p1);
|
||||
people.add(p2);
|
||||
people.add(p3);
|
||||
people.add(p4);
|
||||
people.add(p5);
|
||||
}
|
||||
|
||||
public void createPerson(Person person) {
|
||||
person.setId(new Long(++COUNT));
|
||||
people.add(person);
|
||||
}
|
||||
public void createPerson(Person person) {
|
||||
person.setId(new Long(++COUNT));
|
||||
people.add(person);
|
||||
}
|
||||
|
||||
public void updatePerson(Person person) {
|
||||
people.add(person);
|
||||
}
|
||||
public void updatePerson(Person person) {
|
||||
people.add(person);
|
||||
}
|
||||
|
||||
public Set getPeople() {
|
||||
return people;
|
||||
}
|
||||
public Set<Person> getPeople() {
|
||||
return people;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
@ParentPackage("person")
|
||||
@Namespace("/person")
|
||||
package org.apache.struts2.showcase.person;
|
||||
@Namespace("/person") package org.apache.struts2.showcase.person;
|
||||
|
||||
import org.apache.struts2.convention.annotation.Namespace;
|
||||
import org.apache.struts2.convention.annotation.ParentPackage;
|
||||
|
||||
+167
-171
@@ -20,6 +20,12 @@
|
||||
*/
|
||||
package org.apache.struts2.showcase.source;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
import com.opensymphony.xwork2.util.ClassLoaderUtil;
|
||||
import org.apache.struts2.ServletActionContext;
|
||||
import org.apache.struts2.util.ServletContextAware;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@@ -29,211 +35,201 @@ import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.struts2.ServletActionContext;
|
||||
import org.apache.struts2.util.ServletContextAware;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
import com.opensymphony.xwork2.util.ClassLoaderUtil;
|
||||
|
||||
/**
|
||||
* Processes configuration, page, and action class paths to create snippets
|
||||
* of the files for display.
|
||||
*/
|
||||
public class ViewSourceAction extends ActionSupport implements ServletContextAware {
|
||||
|
||||
private String page;
|
||||
private String className;
|
||||
private String config;
|
||||
private String page;
|
||||
private String className;
|
||||
private String config;
|
||||
|
||||
private List pageLines;
|
||||
private List classLines;
|
||||
private List configLines;
|
||||
private List pageLines;
|
||||
private List classLines;
|
||||
private List configLines;
|
||||
|
||||
private int configLine;
|
||||
private int padding = 10;
|
||||
private int configLine;
|
||||
private int padding = 10;
|
||||
|
||||
private ServletContext servletContext;
|
||||
private ServletContext servletContext;
|
||||
|
||||
public String execute() throws MalformedURLException, IOException {
|
||||
public String execute() throws MalformedURLException, IOException {
|
||||
|
||||
if (page != null) {
|
||||
if (page != null) {
|
||||
|
||||
InputStream in = ClassLoaderUtil.getResourceAsStream(page.substring(page.indexOf("//")+1), getClass());
|
||||
page = page.replace("//", "/");
|
||||
InputStream in = ClassLoaderUtil.getResourceAsStream(page.substring(page.indexOf("//") + 1), getClass());
|
||||
page = page.replace("//", "/");
|
||||
|
||||
if (in == null) {
|
||||
in = servletContext.getResourceAsStream(page);
|
||||
while (in == null && page.indexOf('/', 1) > 0) {
|
||||
page = page.substring(page.indexOf('/', 1));
|
||||
in = servletContext.getResourceAsStream(page);
|
||||
}
|
||||
}
|
||||
pageLines = read(in, -1);
|
||||
if (in == null) {
|
||||
in = servletContext.getResourceAsStream(page);
|
||||
while (in == null && page.indexOf('/', 1) > 0) {
|
||||
page = page.substring(page.indexOf('/', 1));
|
||||
in = servletContext.getResourceAsStream(page);
|
||||
}
|
||||
}
|
||||
pageLines = read(in, -1);
|
||||
|
||||
if (in != null) {
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
if (in != null) {
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
|
||||
if (className != null) {
|
||||
className = "/"+className.replace('.', '/') + ".java";
|
||||
InputStream in = getClass().getResourceAsStream(className);
|
||||
if (in == null) {
|
||||
in = servletContext.getResourceAsStream("/WEB-INF/src"+className);
|
||||
}
|
||||
classLines = read(in, -1);
|
||||
if (className != null) {
|
||||
className = "/" + className.replace('.', '/') + ".java";
|
||||
InputStream in = getClass().getResourceAsStream(className);
|
||||
if (in == null) {
|
||||
in = servletContext.getResourceAsStream("/WEB-INF/src" + className);
|
||||
}
|
||||
classLines = read(in, -1);
|
||||
|
||||
if (in != null) {
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
if (in != null) {
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
|
||||
String rootPath = ServletActionContext.getServletContext().getRealPath("/");
|
||||
|
||||
if (config != null && (rootPath == null || config.startsWith(rootPath))) {
|
||||
int pos = config.lastIndexOf(':');
|
||||
configLine = Integer.parseInt(config.substring(pos+1));
|
||||
config = config.substring(0, pos).replace("//", "/");
|
||||
configLines = read(new URL(config).openStream(), configLine);
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
String rootPath = ServletActionContext.getServletContext().getRealPath("/");
|
||||
|
||||
if (config != null && (rootPath == null || config.startsWith(rootPath))) {
|
||||
int pos = config.lastIndexOf(':');
|
||||
configLine = Integer.parseInt(config.substring(pos + 1));
|
||||
config = config.substring(0, pos).replace("//", "/");
|
||||
configLines = read(new URL(config).openStream(), configLine);
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param className the className to set
|
||||
*/
|
||||
public void setClassName(String className) {
|
||||
if (className != null && className.trim().length()>0) {
|
||||
this.className = className;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @param className the className to set
|
||||
*/
|
||||
public void setClassName(String className) {
|
||||
if (className != null && className.trim().length() > 0) {
|
||||
this.className = className;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param config the config to set
|
||||
*/
|
||||
public void setConfig(String config) {
|
||||
if (config != null && config.trim().length()>0) {
|
||||
this.config = config;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @param config the config to set
|
||||
*/
|
||||
public void setConfig(String config) {
|
||||
if (config != null && config.trim().length() > 0) {
|
||||
this.config = config;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param page the page to set
|
||||
*/
|
||||
public void setPage(String page) {
|
||||
if (page != null && page.trim().length()>0) {
|
||||
this.page = page;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @param page the page to set
|
||||
*/
|
||||
public void setPage(String page) {
|
||||
if (page != null && page.trim().length() > 0) {
|
||||
this.page = page;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param padding the padding to set
|
||||
*/
|
||||
public void setPadding(int padding) {
|
||||
this.padding = padding;
|
||||
}
|
||||
/**
|
||||
* @param padding the padding to set
|
||||
*/
|
||||
public void setPadding(int padding) {
|
||||
this.padding = padding;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the classLines
|
||||
*/
|
||||
public List getClassLines() {
|
||||
return classLines;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the classLines
|
||||
*/
|
||||
public List getClassLines() {
|
||||
return classLines;
|
||||
}
|
||||
/**
|
||||
* @return the configLines
|
||||
*/
|
||||
public List getConfigLines() {
|
||||
return configLines;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the configLines
|
||||
*/
|
||||
public List getConfigLines() {
|
||||
return configLines;
|
||||
}
|
||||
/**
|
||||
* @return the pageLines
|
||||
*/
|
||||
public List getPageLines() {
|
||||
return pageLines;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the pageLines
|
||||
*/
|
||||
public List getPageLines() {
|
||||
return pageLines;
|
||||
}
|
||||
/**
|
||||
* @return the className
|
||||
*/
|
||||
public String getClassName() {
|
||||
return className;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the className
|
||||
*/
|
||||
public String getClassName() {
|
||||
return className;
|
||||
}
|
||||
/**
|
||||
* @return the config
|
||||
*/
|
||||
public String getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the config
|
||||
*/
|
||||
public String getConfig() {
|
||||
return config;
|
||||
}
|
||||
/**
|
||||
* @return the page
|
||||
*/
|
||||
public String getPage() {
|
||||
return page;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the page
|
||||
*/
|
||||
public String getPage() {
|
||||
return page;
|
||||
}
|
||||
/**
|
||||
* @return the configLine
|
||||
*/
|
||||
public int getConfigLine() {
|
||||
return configLine;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the configLine
|
||||
*/
|
||||
public int getConfigLine() {
|
||||
return configLine;
|
||||
}
|
||||
/**
|
||||
* @return the padding
|
||||
*/
|
||||
public int getPadding() {
|
||||
return padding;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the padding
|
||||
*/
|
||||
public int getPadding() {
|
||||
return padding;
|
||||
}
|
||||
/**
|
||||
* Reads in a strea, optionally only including the target line number
|
||||
* and its padding
|
||||
*
|
||||
* @param in The input stream
|
||||
* @param targetLineNumber The target line number, negative to read all
|
||||
* @return A list of lines
|
||||
*/
|
||||
private List read(InputStream in, int targetLineNumber) {
|
||||
List snippet = null;
|
||||
if (in != null) {
|
||||
snippet = new ArrayList();
|
||||
int startLine = 0;
|
||||
int endLine = Integer.MAX_VALUE;
|
||||
if (targetLineNumber > 0) {
|
||||
startLine = targetLineNumber - padding;
|
||||
endLine = targetLineNumber + padding;
|
||||
}
|
||||
try {
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
|
||||
|
||||
/**
|
||||
* Reads in a strea, optionally only including the target line number
|
||||
* and its padding
|
||||
*
|
||||
* @param in The input stream
|
||||
* @param targetLineNumber The target line number, negative to read all
|
||||
* @return A list of lines
|
||||
*/
|
||||
private List read(InputStream in, int targetLineNumber) {
|
||||
List snippet = null;
|
||||
if (in != null) {
|
||||
snippet = new ArrayList();
|
||||
int startLine = 0;
|
||||
int endLine = Integer.MAX_VALUE;
|
||||
if (targetLineNumber > 0) {
|
||||
startLine = targetLineNumber - padding;
|
||||
endLine = targetLineNumber + padding;
|
||||
}
|
||||
try {
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
|
||||
int lineno = 0;
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
lineno++;
|
||||
if (lineno >= startLine && lineno <= endLine) {
|
||||
snippet.add(line);
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
// ignoring as snippet not available isn't a big deal
|
||||
}
|
||||
}
|
||||
return snippet;
|
||||
}
|
||||
|
||||
int lineno = 0;
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
lineno++;
|
||||
if (lineno >= startLine && lineno <= endLine) {
|
||||
snippet.add(line);
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
// ignoring as snippet not available isn't a big deal
|
||||
}
|
||||
}
|
||||
return snippet;
|
||||
}
|
||||
|
||||
public void setServletContext(ServletContext arg0) {
|
||||
this.servletContext = arg0;
|
||||
}
|
||||
public void setServletContext(ServletContext arg0) {
|
||||
this.servletContext = arg0;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
+15
-10
@@ -24,19 +24,24 @@ import com.opensymphony.xwork2.ActionSupport;
|
||||
|
||||
public class SubmitAction extends ActionSupport {
|
||||
|
||||
private static final long serialVersionUID = -7832803019378213087L;
|
||||
private static final long serialVersionUID = -7832803019378213087L;
|
||||
|
||||
private String text;
|
||||
private String text;
|
||||
|
||||
public String getText() { return text; }
|
||||
public void setText(String text) { this.text = text; }
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public String execute() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
public void setText(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public String alternateMethod() {
|
||||
return "methodPrefixResult";
|
||||
}
|
||||
public String execute() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
public String alternateMethod() {
|
||||
return "methodPrefixResult";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+7
-7
@@ -26,13 +26,13 @@ import com.opensymphony.xwork2.ActionSupport;
|
||||
*/
|
||||
public class ActionTagDemo extends ActionSupport {
|
||||
|
||||
private static final long serialVersionUID = -2749145880590245184L;
|
||||
private static final long serialVersionUID = -2749145880590245184L;
|
||||
|
||||
public String show() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
public String show() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
public String doInclude() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
public String doInclude() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
+35
-39
@@ -28,53 +28,49 @@ import com.opensymphony.xwork2.Validateable;
|
||||
*/
|
||||
public class AppendIteratorTagDemo extends ActionSupport implements Validateable {
|
||||
|
||||
private static final long serialVersionUID = -6525059998526094664L;
|
||||
private static final long serialVersionUID = -6525059998526094664L;
|
||||
|
||||
private String iteratorValue1;
|
||||
private String iteratorValue2;
|
||||
private String iteratorValue1;
|
||||
private String iteratorValue2;
|
||||
|
||||
|
||||
public void validate() {
|
||||
if (iteratorValue1 == null || iteratorValue1.trim().length() <= 0 ) {
|
||||
addFieldError("iteratorValue1", "iterator value 1 cannot be empty");
|
||||
}
|
||||
else if (iteratorValue1.trim().indexOf(",") <= 0) {
|
||||
addFieldError("iteratorValue1", "iterator value 1 needs to be comma separated");
|
||||
}
|
||||
if (iteratorValue2 == null || iteratorValue2.trim().length() <= 0) {
|
||||
addFieldError("iteratorValue2", "iterator value 2 cannot be empty");
|
||||
}
|
||||
else if (iteratorValue2.trim().indexOf(",") <= 0) {
|
||||
addFieldError("iteratorValue2", "iterator value 2 needs to be comma separated");
|
||||
}
|
||||
}
|
||||
public void validate() {
|
||||
if (iteratorValue1 == null || iteratorValue1.trim().length() <= 0) {
|
||||
addFieldError("iteratorValue1", "iterator value 1 cannot be empty");
|
||||
} else if (iteratorValue1.trim().indexOf(",") <= 0) {
|
||||
addFieldError("iteratorValue1", "iterator value 1 needs to be comma separated");
|
||||
}
|
||||
if (iteratorValue2 == null || iteratorValue2.trim().length() <= 0) {
|
||||
addFieldError("iteratorValue2", "iterator value 2 cannot be empty");
|
||||
} else if (iteratorValue2.trim().indexOf(",") <= 0) {
|
||||
addFieldError("iteratorValue2", "iterator value 2 needs to be comma separated");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public String getIteratorValue1() {
|
||||
return iteratorValue1;
|
||||
}
|
||||
|
||||
public void setIteratorValue1(String iteratorValue1) {
|
||||
this.iteratorValue1 = iteratorValue1;
|
||||
}
|
||||
|
||||
|
||||
public String getIteratorValue1() {
|
||||
return iteratorValue1;
|
||||
}
|
||||
public void setIteratorValue1(String iteratorValue1) {
|
||||
this.iteratorValue1 = iteratorValue1;
|
||||
}
|
||||
public String getIteratorValue2() {
|
||||
return iteratorValue2;
|
||||
}
|
||||
|
||||
public void setIteratorValue2(String iteratorValue2) {
|
||||
this.iteratorValue2 = iteratorValue2;
|
||||
}
|
||||
|
||||
|
||||
public String input() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
public String getIteratorValue2() {
|
||||
return iteratorValue2;
|
||||
}
|
||||
public void setIteratorValue2(String iteratorValue2) {
|
||||
this.iteratorValue2 = iteratorValue2;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String input() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
public String submit() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
public String submit() throws Exception {
|
||||
return SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user