Confirmation link Email in JSF

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-02 17:46:05

Assuming you're already on JSF 2.0, you could grab @ManagedProperty and @PostConstruct.

@ManagedBean
@RequestScoped
public class Activation {

    @ManagedProperty(value="#{param.key}")
    private String key;
    private boolean valid;

    @PostConstruct
    public void init() {
        valid = check(key); // And auto-login if valid?
    }

    // ...
}

and then in JSF which is accessed by http://example.com/activate.jsf?key=somelonggeneratedkey

<h:panelGroup layout="block" rendered="#{activation.valid}">
   <p>Your account is successfully activated!</p>
   <p><h:link outcome="home">Go to home page</h:link></p>
</h:panelGroup>
<h:panelGroup layout="block" rendered="#{!activation.valid}">
   <p>Activation failed! Please enter your email address to try once again.</p> 
   <h:form>
       ...
   </h:form>
</h:panelGroup>

You can implement it by creating a page (.jsp for ex) that has:

<f:view beforePhaseListener="#{userActivationController.performActivation}">

(this is for facelets; for jsp the attribute is just beforePhase). And then, in the managed bean's method use FacesContext.getCurrentContext().getExternalContext().getParameterMap() to obtain the request patameters and get the activation code, which is passed like:

http://yoursite.com/activate.jsp?code=54gfd54tgdgfd

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!