Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f2e85e2
commit bf582e1
Showing
8 changed files
with
261 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>com.exoplatform</groupId> | ||
<artifactId>simple-strut2</artifactId> | ||
<packaging>war</packaging> | ||
<name>My Portlet Application</name> | ||
<version>1.0</version> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>javax.portlet</groupId> | ||
<artifactId>portlet-api</artifactId> | ||
<version>1.0</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>javax.servlet</groupId> | ||
<artifactId>servlet-api</artifactId> | ||
<version>2.5</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.struts</groupId> | ||
<artifactId>struts2-portlet-plugin</artifactId> | ||
<version>2.1.6</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<source>1.5</source> | ||
<target>1.5</target> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
44 changes: 44 additions & 0 deletions
44
simple-strut2/src/main/java/com/exoplatform/HelloAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.exoplatform; | ||
|
||
import javax.portlet.PortletPreferences; | ||
|
||
import org.apache.struts2.dispatcher.DefaultActionSupport; | ||
import org.apache.struts2.portlet.interceptor.PortletPreferencesAware; | ||
|
||
/** | ||
* @author <a href="kienna@exoplatform.com">Kien Nguyen</a> | ||
* @version $Revision$ | ||
*/ | ||
public class HelloAction extends DefaultActionSupport implements PortletPreferencesAware | ||
{ | ||
private static final long serialVersionUID = 1L; | ||
|
||
private String firstName; | ||
|
||
private String lastName; | ||
|
||
private PortletPreferences preferences; | ||
|
||
public String getFirstName() | ||
{ | ||
return firstName; | ||
} | ||
|
||
public String getLastName() | ||
{ | ||
return lastName; | ||
} | ||
|
||
public void setPortletPreferences(PortletPreferences preferences) | ||
{ | ||
this.preferences = preferences; | ||
} | ||
|
||
@Override | ||
public String execute() throws Exception | ||
{ | ||
firstName = preferences.getValue("firstName", ""); | ||
lastName = preferences.getValue("lastName", ""); | ||
return SUCCESS; | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
simple-strut2/src/main/java/com/exoplatform/UpdateNameAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package com.exoplatform; | ||
|
||
import javax.portlet.PortletPreferences; | ||
|
||
import org.apache.struts2.dispatcher.DefaultActionSupport; | ||
import org.apache.struts2.portlet.interceptor.PortletPreferencesAware; | ||
|
||
/** | ||
* @author <a href="kienna@exoplatform.com">Kien Nguyen</a> | ||
* @version $Revision$ | ||
*/ | ||
public class UpdateNameAction extends DefaultActionSupport implements PortletPreferencesAware | ||
{ | ||
private static final long serialVersionUID = 1L; | ||
|
||
private String firstName; | ||
|
||
private String lastName; | ||
|
||
private PortletPreferences preferences; | ||
|
||
@Override | ||
public String execute() throws Exception | ||
{ | ||
preferences.setValue("firstName", firstName); | ||
preferences.setValue("lastName", lastName); | ||
preferences.store(); | ||
getActionMessages().add("Name updated"); | ||
return SUCCESS; | ||
} | ||
|
||
@Override | ||
public String input() throws Exception | ||
{ | ||
firstName = preferences.getValue("firstName", ""); | ||
lastName = preferences.getValue("lastName", ""); | ||
return INPUT; | ||
} | ||
|
||
public void setPortletPreferences(PortletPreferences preferences) | ||
{ | ||
this.preferences = preferences; | ||
} | ||
|
||
public void setFirstName(String firstName) | ||
{ | ||
this.firstName = firstName; | ||
} | ||
|
||
public String getFirstName() | ||
{ | ||
return firstName; | ||
} | ||
|
||
public void setLastName(String lastName) | ||
{ | ||
this.lastName = lastName; | ||
} | ||
|
||
public String getLastName() | ||
{ | ||
return lastName; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<!DOCTYPE struts PUBLIC | ||
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" | ||
"http://struts.apache.org/dtds/struts-2.0.dtd"> | ||
|
||
<struts> | ||
<package name="default" extends="struts-portlet-default" namespace="/view"> | ||
<action name="index" class="com.exoplatform.HelloAction"> | ||
<result>/WEB-INF/jsp/view/index.jsp</result> | ||
</action> | ||
</package> | ||
|
||
<package name="edit" extends="struts-portlet-default" namespace="/edit"> | ||
|
||
<action name="index" class="com.exoplatform.UpdateNameAction"> | ||
<result type="redirectAction"> | ||
<param name="actionName">index</param> | ||
<param name="portletMode">view</param> | ||
</result> | ||
<result name="input">/WEB-INF/jsp/edit/index.jsp</result> | ||
</action> | ||
</package> | ||
</struts> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<%@ taglib prefix="s" uri="/struts-tags" %> | ||
|
||
<div>you are logged in <%=request.getRemoteUser() %></div> | ||
<h2>Your name:</h2> | ||
|
||
<s:form action="index"> | ||
<table> | ||
<s:textfield name="firstName" label="First name"/> | ||
<s:textfield name="lastName" label="Last name"/> | ||
<s:submit value="Update"/> | ||
</table> | ||
</s:form> | ||
|
||
<s:actionmessage/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<%@ taglib prefix="s" uri="/struts-tags" %> | ||
|
||
<div>you are logged in <%=request.getRemoteUser() %></div> | ||
<s:if test='%{firstName != "" || lastName != ""}'> | ||
<h2>Hello, <s:property value="firstName"/> <s:property value="lastName"/> | ||
</s:if> | ||
<s:else> | ||
<b>No name set. Go to <a href="<s:url action="index" method="input" portletMode="edit"/>">edit mode</a> to set your name</b> | ||
</s:else> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<portlet-app | ||
version="1.0" | ||
xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd" | ||
id="strut2"> | ||
|
||
<portlet id="HelloPortlet"> | ||
<description xml:lang="EN">Simple hello world portlet</description> | ||
<portlet-name>HelloPortlet</portlet-name> | ||
<display-name xml:lang="EN">strut2</display-name> | ||
|
||
<portlet-class>org.apache.struts2.portlet.dispatcher.Jsr168Dispatcher</portlet-class> | ||
|
||
<!-- The namespace for the actions configured for view mode --> | ||
<init-param> | ||
<name>viewNamespace</name> | ||
<value>/view</value> | ||
</init-param> | ||
|
||
<!-- The default action to invoke in view mode. --> | ||
<init-param> | ||
<name>defaultViewAction</name> | ||
<value>index</value> | ||
</init-param> | ||
|
||
<!-- The namespace for the actions configured for edit mode --> | ||
<init-param> | ||
<name>editNamespace</name> | ||
<value>/edit</value> | ||
</init-param> | ||
|
||
<!-- The default action to invoke in edit mode. --> | ||
<init-param> | ||
<name>defaultEditAction</name> | ||
<value>index!input</value> | ||
</init-param> | ||
|
||
<expiration-cache>0</expiration-cache> | ||
|
||
<supports> | ||
<mime-type>text/html</mime-type> | ||
<portlet-mode>view</portlet-mode> | ||
<portlet-mode>edit</portlet-mode> | ||
</supports> | ||
|
||
<supported-locale>en</supported-locale> | ||
|
||
<portlet-info> | ||
<title>HelloPortlet</title> | ||
<short-title>HelloPortlet</short-title> | ||
<keywords>struts 2</keywords> | ||
</portlet-info> | ||
</portlet> | ||
|
||
</portlet-app> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> | ||
<web-app id="strut2"> | ||
<!-- Empty --> | ||
</web-app> |