Book Image

Mastering JavaServer Faces 2.2

By : Anghel Leonard
Book Image

Mastering JavaServer Faces 2.2

By: Anghel Leonard

Overview of this book

Table of Contents (20 chapters)
Mastering JavaServer Faces 2.2
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
The JSF Life Cycle
Index

Passing bean properties and action methods via <ui:param>


In the previous example, you saw how to exploit <ui:param> for sending literal strings to a template or included page, but <ui:param> can be used for more than this. Let's suppose that we have the following code of the bean, TemplatesBean:

@Named
@ViewScoped
public class TemplatesBean implements Serializable {
    
  private String msgTopDefault="";
  private String msgBottomDefault="";
  private String msgCenterDefault="No center content ...press the below button!";

  //getters and setters
   
  public void topAction(String msg){
    this.msgTopDefault = msg;
  }
    
  public void bottomAction(String msg){
    this.msgBottomDefault = msg;
  }
    
  public void centerAction(){
    this.msgCenterDefault="This is default content";
  }    
}

Further, we want to display the value of the msgCenterDefault property in contentDefault.xhtml. Of course, this is very easy to accomplish using the following line of code:

&lt...