how to read querystring value via Managed Bean in jsf1.1
How to read query string value via managed bean in jsf1.1开发者_JAVA技巧
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.
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.
You can accomplish this by passing the query string params as <f:param />
values inside your command button.
For example, given the following URL (i.e. a user clicked this in an e-mail, thus no backing-bean code has been executed yet):
http://localhost:8080/webapp/resetPassword.xhtml?uuid=3d7844ba-5f4b-4de0-9595-fdcbdedad4dc&code=a2JITmEyamJhQ29HTVhyaHhhNnRqdXI3T1kyMldydU4=
Your JSF code:
<h:commandButton action="#{resetPasswordController.doActualReset}" value="Submit">
<f:param name="code"
value="#{param.code}" />
<f:param name="uuid"
value="#{param.uuid}" />
</h:commandButton>
BackingBean:
public String doActualReset() {
FacesContext context = FacesContext.getCurrentInstance();
Map<String, String> requestMap = context.getExternalContext().getRequestParameterMap();
String code = (String) requestMap.get("code");
String uuid = (String) requestMap.get("uuid");
...
}
Caveat: This was tested in JSF 2, but should work in 1.1. There's nothing here that is 2.x specific.
精彩评论