Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML

Tutorial Categories: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML

Fresher Job


 

Search Host

Monthly Fee($)
Disk Space (MB)
Register With us for Newsletter!
Visit Forum! Post Questions!
Jobs At RoseIndia.net!

Have tutorials?
Add your tutorial to our Java Resource and get tons of hits.

We offer free hosting for your tutorials. and exposure for thousands of readers. drop a mail
roseindia_net@yahoo.com
 
   

Tutorials

Java Server Pages

JAXB

Java Beans

JDBC

MySQL

Java Servlets

Struts

Bioinformatics

Java Code Examples

Interview Questions

 
Join For Newsletter

Powered by groups.yahoo.com
Visit Group! Post Questions!

Web Promotion

Web Submission

Submit Sites

Manual Submission?

Web Promotion Guide

Hosting Companies

Web Hosting Guide

Web Hosting

Linux

Beginner Guide to Linux Server

Frameworks

Persistence Framework

Web Frameworks

Free EAI Tools

Web Servers

Aspect Oriented Programming

Free Proxy Servers

Softwares

Adware & Spyware Remover

Open Source Softwares

problem with selectItem tags
Expert:srikala
Hi frnds,
here iam providing my code ,give me the solution.There are 2 jsf pages,1 java bean in this application.
Code is:
1.index1.jsp:
<html>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<f:view>
<head>
<link rel="stylesheet" href="<%=request.getContextPath()%>/css/styles.css" type="text/css" />
<title>
<h:outputText value="Checkboxes, Radio buttons, Menus, and Listboxes" />
</title>
</head>

<body>
<h:outputText value="indexPageTitle" styleClass="emphasis"/>
<h:outputText value="Please fill out the following information" styleClass="emphasis"/>
<h:form>
<table>
<tr>
<td>
<h:outputText value="Name:"/>
</td>
<td>
<h:inputText value="#{form.name}"/>
</td>
</tr>
<tr>
<td>
<h:outputText value="Contact me"/>
</td>
<td>
<h:selectBooleanCheckbox value="#{form.contactMe}"/>
</td>
</tr>
<tr>
<td>
<h:outputText value="What's the best day to contact you?"/>
</td>
<td>
<h:selectManyMenu value="#{form.bestDaysToContact}">
<f:selectItems value="#{form.daysOfTheWeekItems}"/>
</h:selectManyMenu>
</td>
</tr>
<tr>
<td>
<h:outputText value="What year were you born?"/>
</td>
<td>
<h:selectOneListbox size="5" value="#{form.yearOfBirth}">
<f:selectItems value="#{form.yearItems}"/>
</h:selectOneListbox>
</td>
</tr>
<tr>
<td>
<h:outputText value="colors"/>
</td>
<td>
<h:selectManyCheckbox value="#{form.colors}">
<f:selectItems value="#{form.colorItems}"/>
</h:selectManyCheckbox>
</td>
</tr>
<tr>
<td>
<h:outputText value="Select the languages you speak:"/>
</td>
<td>
<h:selectManyListbox value="#{form.languages}">
<f:selectItems value="#{form.languageItems}"/>
</h:selectManyListbox>
</td>
</tr>
<tr>
<td>
<h:outputText value="Select your highest education level:"/>
</td>
<td>
<h:selectOneRadio value="#{form.education}"
layout="pageDirection">
<f:selectItems value="#{form.educationItems}"/>
</h:selectOneRadio>
</td>
</tr>
</table>
</h:form>
<h:form>
<h:commandButton value="Submit information"
action="showInformation"/>
</h:form>
<h:messages/>
</body>
</f:view>
</html>
2.showInformation.jsp:
<html>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<f:view>
<head>
<link rel="stylesheet" href="<%=request.getContextPath()%>/css/styles.css" type="text/css" />
<title>
<h:outputText value="Checkboxes, Radio buttons, Menus, and Listboxes"/>
</title>
</head>

<body>
<h:outputFormat value="Thank you {0}, for your information">
<f:param value="#{form.name}"/>
</h:outputFormat>
<p>
<table>
<tr>
<td><h:outputText value="Contact me:"/></td>
<td><h:outputText value="#{form.contactMe}"/></td>
</tr>

<tr>
<td><h:outputText value="Best day to contact you:"/></td>
<td><h:outputText value="#{form.bestDaysConcatenated}"/></td>
</tr>

<tr>
<td><h:outputText value="Your year of birth:"/></td>
<td><h:outputText value="#{form.yearOfBirth}"/></td>
</tr>

<tr>
<td><h:outputText value="Languages:"/></td>
<td><h:outputText value="#{form.languagesConcatenated}"/></td>
</tr>

<tr>
<td><h:outputText value="Colors:"/></td>
<td><h:outputText value="#{form.colorsConcatenated}"/></td>
</tr>

<tr>
<td><h:outputText value="Education:"/></td>
<td><h:outputText value="#{form.education}"/></td>
</tr>
</table>
</body>
</f:view>
</html>
3.RegisterForm.java:
import java.text.DateFormatSymbols;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

import javax.faces.model.SelectItem;

