Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Expected a child component type of UISelectItem...

843844Feb 28 2008 — edited Feb 28 2008
When I run my JSF app, I am getting the following error:

javax.servlet.ServletException: Expected a child component type of UISelectItem/UISelectItems for component type javax.faces.SelectOne(j_id_jsp_787851920_7). Found null.
-----
Delving into the generated java class for my page, I find jsp_787851920_7 refers to this section
_jspx_th_h_005fselectOneMenu_005f0.setValue(new org.apache.jasper.el.JspValueExpression("/searchForm.jsp(41,9) '#{flight.departTime}'",_el_expressionfactory.createValueExpression(_jspx_page_context.getELContext(),"#{flight.departTime}",java.lang.Object.class)));
    _jspx_th_h_005fselectOneMenu_005f0.setJspId("jsp_787851920_7");
-----
Going back to my orginal source this relates to this snippet:
         <h:selectOneMenu value="#{flight.departTime}">
           <f:selectItems value="#{times.times}"/>
         </h:selectOneMenu>
-----
Here is the corresponding sections in my faces.config.xml
  <managed-bean>
    <managed-bean-name>flight</managed-bean-name>
    <managed-bean-class>com.apress.jsf.FlightSearch</managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>
    <managed-property>
      <property-name>matchingFlights</property-name>
      <list-entries>
        <value-class>com.apress.jsf.Flight</value-class>
        <value>#{flight1}</value>
        <value>#{flight2}</value>
      </list-entries>
    </managed-property>
  </managed-bean>
    <managed-bean-name>times</managed-bean-name>
    <managed-bean-class>com.apress.jsf.FlightTimes</managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>
  <managed-bean>
-----
Here are the two Java classes 1) FlightSearch
package com.apress.jsf;

import java.util.List;
import java.util.ArrayList;
import java.util.Collection;

public class FlightSearch {
  String origination;
  String destination;
  String departDate;
  String departTime;
  String returnDate;
  String returnTime;
  String tripType;
  ArrayList <Flight>matchingFlights = new ArrayList<Flight>();

  public String getDepartDate() {
    return departDate;
  }

  public void setDepartDate(String departDate) {
    this.departDate = departDate;
    matchingFlights.get(0).setDepartDate(departDate);
    matchingFlights.get(1).setDepartDate(departDate);
  }

  public String getDepartTime() {
    return departTime;
  }

  public void setDepartTime(String departTime) {
    this.departTime = departTime;
    matchingFlights.get(0).setDepartTime(departTime);
    matchingFlights.get(1).setDepartTime(departTime);
  }

 public String getDestination() {
    return destination;
  }

  public void setDestination(String destination) {
    this.destination = destination;
    matchingFlights.get(0).setDestination(destination);
    matchingFlights.get(1).setDestination(destination);
    matchingFlights.get(0).setFlightNum("133");
    matchingFlights.get(1).setFlightNum("233");

  }

 public String getOrigination() {
    return origination;
  }

  public void setOrigination(String origination) {
    this.origination = origination;
    matchingFlights.get(0).setOrigination(origination);
    matchingFlights.get(1).setOrigination(origination);
  }

 public String getReturnDate() {
    return returnDate;
  }

  public void setReturnDate(String returnDate) {
    this.returnDate = returnDate;
    matchingFlights.get(0).setReturnDate(returnDate);
    matchingFlights.get(1).setReturnDate(returnDate);
  }

 public String getReturnTime() {
    return returnTime;
  }

  public void setReturnTime(String returnTime) {
    this.returnTime = returnTime;
    matchingFlights.get(0).setReturnTime(returnTime);
    matchingFlights.get(1).setReturnTime(returnTime);

  }

  public String getTripType() {
    return tripType;
  }

  public void setTripType(String tripType) {
    this.tripType= tripType;
  }

  public void setMatchingFlights(List<? extends Flight> matchingFlights) {
    this.matchingFlights.addAll(matchingFlights);
  }
} 
-----
2) FlightTimes
package com.apress.jsf;

import javax.faces.model.SelectItem;

public class FlightTimes {
  static SelectItem[] times = new SelectItem[] {
    new SelectItem("Anytime", "Anytime"),
    new SelectItem("Morning", "Morning"),
    new SelectItem("Afternoon", "Afternoon"),
    new SelectItem("Evening", "Evening") };
  
  public SelectItem[] getTimes() {
    return times;
  }

  public void setTimes(SelectItem[] times) {
    FlightTimes.times = times;
  }
}
-----
From this, I can't understand why it says null was found...

I mean the selectOneMenu has a body that contains a selectItems tag.

Am I reading the error log correctly?

Can someone point me in the right direction?
Cheers..
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 27 2008
Added on Feb 28 2008
2 comments
1,284 views