JAVA SERVER FACES(JSF)

JSF PROJECTS

JSF PROJECT 1

JSF Examples

JSF EXAMPLE

select Items Tag Example
Previous Home Next

Tag Description: JSF Tag is use to add a child UISelectItems component to the UIComponent associate with the enclosing parent tag.SelectItems represents a single item in the list of supported items associated with a UISelectMany or UISelectOne component.

Code for <f:selectItems> Example:

For run this example following step is required.

Step 1 :

Welcome page of Example


<%--
   Name= welcomeJSF.jsp
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<%--
This file is an entry point for JavaServer Faces application.
--%>
<f:view>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>r4r.co.in</title>
</head>
<body>
<h1><h:outputText value="Tag <f:selectItems> Example "/></h1>
<h:form>

<h:panelGrid columns="2" cellpadding="2" cellspacing="2">
<h:outputLabel value="Select a day from the list" />

<%-- Store object value into variable from list --%>
<h:selectOneMenu value="#{selectMenu.display}" >
<%-- Disaply List form Bean class --%>
<f:selectItems id="result" value="#{selectMenu.items}" />
</h:selectOneMenu>
   
<h:commandButton action="#{selectMenu.show()}" value="Submit" />
</h:panelGrid>
<BR><BR>

<%-- Display result --%>
<h:panelGrid rendered="#{selectMenu.flag != false}"  >
<h:outputLabel value="Object value of selected day == " >
<h:outputText value="#{selectMenu.display}" />
</h:outputLabel>
</h:panelGrid>
</h:form>
</body>
</html>
</f:view>

Step 2 :

ManagedBean class for provide logic in program

/*
 * Save as a SelectMenuBean.java
 */
package r4r.JSF2;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.model.SelectItem;

/* -- Name of Bean -- */
@ManagedBean(name = "selectMenu")
@RequestScoped
public class SelectMenuBean {

/* -- create a list -- */
private SelectItem[] items = new SelectItem[]{
//Add Object value and String value into list
new SelectItem(01, "Sunday"),
new SelectItem(02, "Monday"),
new SelectItem(03, "Tuesday"),
new SelectItem(04, "Wednesday"),
new SelectItem(05, "Thrusday"),
new SelectItem(06, "Friday"),
new SelectItem(07, "Saturday"),
};
private String display;
private boolean flag = false;

public String getDisplay() {
return display;
}

public void setDisplay(String display) {
this.display = display;
}

public SelectItem[] getItems() {
return items;
}

public void setItems(SelectItem[] items) {
this.items = items;
}

public boolean isFlag() {
return flag;
}

public void setFlag(boolean flag) {
this.flag = flag;
}

/* --  show method -- */
public String show() {
flag = true;
return "show";
}
}

 

Output:

Previous Home Next

Tolal:0 Click:

Show All Comments

Did not find what you were looking for leave your name and message. We will revert within 24 hours
Name:
eMail:
Comment / Feedback: