Saturday, October 10, 2015

Jsf, Getting url parameter value

Source image: wallpaperseries.com
Good morning, people!
Have you drink your coffee today? I'm drinking a cup of americano from nearby store. :)


Let say you have to get param value in http://localhost:8080/apps/faces/test.xhtml?param=hello.
All you need is just add view param in your xhtml file and mapped it with a variable in managed bean.

xhtml Code :
 <f:metadata>  
     <f:viewParam name="param" value="#{testBean.message}" />  
 </f:metadata>  

Managed Bean Code :
 @ManagedBean(name = "testBean")  
 @ViewScoped  
 public class TestBean implements Serializable {  
   private String message;  
   public String getMessage(){  
     return message;  
   }  
   public String setMessage(String message){  
     this.message = message;  
   }  
 }  

0 comments:

Post a Comment