Struts RequestAware and FreeMarker

Discussion in 'Java' started by Q1tum, Jun 21, 2007.

  1. Q1tum

    Q1tum Guest

    Hi all,

    I started learning JSP / Java. At the moment I have a problem and
    could not find the solution on the internet, I hope someone can reply
    to my post with a sollution:

    My problem is that I'm not able to get Post or Get variables within a
    Freemarker template file.

    I'm extending a Class that is SessionAware and RequestAware:

    public class TutorialSupport extends ActionSupport
    implements RequestAware, SessionAware {

    private Map Session = null;
    private Map Request = null;

    public Map getSession() {
    return Session;
    }

    public void setSession(Map Session) {
    this.Session = Session;
    }

    public Map getRequest() {
    return Request;
    }

    public void setRequest(Map request) {
    this.Request = request;
    }
    }

    public class MessageAction extends TutorialSupport {
    .....
    .....
    }

    In the template file I use the following to access the Session Map:

    ${Session.login.getLogin()}

    This works fine and displays my login name.

    But when I want to try the same with ${Request.id}

    The URL I used was messages.action?id=1, so I thought that $
    {Request.id} would display 1. but I get an Exception:

    Expression Request.id is undefined on line 12, column 3 in ftl/
    messages.ftl.

    When I display ${Request} in the template I get this Exception:

    Error on line 12, column 3 in ftl/messages.ftl
    Expecting a string, date or number here, Expression Request is instead
    a freemarker.ext.servlet.HttpRequestHashModel

    I hope my issue is explained good and someone can give me the solution
    about how to display POST and GET variables in a FreeMarker Template.

    Regards,

    Q1tum
     
    Q1tum, Jun 21, 2007
    #1
    1. Advertisements

  2. Q1tum

    Q1tum Guest

    On Jun 21, 4:34 pm, Q1tum <> wrote:
    > Hi all,
    >
    > I started learning JSP / Java. At the moment I have a problem and
    > could not find the solution on the internet, I hope someone can reply
    > to my post with a sollution:
    >
    > My problem is that I'm not able to get Post or Get variables within a
    > Freemarker template file.
    >
    > I'm extending a Class that is SessionAware and RequestAware:
    >
    > public class TutorialSupport extends ActionSupport
    > implements RequestAware, SessionAware {
    >
    > private Map Session = null;
    > private Map Request = null;
    >
    > public Map getSession() {
    > return Session;
    > }
    >
    > public void setSession(Map Session) {
    > this.Session = Session;
    > }
    >
    > public Map getRequest() {
    > return Request;
    > }
    >
    > public void setRequest(Map request) {
    > this.Request = request;
    > }
    >
    > }
    >
    > public class MessageAction extends TutorialSupport {
    > ....
    > ....
    >
    > }
    >
    > In the template file I use the following to access the Session Map:
    >
    > ${Session.login.getLogin()}
    >
    > This works fine and displays my login name.
    >
    > But when I want to try the same with ${Request.id}
    >
    > The URL I used was messages.action?id=1, so I thought that $
    > {Request.id} would display 1. but I get an Exception:
    >
    > Expression Request.id is undefined on line 12, column 3 in ftl/
    > messages.ftl.
    >
    > When I display ${Request} in the template I get this Exception:
    >
    > Error on line 12, column 3 in ftl/messages.ftl
    > Expecting a string, date or number here, Expression Request is instead
    > a freemarker.ext.servlet.HttpRequestHashModel
    >
    > I hope my issue is explained good and someone can give me the solution
    > about how to display POST and GET variables in a FreeMarker Template.
    >
    > Regards,
    >
    > Q1tum


    I found another solution to get all GET parameters within a FreeMarker
    template, the solution is shown below:

    Assuming that URL example.action?id=1 is used you are able to get '1'
    with the following tag: ${parameters.get('id')[0]}
     
    Q1tum, Jun 22, 2007
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Katie Wright
    Replies:
    8
    Views:
    4,760
    Andrea Desole
    Jan 7, 2005
  2. Merlijn
    Replies:
    0
    Views:
    4,416
    Merlijn
    Mar 24, 2006
  3. Chris
    Replies:
    1
    Views:
    1,558
    Oliver Wong
    Apr 15, 2006
  4. znôrt
    Replies:
    2
    Views:
    1,215
    znôrt
    Jun 25, 2003
  5. Jonathan Revusky

    [ANN] FreeMarker 2.3pre9 available

    Jonathan Revusky, Jul 22, 2003, in forum: XML
    Replies:
    0
    Views:
    564
    Jonathan Revusky
    Jul 22, 2003
  6. OTB
    Replies:
    0
    Views:
    842
  7. theog
    Replies:
    0
    Views:
    1,200
    theog
    Jul 7, 2008
  8. theog
    Replies:
    0
    Views:
    777
    theog
    Nov 13, 2008
Loading...