tags:

views:

161

answers:

2

Hi

How to read query string value via managed bean in jsf1.1

A: 
String queryString = ((HttpServletRequest) FacesContext.getCurrentContext()
       .getExternalContext().getRequest()).getQueryString();

Put this in the action method or a phase listener where you need it. Don't put it in constructor.

Bozho
thanks for ur reply
johnbritto
I tried It is not woking
johnbritto
@johnbritto _how_ it isn't working? give more details
Bozho
johnbritto
ian waiting for ur reply
johnbritto
I didn't get your explanation
Bozho
johnbritto
@johnbritto check my update
Bozho
now Query string is working fine earlier i make mistake
johnbritto
A: 

I am not sure how the answer of Bozho didn't work for you, but regardless of this, I would suggest to let JSF do all the work rather than getting the "raw" HttpServletRequest from under the JSF hoods inside a bean. Make use of the JSF managed property facility.

First, add two properties to the bean: confirmuser and emailid, of course with getters and setters. Then, define them as managed properties in faces-config.xml wherein they are to be filled with #{param.confirmuser} and #{param.emailid}. You probably already know, the #{param} points to the request parameter map.

E.g.

<managed-bean>
    <managed-bean-name>userManager</managed-bean-name>
    <managed-bean-class>com.example.UserManager</managed-bean-class>
    <managed-bean-scope>request</managed-bean-scope>
    <managed-property>
        <property-name>confirmuser</property-name>
        <value>#{param.confirmuser}</value>
    </managed-property>
    <managed-property>
        <property-name>emailid</property-name>
        <value>#{param.emailid}</value>
    </managed-property>
</managed-bean>

This way JSF will automatically set the bean properties with those values.

BalusC
Iam using Jsf1.1 .Jsf 1.1 is not supported #{param} El.I want to fix this issue in jsf1.1
johnbritto
It's supported in JSF 1.1. Even more, this is independent of JSF. If it doesn't solve your problem, then the cause of the problem lies somewhere else. It's probably the same cause as that you didn't get anything from `getQueryString()`. Don't you have some weird filters or servlets in the request chain which manipulates the URL before forwarding or so?
BalusC
This examples woks fine earlier i made mistake.Thanks Baulc
johnbritto