public class RegisterForm {
enum Education { HIGH_SCHOOL, BACHELOR, MASTER, DOCTOR };

private String name;
private boolean contactMe;
private Integer[] bestDaysToContact;
private Integer yearOfBirth;
private String[] colors;
private String[] languages;
private Education education;

// PROPERTY: name
public String getName() {
return name;
}
public void setName(String newValue) {
name = newValue;
}

// PROPERTY: contactMe
public boolean getContactMe() {
return contactMe;
}
public void setContactMe(boolean newValue) {
contactMe = newValue;
}

// PROPERTY: bestDaysToContact
public Integer[] getBestDaysToContact() {
return bestDaysToContact;
}
public void setBestDaysToContact(Integer[] newValue) {
bestDaysToContact = newValue;
}

// PROPERTY: yearOfBirth
public Integer getYearOfBirth() {
return yearOfBirth;
}
public void setYearOfBirth(Integer newValue) {
yearOfBirth = newValue;
}

// PROPERTY: colors
public String[] getColors() {
return colors;
}
public void setColors(String[] newValue) {
colors = newValue;
}

// PROPERTY: languages
public String[] getLanguages() {
return languages;
}
public void setLanguages(String[] newValue) {
languages = newValue;
}

// PROPERTY: education
public Education getEducation() {
return education;
}

public void setEducation(Education newValue) {
education = newValue;
}

// PROPERTY: yearItems
public Collection<SelectItem> getYearItems() {
return birthYears;
}

// PROPERTY: daysOfTheWeekItems
public SelectItem[] getDaysOfTheWeekItems() {
return daysOfTheWeek;
}

// PROPERTY: languageItems
public Map<String, Object> getLanguageItems() {
return languageItems;
}

// PROPERTY: colorItems
public SelectItem[] getColorItems() {
return colorItems;
}

// PROPERTY: educationItems
public SelectItem[] getEducationItems() {
return educationItems;
}

// PROPERTY: bestDaysConcatenated
public String getBestDaysConcatenated() {
return concatenate(bestDaysToContact);
}

// PROPERTY: languagesConcatenated
public String getLanguagesConcatenated() {
return concatenate(languages);
}

// PROPERTY: colorsConcatenated
public String getColorsConcatenated() {
return concatenate(colors);
}

private static String concatenate(Object[] values) {
if (values == null)
return "";
StringBuilder r = new StringBuilder();
for (Object value : values) {
if (r.length()> 0)
r.append(',');
r.append(value.toString());
}
return r.toString();
}

private static SelectItem[] colorItems = {
new SelectItem("Red"),
new SelectItem("Blue"),
new SelectItem("Yellow"),
new SelectItem("Green"),
new SelectItem("Orange")
};

private static SelectItem[] educationItems = {
new SelectItem(Education.HIGH_SCHOOL, "High School"),
new SelectItem(Education.BACHELOR, "Bachelor's"),
new SelectItem(Education.MASTER, "Master's"),
new SelectItem(Education.DOCTOR, "Doctorate") };

private static Map<String, Object> languageItems;
static {
languageItems = new LinkedHashMap<String, Object>();
languageItems.put("English", "en"); // item, value
languageItems.put("French", "fr");
languageItems.put("Russian", "ru");
languageItems.put("Italian", "it");
languageItems.put("Spanish", "es");
}

private static Collection<SelectItem> birthYears;
static {
birthYears = new ArrayList<SelectItem>();
for (int i = 1900; i < 2000; ++i) {
birthYears.add(new SelectItem(i));
}
}

private static SelectItem[] daysOfTheWeek;
static {
DateFormatSymbols symbols = new DateFormatSymbols();
String[] weekdays = symbols.getWeekdays();
daysOfTheWeek = new SelectItem[7];
for (int i = Calendar.SUNDAY; i <= Calendar.SATURDAY; i++) {
daysOfTheWeek[i - 1] = new SelectItem(new Integer(i), weekdays[i]);
}
}
}
4.faces-config.xml:
<?xml version="1.0"?>
<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"
version="1.2">


<managed-bean>
<managed-bean-name>form</managed-bean-name>
<managed-bean-class>RegisterForm</managed-bean-class>
<managed-bean-scope>application</managed-bean-scope>
</managed-bean>
<navigation-rule>
<from-view-id>/jsf/index1.jsp</from-view-id>
<navigation-case>
<from-outcome>showInformation</from-outcome>
<to-view-id>/jsf/showInformation.jsp</to-view-id>
</navigation-case>
</navigation-rule>

</faces-config>
5.web.xml:
<?xml version="1.0"?>
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>

<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>

<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>/WEB-INF/faces-config.xml</param-value>
</context-param>

<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>

<!-- Faces Servlet -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup> 1 </load-on-startup>
</servlet>


<!-- Faces Servlet Mapping -->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
</web-app>

while running this code,after filling the register form , after clicking submitt button it giving the following exception:

Thank you null, for your information
Contact me: false
Best day to contact you:
Your year of birth:
Languages:
Colors:
Education:

we expected output like this:

Thank you XXX,for your information
Contact me:
Best day to contact you: sunday
Your year of birth: 1986
Languages:English
Colors: blue
Education: BACHELOR

Please check my code and give me the solution for this.
This is very urgent for me.
Please give me solution as early as possible.
Answers
More Questions
Post Answers
 
Ask Question Facing Programming Problem?
Useful Links
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification

Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

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

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

Copyright © 2007. All rights reserved.