Nick Rolando
Nick Rolando

Reputation: 26157

How can I get the query string

I'm using jsf 1.1 and icefaces 1.8. I have a PartsInv.jsp page and a managed PartsInv.java bean. I've tried messing around with several classes based on google hits I've come across, and feel like I'm getting close, but I can't quite nail it. This is what I have:

HttpServletRequestWrapper hsrw;
String rcVal = hsrw.getAttribute("rc").toString();

But of course hsrw isn't properly instantiated.. I'm not really sure how to (or what to wrap it around). Any help would be appreciated.

Edit: Based on Jigar's answer, I've updated my code to the following:

    HttpServletRequest hsr = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();

    if(hsr.getAttribute("rc") != null)
    {
        try
        {
            int rc = Integer.parseInt(hsr.getAttribute("rc").toString());
            this.SOM_RC.setValue(rc);
            this.changeRC(null);
        }
        catch(NumberFormatException nfe)
        {
            this.lblStatus.setValue("eASP error, please see an administrator.");
            return;
        }
    }

Edit2: ok, so i used the wrong method. hsr.getParameter() does the trick

Upvotes: 4

Views: 7222

Answers (2)

McDowell
McDowell

Reputation: 108859

If you want a specific parameter, inject it into your bean:

<managed-bean>
  <managed-bean-name>fooBean</managed-bean-name>
  <managed-bean-class>foo.FooBean</managed-bean-class>
  <managed-bean-scope>request</managed-bean-scope>
  <managed-property>
    <property-name>bar</property-name>
    <property-class>java.lang.String</property-class>
    <value>#{param.bar}</value>
  </managed-property>
</managed-bean>

If the bean you want to reference the parameter from is in a broader scope, you can look it up from the external context (parameter; parameters).

If you really want the query string, you can probably inject that from the request using the expression #{request.queryString}.

Upvotes: 3

Jigar Joshi
Jigar Joshi

Reputation: 240860

for JSF go

HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();

Upvotes: 4

Related Questions