0

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?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
user1795370
  • 332
  • 2
  • 4
  • 18

2 Answers2

1

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!

user1795370
  • 332
  • 2
  • 4
  • 18
0

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

chkal
  • 5,598
  • 21
  • 26