1

I try to get a parameter from the URL but I can't. I do this in my jsf

   <f:metadata>  
   <f:viewParam name="key" value="#{confirmationMB.key}"  required="true"   />  
   <f:viewAction action="#{confirmationMB.confirmer()}"/>  
   </f:metadata>

and this in my managed bean :

@ManagedBean
@ViewScoped
public class confirmationMB {
private String key;  public String getKey() {
    return key;
}

public void setKey(String key) {
    this.key = key;
}
public void confirmer(){

    System.out.println("the key is   "+key);

}

my URL is like this:

http://localhost:8080/exempler/validate_inscription.xhtml?key=124he

I get always null as value in System.out..can someone help me please ?

Edit: when I try <h:outputText value="#{param['key']}" /> in xhtml I can get the key but I don't know how I can insert it into my Bean !!

2 Answers 2

2

It s ok I find a solution to my problem : I ve add this lines into my managedBean and I can get now the key from the URL

HttpServletRequest req = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();   
    String val = (String)req.getParameter("key");

I put this solution to help people who may have the same problem

Sign up to request clarification or add additional context in comments.

Comments

0

Use:

<f:metadata>
    <f:viewParam name="key" value="#{confirmationMB.key}" />
    <f:event type="preRenderView"
        listener="#{confirmationMB.confirmer()}" />
</f:metadata>

5 Comments

thank you @sQer for your reply ... I just tried this but still have always NULL value the key is NULL
In fact .. I construct the link like this String lien = "http://localhost:8080/exemple/validate_inscription.xhtml?key="+key+";``String body =" pour confirmer "+"<html><body><a href="+lien+">Clique here</a></body></html>"; and then I sent it with javamail
Could you try <h:outputText value="#{param['key']}" /> in xhtml ? What result ?
I can get the right result in the jsf ( the exact key in the URL ) .. so how can I get it and save it in the managed bean?
please @sQer can you help me if you know what should I do to resolve this problem ?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.