Friday 31 May 2013

JSF selectOneRadio tag example


1). JSF selectOneRadio tag Program Structure:

 
 

2). index.jsp 

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>

<html>
 <head>
   <title>JSF h:selectOneRadio tag example!</title>  
</head>
  <body>
        <f:view>
             <h2>h:selectOneRadio example</h2>
             <hr />
            <h:form>
             <h3>Radio Button</h3>
         <h:selectOneRadio value="#{selectedData.data}">
            <f:selectItem itemValue="Satyam" itemLabel="Satyam" />
            <f:selectItem itemValue="Pallavi" itemLabel="Pallavi" />
            <f:selectItem itemValue="Srinu" itemLabel="Srinu" />
            <f:selectItem itemValue="Priya" itemLabel="Priya" />
            <f:selectItem itemValue="Bharathi" itemLabel="Bharathi" />
         </h:selectOneRadio>              
         <h:commandButton value="Submit" action="result" />
            </h:form>
        </f:view>
    </body>
</html>
 

3). SelectedData.java

package com.satyamsoft;

import java.io.Serializable;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

@ManagedBean(name = "selectedData", eager = true)
@SessionScoped
public class SelectedData implements Serializable {

    private static final long serialVersionUID = 1L;
   
    public String data = "1";

    public String getData() {
        return data;
    }

    public void setData(String data) {
        this.data = data;
    }
}

4). result.jsp

 <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<html>
 <head>
   <title>JSF selectBooleanCheckbox tag example!</title> 
</head>
  <body>
        <f:view>
             <h2>h:selectManyCheckbox example</h2>
             <hr />
            <h:form>         
           <h:panelGrid columns="1">
                       <h:column>                     
                          <h:dataTable value="#{selectedData.data}" var="name" border="0">
                              <h:column>
                                  <f:facet name="header">
                                      <h:outputText value="Selected Name is:" />
                                </f:facet>
                                <b><h:outputText value="#{name}"/></b>
                            </h:column>
                          </h:dataTable>
                      </h:column>
                  </h:panelGrid>    
              </h:form>
        </f:view>
    </body>
</html>

 

5). OutPut


No comments:

Post a Comment