JSF无法从URL获取参数

贝蒂

我尝试从URL获取参数,但不能。我在我的jsf中执行此操作

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

这在我的托管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);

}

我的网址是这样的:

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

在System.out中总是得到null作为值。有人可以帮我吗?

编辑:当我<h:outputText value="#{param['key']}" />在xhtml中尝试时,我可以获取密钥,但是我不知道如何将其插入到Bean中!

贝蒂

可以,我可以找到问题的解决方案:我已将以下行添加到managedBean中,现在可以从URL中获取密钥

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

我提出这个解决方案来帮助可能遇到相同问题的人

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章