Powered By Blogger

Monday, April 11, 2011

Developing a portlet with multiple actions

In our portlet class we need not implement our functionalities using processAction(),
We can write our own method actions.The name of the method can be whatever you want since you will be
referring to it when creating the URL


public class MyGreetingPortlet extends MVCPortlet {
public void setGreeting(
ActionRequest actionRequest, ActionResponse actionResponse)
throws IOException, PortletException {
PortletPreferences prefs = actionRequest.getPreferences();
String greeting = actionRequest.getParameter("greeting");
if (greeting != null) {
try {
prefs.setValue("greeting", greeting);
prefs.store();
}
catch(Exception e) {
SessionErrors.add(actionRequest, "error");
}
}
SessionMessages.add(actionRequest, "success");
}
public void sendEmail(
ActionRequest actionRequest, ActionResponse actionResponse)
throws IOException, PortletException {
// Add code here to send an email
}
}


The jsp element to call this is as below


No comments:

Post a Comment