Commits

Micha Kops committed 7dc5255

Annotated Portlet Example added

  • Participants
  • Parent commits ef8991d

Comments (0)

Files changed (2)

File src/main/java/com/hascode/tutorial/portlet/SimpleAnnotatedPortlet.java

+package com.hascode.tutorial.portlet;
+
+import java.io.IOException;
+import java.util.Date;
+
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.GenericPortlet;
+import javax.portlet.PortletURL;
+import javax.portlet.ProcessAction;
+import javax.portlet.RenderMode;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+
+public class SimpleAnnotatedPortlet extends GenericPortlet {
+
+	@RenderMode(name = "view")
+	public void showMeSomeText(RenderRequest req, RenderResponse res) throws IOException {
+		String theTime = req.getParameter("thetime");
+		PortletURL actionUrl = res.createActionURL();
+		actionUrl.setParameter(ActionRequest.ACTION_NAME, "mySpecialAction");
+		res.getWriter().println("The time is: " + theTime + "<br/><small><a href=\"" + actionUrl + "\">Update time</a></small>");
+	}
+
+	@ProcessAction(name = "mySpecialAction")
+	public void timeLookup(ActionRequest req, ActionResponse res) {
+		res.setRenderParameter("thetime", new Date().toString());
+	}
+}

File src/main/webapp/WEB-INF/portlet.xml

 			<qname xmlns:hc="http://www.hascode.com/portlet">hc:customMessage</qname>
 		</supported-processing-event>
 	</portlet>
-	
-		<portlet>
+
+	<portlet>
 		<portlet-name>hascode-preferences-portlet</portlet-name>
 		<display-name>hascode-preferences-portlet</display-name>
 		<portlet-class>com.hascode.tutorial.portlet.SimplePreferencesReadingPortlet</portlet-class>
 		</portlet-preferences>
 	</portlet>
 
+	<portlet>
+		<portlet-name>hascode-annotation-example</portlet-name>
+		<display-name>hascode-annotation-example</display-name>
+		<portlet-class>com.hascode.tutorial.portlet.SimpleAnnotatedPortlet</portlet-class>
+		<expiration-cache>0</expiration-cache>
+		<supports>
+			<mime-type>text/html</mime-type>
+			<portlet-mode>VIEW</portlet-mode>
+		</supports>
+		<portlet-info>
+			<title>hascode-annotation-example</title>
+			<keywords>hascode-annotation-example</keywords>
+		</portlet-info>
+	</portlet>
+
 	<event-definition>
 		<qname xmlns:hc="http://www.hascode.com/portlet">hc:message</qname>
 		<value-type>java.lang.String</value-type>