Hi, I am pretty new to JSF and I was wondering if someone could help me with a problem that I've been stuck on. I'm writing a Date Input custom component that consists of 1 HtmlPanelGrid containing 3 HtmlInputText fields as it's children. The custom component is extending UIInput. I have gotten it to render however when the form on the page submits, I get an IndexOutOfBoundsException in the processRestoreState function call. Any help or suggestions would be greatly appreciated!!

(If anyone is familiar with the DatePicker and DateDisplay custom component example on developers.sun.com , I modified their DatePicker to use 3 HtmlInputText instead of 3 HtmlSelectOneMenu fields. Refer to: http://developers.sun.com/prodtech/javatools/jscreator/reference/techart/2/customize_build_components.html  for the sample code.)

Attached is the error output of the browser:

java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
java.util.ArrayList.RangeCheck(Unknown Source)
java.util.ArrayList.get (Unknown Source)
javax.faces.component.UIComponentBase.processRestoreState
(UIComponentBase.java:499)
javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.java:502)
javax.faces.component.UIComponentBase.processRestoreState
(UIComponentBase.java:502)
javax.faces.component.UIComponentBase.processRestoreState
(UIComponentBase.java:502)
org.apache.myfaces.application.jsp.JspStateManagerImpl.restoreComponentState(JspStateManagerImpl.java
:129)
org.apache.myfaces.application.jsp.JspStateManagerImpl.restoreView(JspStateManagerImpl.java
:185)
org.apache.myfaces.application.jsp.JspViewHandlerImpl.restoreView(JspViewHandlerImpl.java:255)
com.sun.facelets.FaceletViewHandler.restoreView
(FaceletViewHandler.java:352)
com.sun.facelets.FaceletViewHandler.restoreView
(FaceletViewHandler.java:352)
org.apache.myfaces.lifecycle.LifecycleImpl.restoreView(LifecycleImpl.java:124)
org.apache.myfaces.lifecycle.LifecycleImpl.execute
(LifecycleImpl.java:66)
javax.faces.webapp.FacesServlet.service
(FacesServlet.java:106)
com.geico.ibu.service.insite.util.LoginFilter.doFilter(LoginFilter.java:68)
org.apache.myfaces.component.html.util.ExtensionsFilter.doFilter
(ExtensionsFilter.java:122)

This is a partial class definition for my custom component:

public class UIDateInput extends UIInput {
    private HtmlPanelGrid gridPanel;
    private HtmlInputText dayInput;
    private HtmlInputText monthInput;
    private HtmlInputText yearInput;
........

}


The constructor for this class calls an init() function that contains this code where dayInput, monthInput and yearInput have been initialized to new HtmlInputText objects before being added as gridPanel's children:

..........
        gridPanel = new HtmlPanelGrid();
        gridPanel.setId(clientId+GRID);
        gridPanel.getChildren().add(monthInput);
        gridPanel.getChildren().add(dayInput);
        gridPanel.getChildren().add(yearInput);
        gridPanel.setColumns(3);

        // Add the panel as a child of this component
        getChildren().clear();
        getChildren().add(gridPanel);
.............


Here is the saveState and restoreSate functions in my custom component class:

    public Object saveState(FacesContext context) {

        Object values[] = new Object[8];
        values[0] = super.saveState(context);
        values[1] = gridPanel.saveState(context);
        values[2] = monthInput.saveState(context);
        values[3] = yearInput.saveState(context);
        values[4] = style;
        values[5] = styleClass;
        values[6] = title;
        values[7] = dayInput.saveState(context);
        return values;
    }

   public void restoreState(FacesContext context, Object state) {

        Object values[] = (Object[]) state;
        super.restoreState(context, values[0]);
        gridPanel.restoreState(context, values[1]);
        monthInput.restoreState(context, values[2]);
        yearInput.restoreState(context, values[3]);
        style = (String) values[4];
        styleClass = (String) values[5];
        title = (String) values[6];
        dayInput.restoreState(context, values[7]);
    }


Reply via email to