I'm trying to send an email confirmation link in JSF 2.0. The correct link is sending to the user's email without any problems, but I'm struggling to have the link redirect to the correct page when the user clicks on it. I am trying to use pretty faces for URL mapping.
The confirmation link looks something like:
/confirm?param=1xfib3e
My code in pretty faces:
<url-mapping id="confirm">
<pattern value="/confirm?param=#{ iid : emailConfirmation.param}" />
<action>#{emailConfirmation.confirmationLink}</action>
</url-mapping>
I've also tried changing { iid : emailConfirmation.param}
to {emailConfirmation.param}
and { param : emailConfirmation.param}
and I've tried
<url-mapping id="confirm">
<pattern value="/confirm" />
<query-param name="param">#{emailConfirmation.param}</query-param>
<action>#{emailConfirmation.confirmationLink}</action>
</url-mapping>
I also have a RequestScoped bean that looks something like:
@Named("emailConfirmation")
@RequestScoped
public class EmailConfirmation implements Serializable{
private String param;
....
public String confirmationLink() {
log("param value: " + param);
}
public String getParam() {
return param;
}
public void setParam(String param) {
this.param = param;
}
}
Whenever the user clicks on the link right now, the param value is null. How is this caused and how can I solve it?
Found the answer. If anyone is curious, it is because I had imported
javax.faces.bean
instead of
javax.enterprise.context.RequestScoped ....
Also, it was the second block of url mapping code that worked, not the first!
You cannot use query parameters in the <pattern>
part of the mapping. If you want to configure query parameters for a mapping, use something like this:
<url-mapping id="confirm">
<pattern value="/confirm" />
<query-param name="param">#{emailConfirmation.param}</query-param>
<action>#{emailConfirmation.confirmationLink}</action>
</url-mapping>
See:
http://www.ocpsoft.org/docs/prettyfaces/3.3.3/en-US/html/Configuration.html#config.queryparams
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.