简体   繁体   English

使用PrettyFaces在bean中设置确认链接参数

[英]Set confirmation link parameter in bean using PrettyFaces

I'm trying to send an email confirmation link in JSF 2.0. 我正在尝试在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. 我正在尝试使用漂亮的面孔进行URL映射。

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} 我还尝试将{ iid : emailConfirmation.param}更改为{emailConfirmation.param}{ 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: 我还有一个RequestScoped bean,看起来像:

    @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. 用户现在单击链接时,param值为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 javax.faces.bean

instead of 代替

javax.enterprise.context.RequestScoped .... javax.enterprise.context.RequestScoped ....

Also, it was the second block of url mapping code that worked, not the first! 另外,它是起作用的第二个URL映射代码块,而不是第一个!

You cannot use query parameters in the <pattern> part of the mapping. 您不能在映射的<pattern>部分中使用查询参数。 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 http://www.ocpsoft.org/docs/prettyfaces/3.3.3/en-US/html/Configuration.html#config.queryparams

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用PrettyFaces调用FileUploadListener时重建ViewScoped bean - ViewScoped bean rebuilt when FileUploadListener called using PrettyFaces 使用PrettyFaces 3.3.1-SNAPSHOT - Using PrettyFaces 3.3.1-SNAPSHOT 如何在支持bean中处理prettyfaces的query-param? - How to process prettyfaces 'query-param' in backing bean? 将Managed Bean设置为Composite Component中的参数 - Set Managed Bean as parameter in Composite Component 使用prettyfaces对dispatcherTypes = {DispatcherType.REQUEST}进行nullpointerexception - nullpointerexception on dispatcherTypes = {DispatcherType.REQUEST} using prettyfaces 在p:menuitem上以编程方式使用PrettyFaces动作 - Using PrettyFaces action programatically on p:menuitem PrettyFaces和h:link结果标记不会重定向到干净的URL - PrettyFaces and h:link outcome tag don't redirect to a clean URL JSF / Primefaces / PrettyFaces-每次单击按钮或链接时都要执行操作 - JSF/Primefaces/PrettyFaces - do action everytime button or link is being clicked 如何在RequestScoped bean中调用@PostConstruct之前在SessionScoped bean中设置参数值 - How to set parameter value in SessionScoped bean before @PostConstruct gets called in RequestScoped bean 如何使用MultiPageMes​​sagesSupport在PrettyFaces中跨重定向保留FacesMessages? - How to preserve FacesMessages across redirects with PrettyFaces using MultiPageMessagesSupport?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM