You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Marcio E Miranda <Ma...@fastsearch.com> on 2006/03/10 15:34:24 UTC

Restore state error in custom composite component

Hi all,

 

I'm just a beginner in JSF development, so this might be a silly
question, but I'm really stuck at the moment. I'm developing a custom
component, which is a composite component. My component extends the
UIPanel, and adds an input box and a command button programmatically.
Some configurations in the child components are done there as well. I've
chosen the UIPanel as the base class because it can render its children.

 

The component renders fine, but when I submit the button, I get the
following error:

 

java.lang.IndexOutOfBoundsException: Index: 2, Size: 2
        java.util.ArrayList.RangeCheck(ArrayList.java:507)
        java.util.ArrayList.get(ArrayList.java:324)
 
javax.faces.component.UIComponentBase.processRestoreState(UIComponentBas
e.java:499)
 
javax.faces.component.UIComponentBase.processRestoreState(UIComponentBas
e.java:502)
 
javax.faces.component.UIComponentBase.processRestoreState(UIComponentBas
e.java:502)
 
org.apache.myfaces.application.jsp.JspStateManagerImpl.restoreComponentS
tate(JspStateManagerImpl.java:129)
 
org.apache.myfaces.application.jsp.JspStateManagerImpl.restoreView(JspSt
ateManagerImpl.java:185)
 
org.apache.myfaces.application.jsp.JspViewHandlerImpl.restoreView(JspVie
wHandlerImpl.java:255)
 
org.apache.myfaces.lifecycle.LifecycleImpl.restoreView(LifecycleImpl.jav
a:124)
 
org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:66
)
        javax.faces.webapp.FacesServlet.service(FacesServlet.java:106)
 
org.apache.myfaces.component.html.util.ExtensionsFilter.doFilter(Extensi
onsFilter.java:122)

 

 

Since I don't have any particular property in my control (that I want to
save state), I thought the base control would handle the state. Could
someone kindly take a look at the code bellow and tell me what I am
doing wrong?

 

//The component

public class UISearchPanel extends UIPanel {

            

            private static final Log log =
LogFactory.getLog(UISearchPanel.class);

            

            /** Component type used by application factories. */

            public final static String COMPONENT_TYPE =
"esp.UISearchPanel";

            

            private UIInput    searchInputBox;

            private UICommand        submitButton;

            

            /** Create the inner components. */

            public UISearchPanel(){

                        super();

                        setId("searchForm");

                        setRendererType("javax.faces.Grid");

                        addChildren();

            }

            

            /** Add children components. */

            protected void addChildren(){

                        Application app =
FacesContext.getCurrentInstance().getApplication();

                        setSearchInputBox(createSearchInputBox(app));

                        setSubmitButton(createSubmitButton(app));

            }

            

            /** Create the inner search input box. */

            protected UIInput createSearchInputBox(Application app){

                        UIInput searchInputBox =
(UIInput)app.createComponent(UIInput.COMPONENT_TYPE);

                        searchInputBox.setId("queryString");

                        searchInputBox.setRequired(true);

                        //set default validator

                        QueryValidator validator = new QueryValidator();


                        searchInputBox.addValidator(validator);

                        //return child component

                        return searchInputBox;

            }

            

            /** Create the inner submit button. */

            protected UICommand createSubmitButton(Application app){

                        UICommand submitButton =
(UICommand)app.createComponent(UICommand.COMPONENT_TYPE);

                        submitButton.setId("submit");

                        submitButton.setValue(">>");

                        return submitButton;

            }

            

            protected void setSearchInputBox(UIInput searchInputBox) {

                        this.searchInputBox = searchInputBox;

                        getChildren().add(searchInputBox);

            }

 

            protected void setSubmitButton(UICommand submitButton) {

                        this.submitButton = submitButton;

                        getChildren().add(submitButton);

            }

 

            public UIInput getSearchInputBox() {

                        return searchInputBox;

            }

 

            public UICommand getSubmitButton() {

                        return submitButton;

            }

 

}

 

//The tag lib

public class SearchPanel_GridTag extends UIComponentTag {

 

            private static final Log log =
LogFactory.getLog(SearchPanel_GridTag.class);

            private String value;

            private String action;

            

            public SearchPanel_GridTag(){

                        super();

            }

            

            public String getComponentType() {

                        return UISearchPanel.COMPONENT_TYPE;

            }

 

            public String getRendererType() {

                        return "javax.faces.Grid";

            }

            

            protected void setProperties(UIComponent component){

                        super.setProperties(component);

                        

                        UISearchPanel uiSearchPanel =
(UISearchPanel)component;

                        uiSearchPanel.getAttributes().put("columns", new
Integer(2));

                        

//                      input box properties                    

                        if (value != null){

                                    if (isValueReference(value)){

 
uiSearchPanel.getSearchInputBox().setValueBinding("value",getFacesContex
t().getApplication().createValueBinding(value));

                                    }

                                    else{

 
uiSearchPanel.getSearchInputBox().setValue(value);

                                    }

                }

 
uiSearchPanel.getSearchInputBox().getAttributes().put("styleClass",
"portlet-form-input-field");

                        

//                      command button properties

                        if (action != null){

            MethodBinding mb;

            if (isValueReference(action)){

                mb =
getFacesContext().getApplication().createMethodBinding(action, null);

            }

            else{

                mb = new SimpleActionMethodBinding(action);

            }

            uiSearchPanel.getSubmitButton().setAction(mb);

        }

 
uiSearchPanel.getSearchInputBox().getAttributes().put("styleClass",
"portlet-form-button");

                        

                        log.debug("setProperties executed.");

            }

            

            public void release(){

                        value = null;

                        action = null;

            }

 

            public String getValue() {

                        return value;

            }

 

            public void setValue(String value) {

                        this.value = value;

            }

 

            public String getAction() {

                        return action;

            }

 

            public void setAction(String action) {

                        this.action = action;

            }

 

}

 

//The jsp call

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

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

<%@ taglib uri="esp-components" prefix="esp" %>

 

<html>

      <head>

            <title></title>

      </head>

      <body>

            

            <f:view>

                  <h:form id="searchForm">

                  <esp:searchPanel value="#{myquery.queryString}"
action="success"/>

                  </h:form>

            </f:view>

            

      </body>     

</html>  

 

 

Many thanks!!