Frameworks| Hibernate| Struts| JSF| JavaFX| Ajax| Spring| DOJO| JDO| iBatis| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Binding Component Instance to a Bean Property 
 

JavaBeans are used to associate the UI components.

 

Binding Component Instance to a Bean Property

                          

JavaBeans are used to associate the UI components. This backing bean (JavaBean) contains properties that are bound to either component value or component instance. Both types of binding requires use of Expression Language (EL) syntax. A component instance can be bound to the bean property by referencing the property in the "binding" attribute of the tag associated with the component. But we have to take care of one fact that the property of the bean must accept and return the same component type as the instance of the bound component.

For example:

 

 

 

 

<h:panelGrid columns="2" binding="#{InstanceBean.gridInstance}">
<h:outputText value="First Name: "/>
<h:outputText value="Ravi"/>
<h:outputText value="Last Name: "/>
<h:outputText value="Kant"/>

<h:outputText value=""/>
<h:commandButton value="#{InstanceBean.buttonBorderText}" action="#{InstanceBean.setBorder}"/> 
</h:panelGrid>

The related property in the backing bean should be of the class type of component and its setter and getter method should deal with same type. For example, In the code below, gridInstance attribute is of type HtmlPanelGrid class which represents the panel grid component. Now you can use this object in action method and manipulate the panel grid as you want.

The sample code for InstanceBean.java:

package roseindia;

import javax.faces.component.html.HtmlPanelGrid;

public class InstanceBean {

HtmlPanelGrid gridInstance;
........................................
........................................
public HtmlPanelGrid getGridInstance() {
      return gridInstance;
}
public void setGridInstance(HtmlPanelGrid gridInstance) {
      this.gridInstance = gridInstance;
}

......................................
......................................
public void setBorder(){

    if(buttonBorderText.equals("Set Border")){
         gridInstance.setBorder(1);
         gridInstance.setBgcolor("pink");
         buttonBorderText = "Remove Border";
    }
    else{
         gridInstance.setBorder(0);
         gridInstance.setBgcolor("white");
         buttonBorderText = "Set Border";
    }
  }
..................................
...................................
}

 

Download code for all examples

                          

» View all related tutorials
Related Tags: c file ide orm text date jsf form internationalization time air button io dates format label numbers vi locale key

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.