Announcement Announcement Module
No announcement yet.
Can you save PortletPreferences without a page refresh using AJAX? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Can you save PortletPreferences without a page refresh using AJAX?

    I'm using a portlet AbstractController.

    I use DWR to avoid page refreshes.

    I want to save my PortletPreferences (so I must do this in handleActionRequest).

    Is this possible without a page refresh?

    Maybe by remoting some spring method using DWR?

    Or can an already DWR'ed method somehow save Portal Preferences?

    Any advice appreciated...

  • #2
    I got it working by using XmlHttpRequest to post data to <portlet:actionURL/>
    Anyone have a recommended way of doing this?

    I used:

    var xmlHttp;
    try {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    } catch (e) {
    // Internet Explorer
    try {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
    try {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    } catch (e) {
    // alert("Cannot save preferences.");

    var url = "<portlet:actionURL/>";
    var data = "name=1&age=2";"POST",url,true);
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", data.length);
    xmlHttp.setRequestHeader("Connection", "close");


    • #3
      What you are doing is probably about as good as it gets in JSR 168. Normally for AJAX integration w/ Portlets you would use a Servlet that shares session state at a webapp level, but this is useless for accessing PortletPreferences, since those are portlet-scope.

      Now that JSR 286 is final and support is emerging for various portals (and is planned for Spring 3.0), you might look towards that. The ResourceRequest is exactly what you are looking for.


      • #4
        Thanks for the info we were wondering if there was a better way.