jsf - f:param value is returning null both with commandButton and also commandLink -


i doing simple navigation example in jsf beginner. getting null when accessing f:param value in managedbean using managedproperty

home.xhtml

    <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en"    "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"     xmlns:h="http://java.sun.com/jsf/html"     xmlns:f="http://java.sun.com/jsf/facelets"> <head> <title>jsf tutorial!</title> </head> <body>     <h3>using jsf outcome</h3>     <h:form>         <h:commandbutton action="#{navigation.show}" value="page1">             <f:param name="pageid" value="1" />         </h:commandbutton>         <h:commandlink action="#{navigation.show}" value="page2">             <f:param name="pageid" value="2" />         </h:commandlink>         <h:commandlink action="#{navigation.show}" value="home">             <f:param name="pageid" value="3" />         </h:commandlink>     </h:form> 

navigation.java

    package com.jason.jsf;  import java.util.map;  import javax.faces.bean.managedbean; import javax.faces.bean.managedproperty; import javax.faces.bean.requestscoped; import javax.faces.context.facescontext;  @managedbean(name = "navigation", eager = true) @requestscoped public class navigation {      @managedproperty(value = "#{param.pageid}")     private string pageid;      public string show() {          system.out.println("page id" + value);         if (pageid == null) {             return "home";         }         if (pageid.equals("1")) {             return "page1";         } else if (pageid.equals("2")) {             return "page2";         } else {             return "home";         }     }      public string getpageid() {         return pageid;     }      public void setpageid(string pageid) {         system.out.println("page id set" + pageid);          this.pageid = pageid;     } } 

how caused , how can solve it? using jsf2.2 mojarra 2.0.3.there other sample page1.xhtml , page2.xhtml navigation me in advance

look closer @ xml namespace prefix , uri , compare whatever shown in decent jsf book/tutorial/resource:

<html xmlns="http://www.w3.org/1999/xhtml"     xmlns:h="http://java.sun.com/jsf/html"     xmlns:f="http://java.sun.com/jsf/facelets"> 

yes, xml namespace uri f: prefix wrong. declared 1 of facelets tags have ui: prefix. causes tags not interpreted @ all. it's being misinterpreted <ui:param> has entirely different meaning real <f:param>.

fix taglib uri. needs http://java.sun.com/jsf/core. here's complete set:

<html xmlns="http://www.w3.org/1999/xhtml"     xmlns:f="http://java.sun.com/jsf/core"     xmlns:h="http://java.sun.com/jsf/html"     xmlns:ui="http://java.sun.com/jsf/facelets"> 

see also:


unrelated concrete problem, mojarra 2.0.3 not jsf 2.2. it's jsf 2.0. , rather old implementation too, on 5 years already. can latest mojarra 2.2 (currently 2.2.11) @ http://javaserverfaces.java.net. after that, can change domain in taglib uris java.sun.com xmlns.jcp.org:

<html xmlns="http://www.w3.org/1999/xhtml"     xmlns:f="http://xmlns.jcp.org/jsf/core"     xmlns:h="http://xmlns.jcp.org/jsf/html"     xmlns:ui="http://xmlns.jcp.org/jsf/facelets"> 

Comments