• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Store portlet preferences in struts portlet

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have successfully built a portlet for liferay 4.3.6 & 5.x using struts. I am now porting this over to work in Jboss portal 2.6.6... everything is working except for the ability to store values in preferences. Liferay must be more accepting of poor code because it works fine, but jboss tells me :

Store must be called within the scope of an action request

Here is the class I'm using:

package com.portlet.test_test.action;

import java.io.IOException;
import java.security.NoSuchAlgorithmException;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletException;
import javax.portlet.PortletPreferences;
import javax.portlet.ReadOnlyException;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.portlet.ValidatorException;
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 com.test.test_test.FileCreator;



public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest req, HttpServletResponse res) {
RenderRequest pReq = (RenderRequest) req
.getAttribute("javax.portlet.request");
RenderResponse rRes = (RenderResponse) req
.getAttribute("javax.portlet.response");
PortletPreferences pr = (PortletPreferences) pReq.getPreferences();
String fwd = "portlet.test_test.view";
String alreadyOK = pr.getValue("verified", "");
String isOK = null;
String keytext = req.getParameter("licenseKey");

if ((null != keytext) && (!keytext.equals(""))) {
FileCreator fc = new FileCreator();
String success = null;
try {
success = fc.makeKeyFile(keytext);
} catch (IOException e) {
System.out.println("Error writing key file: " + e);
}
}

if ((alreadyOK == null) || (!alreadyOK.equals("1"))) {
FileReader fr = new FileReader();
try {
isOK = fr.getLines(pReq, rRes);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (ReadOnlyException e) {
e.printStackTrace();
} catch (ValidatorException e) {
e.printStackTrace();
} finally {
if ((null != isOK) && (isOK.equals("1"))) {
try {
pr.setValue("verified", "1");
// pr.store();
return mapping.findForward(fwd);
} catch (ReadOnlyException e) {
e.printStackTrace();
}
}
}
} else {
isOK = "1";
}
if ((null == isOK) || (!isOK.equals("1"))) {
fwd = "portlet.test_test.license";
}
return mapping.findForward(fwd);
}
}



Why does jboss hate me?

Thanks for your help..

Bryancan
 
Bryan Cantwell
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
btw somehow I failed to copy over the line:

public class ViewAction extends Action {
 
reply
    Bookmark Topic Watch Topic
  • New Topic