8 Replies Latest reply on Apr 9, 2006 5:15 AM by gilboay

    RenderResponse.createActionUrl() does not work

    gilboay

      hi,

      I am using JBoss Portal v2.2 (default package bundled with Jboss AS).

      I am running a sample portlet, in which in EDIT mode the user gets a text field to set the portlet's title. I use a form (drawn in the doEdit() method), which action is obtained by calling RenderResponse.createActionUrl().

      <form action=<Generated URL>>
      <input type=text name=title>
      <input type=submit>
      < /form>

      The URL generated looks something like this:

      /portal/index.html?ctrl:cmd=action&ctrl:window=default.myPage.myPortlet

      This is the way to do it according to all the literature i've read on this.

      However, this did not work. When submitting the form, the query string was trunctuated, and the result was a URL that looks like this (I see this using Live-HTTP-Headers):

      /portal/index.html?title=...

      And thus the request was never directed to the portlet by the portal. The only way for this to work was to manually add 2 (two) hidden inputs to the form as follows:

      <form action=<Generated URL>>
      <input type=text name=title>

      <input type=hidden name="ctrl:cmd" value="action">
      <input type=hidden name="ctrl:window" value="default.myPage.myPortlet">


      <input type=submit>
      < /form>

      What did I do wrong?

        • 1. Re: RenderResponse.createActionUrl() does not work

          is your form using POST or GET ?

          try <form method='POST' action='....>

          • 2. Re: RenderResponse.createActionUrl() does not work
            gilboay

            hi -

            i've tried both GET and POST - the same behaviour happens for both of them.

            Any ideas?

            • 3. Re: RenderResponse.createActionUrl() does not work
              theute

              What is <Generated URL> ?

              • 4. Re: RenderResponse.createActionUrl() does not work
                gilboay

                <Generated URL> means the actual url returned by the RenderResponse.createActionURL() method.

                • 5. Re: RenderResponse.createActionUrl() does not work
                  theute

                  Why not using the portlet tag <portlet:actionURL/> ?

                  And at least please show us exactly the code you write, since it seems that there is a problem with it.

                  Help us help you

                  • 6. Re: RenderResponse.createActionUrl() does not work
                    gilboay

                    hi,


                    I'd rather not used JSP at this point.

                    I'm trying this with a sample code from the book "Building Portals with the Java Portlet API" (Apress), by Jeff Linwood & Dave Minter.

                    Here is the full listing of the portlet class:



                    package com.portalbook.portlets;
                    
                    import java.io.IOException;
                    import java.io.Writer;
                    
                    import javax.portlet.ActionRequest;
                    import javax.portlet.ActionResponse;
                    import javax.portlet.GenericPortlet;
                    import javax.portlet.PortletException;
                    import javax.portlet.RenderRequest;
                    import javax.portlet.RenderResponse;
                    
                    public class AdvancedPortlet extends GenericPortlet
                    {
                    
                     protected void doEdit(
                     RenderRequest renderRequest,
                     RenderResponse renderResponse)
                     throws PortletException, IOException
                     {
                     renderResponse.setContentType("text/html");
                    
                     Writer writer = renderResponse.getWriter();
                    
                     //get the existing parameters to use as defaults.
                     String title = renderRequest.getParameter("title");
                     String contents = renderRequest.getParameter("contents");
                    
                     if (title == null)
                     {
                     title = "";
                     }
                    
                     if (contents == null)
                     {
                     contents = "";
                     }
                    
                     writer.write("<H1>Portlet Settings</H1>");
                     writer.write("<FORM ACTION=");
                     writer.write(renderResponse.createActionURL().toString());
                     writer.write(">");
                    
                     writer.write(
                     "Title: <INPUT TYPE=text NAME=title VALUE='" + title + "' SIZE=25>");
                     writer.write(
                     "Contents: <INPUT TYPE=text NAME=contents VALUE= '"
                     + contents
                     + "' SIZE=25>");
                     writer.write("<P>");
                     writer.write("<INPUT TYPE=submit>");
                     writer.write("</FORM>");
                    
                     }
                    
                     protected void doHelp(
                     RenderRequest renderRequest,
                     RenderResponse renderResponse)
                     throws PortletException, IOException
                     {
                     //return a helpful message
                     renderResponse.setContentType("text/html");
                    
                     Writer writer = renderResponse.getWriter();
                     writer.write(
                     "This portlet allows you to change its content and title.");
                     }
                    
                     protected void doView(
                     RenderRequest renderRequest,
                     RenderResponse renderResponse)
                     throws PortletException, IOException
                     {
                     renderResponse.setContentType("text/html");
                     Writer writer = renderResponse.getWriter();
                     String contents = renderRequest.getParameter("contents");
                     if (contents != null)
                     {
                     writer.write(contents);
                     }
                     else
                     {
                     //return the default contents
                     writer.write("This is the default portlet contents. To change ");
                     writer.write("this message, edit the portlet's settings.");
                     }
                    
                     writer.write("<p>");
                     writer.write(
                     "<IMG SRC="
                     + renderResponse.encodeURL(
                     renderRequest.getContextPath() + "/images/picture.jpg")
                     + ">");
                    
                     writer.write("<p>");
                     writer.write(
                     "<IMG SRC=http://www.greenninja.com/images/teton1-small.jpg>");
                     }
                    
                     protected String getTitle(RenderRequest renderRequest)
                     {
                     String title = renderRequest.getParameter("title");
                     if (title != null)
                     {
                     return title;
                     }
                     //else return a default title, if we don't have one set yet.
                     return "Advanced Portlet";
                     }
                    
                     public void processAction(
                     ActionRequest actionRequest,
                     ActionResponse actionResponse)
                     throws PortletException, IOException
                     {
                     //check for parameters
                     String title = actionRequest.getParameter("title");
                     if (title != null)
                     {
                     actionResponse.setRenderParameter("title", title);
                     }
                    
                     String contents = actionRequest.getParameter("contents");
                     if (contents != null)
                     {
                     actionResponse.setRenderParameter("contents", contents);
                     }
                     }
                    
                    }
                    


                    The doEdit() section works only if I apply the work-around described in the 1st event.

                    thanx :)




                    • 7. Re: RenderResponse.createActionUrl() does not work

                      I'm not sure if this is a forum problem, or if you forgot the quotes around all the attribute values that you write.

                      instead of:

                      writer.write("<FORM ACTION=");
                       writer.write(renderResponse.createActionURL().toString());
                       writer.write(">");
                      



                      try
                      writer.write("<FORM ACTION=\"");
                       writer.write(renderResponse.createActionURL().toString());
                       writer.write("\">");
                      


                      ...apply the same change for the other attributes.


                      • 8. Re: RenderResponse.createActionUrl() does not work
                        gilboay

                        hi again -

                        This is not a markup problem. I've modified the code to generate valid HTML (enclosing all attributes with double quotes). The problem is with the actual value of the action attribute.