You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@myfaces.apache.org by "Jeroen Verhagen (JIRA)" <de...@myfaces.apache.org> on 2007/12/03 21:55:43 UTC

[jira] Created: (MYFACES-1783) IndexOutOfBoundsException in custom compound compoment

IndexOutOfBoundsException in custom compound compoment
------------------------------------------------------

                 Key: MYFACES-1783
                 URL: https://issues.apache.org/jira/browse/MYFACES-1783
             Project: MyFaces Core
          Issue Type: Bug
    Affects Versions:  1.2.0
         Environment: Windows XP, java 1.6.0_03
myfaces 1.2.1-SNAPSHOT and 1.2.0 on jetty-6.1.0pre0
            Reporter: Jeroen Verhagen
             Fix For: 1.2.1-SNAPSHOT


The following code for a custom (compound) component causes and IndexOutOfBoundsException on submit. It renders OK.  

 package com.mycompany;

import javax.el.ELContext;
import javax.el.ExpressionFactory;
import javax.el.ValueExpression;
import javax.faces.application.Application;
import javax.faces.component.EditableValueHolder;
import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
import javax.faces.component.UISelectItems;
import javax.faces.component.html.HtmlSelectOneRadio;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import javax.faces.convert.BooleanConverter;
import javax.faces.model.SelectItem;
import java.io.IOException;
import java.util.Map;

public class UIBooleanFieldset extends UIInput {

	public UIBooleanFieldset() {
		setConverter(new BooleanConverter());
		setRendererType(null);

		Application application = FacesContext.getCurrentInstance().getApplication();
		HtmlSelectOneRadio htmlSelectOneRadio = (HtmlSelectOneRadio) application.createComponent(HtmlSelectOneRadio.COMPONENT_TYPE);

		htmlSelectOneRadio.setId(getId() + "_radios");
		ExpressionFactory ef = FacesContext.getCurrentInstance().getApplication().getExpressionFactory();
		ELContext elContext = FacesContext.getCurrentInstance().getELContext();
		ValueExpression sexValueExpression = ef.createValueExpression(elContext, "#{persoonBean.sex}", String.class);
		htmlSelectOneRadio.setValueExpression("value", sexValueExpression);
		htmlSelectOneRadio.setLayout("pageDirection");

		UISelectItems selectItems = (UISelectItems) application.createComponent(UISelectItems.COMPONENT_TYPE);
		ValueExpression sexItemsValueExpression = ef.createValueExpression(elContext, "#{persoonBean.sexItems}", SelectItem[].class);
		selectItems.setValueExpression("value", sexItemsValueExpression);

		htmlSelectOneRadio.getChildren().add(selectItems);
		getChildren().add(htmlSelectOneRadio);
	}


	public void encodeBegin(FacesContext context) throws IOException {
		ResponseWriter writer = context.getResponseWriter();
		String clientId = getClientId(context);

		writer.startElement("fieldset", this);
		writer.startElement("legend", this);
		writer.writeText(getAttributes().get("legend"), this, clientId);

	}

	public void encodeEnd(FacesContext context) throws IOException {
		ResponseWriter writer = context.getResponseWriter();
		writer.endElement("legend");
		writer.endElement("fieldset");
	}

	public void decode(FacesContext context, UIComponent component) {
		EditableValueHolder fieldset = (EditableValueHolder) component;
		Map<String, String> requestMap = context.getExternalContext().getRequestParameterMap();
		String clientId = component.getClientId(context);

		try {
			int submittedValue = Integer.parseInt((String) requestMap.get(clientId));

			int newValue = 0;
			fieldset.setSubmittedValue("" + newValue);
			fieldset.setValid(true);
		} catch (NumberFormatException ex) {
			// let the converter take care of bad input, but we still have
			// to set the submitted value, or the converter won't have
			// any input to deal with
			fieldset.setSubmittedValue((String) requestMap.get(clientId));
		}
	}

}


The exception:

ava.lang.IndexOutOfBoundsException: Index: 1, Size: 1
       at java.util.ArrayList.RangeCheck(ArrayList.java:546)
       at java.util.ArrayList.get(ArrayList.java:321)
       at javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.java:740)
       at javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.java:743)
       at javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.java:743)
       at org.apache.myfaces.application.jsp.JspStateManagerImpl.restoreView(JspStateManagerImpl.java:300)
       at org.apache.myfaces.application.jsp.JspViewHandlerImpl.restoreView(JspViewHandlerImpl.java:354)
       at org.apache.myfaces.lifecycle.RestoreViewExecutor.execute(RestoreViewExecutor.java:85)
       at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:95)
       at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:70)
       at javax.faces.webapp.FacesServlet.service(FacesServlet.java:137)
       at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)

I had similar problems using Sun RI jsf-impl 1.2-b19 and jsf-api 1.2_02.


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (MYFACES-1783) IndexOutOfBoundsException in custom compound compoment

Posted by "Leonardo Uribe (JIRA)" <de...@myfaces.apache.org>.
    [ https://issues.apache.org/jira/browse/MYFACES-1783?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12553442 ] 

Leonardo Uribe commented on MYFACES-1783:
-----------------------------------------

deffered to 1.2.2

> IndexOutOfBoundsException in custom compound compoment
> ------------------------------------------------------
>
>                 Key: MYFACES-1783
>                 URL: https://issues.apache.org/jira/browse/MYFACES-1783
>             Project: MyFaces Core
>          Issue Type: Bug
>    Affects Versions:  1.2.0
>         Environment: Windows XP, java 1.6.0_03
> myfaces 1.2.1-SNAPSHOT and 1.2.0 on jetty-6.1.0pre0
>            Reporter: Jeroen Verhagen
>             Fix For: 1.2.2-SNAPSHOT
>
>
> The following code for a custom (compound) component causes and IndexOutOfBoundsException on submit. It renders OK.  
>  package com.mycompany;
> import javax.el.ELContext;
> import javax.el.ExpressionFactory;
> import javax.el.ValueExpression;
> import javax.faces.application.Application;
> import javax.faces.component.EditableValueHolder;
> import javax.faces.component.UIComponent;
> import javax.faces.component.UIInput;
> import javax.faces.component.UISelectItems;
> import javax.faces.component.html.HtmlSelectOneRadio;
> import javax.faces.context.FacesContext;
> import javax.faces.context.ResponseWriter;
> import javax.faces.convert.BooleanConverter;
> import javax.faces.model.SelectItem;
> import java.io.IOException;
> import java.util.Map;
> public class UIBooleanFieldset extends UIInput {
> 	public UIBooleanFieldset() {
> 		setConverter(new BooleanConverter());
> 		setRendererType(null);
> 		Application application = FacesContext.getCurrentInstance().getApplication();
> 		HtmlSelectOneRadio htmlSelectOneRadio = (HtmlSelectOneRadio) application.createComponent(HtmlSelectOneRadio.COMPONENT_TYPE);
> 		htmlSelectOneRadio.setId(getId() + "_radios");
> 		ExpressionFactory ef = FacesContext.getCurrentInstance().getApplication().getExpressionFactory();
> 		ELContext elContext = FacesContext.getCurrentInstance().getELContext();
> 		ValueExpression sexValueExpression = ef.createValueExpression(elContext, "#{persoonBean.sex}", String.class);
> 		htmlSelectOneRadio.setValueExpression("value", sexValueExpression);
> 		htmlSelectOneRadio.setLayout("pageDirection");
> 		UISelectItems selectItems = (UISelectItems) application.createComponent(UISelectItems.COMPONENT_TYPE);
> 		ValueExpression sexItemsValueExpression = ef.createValueExpression(elContext, "#{persoonBean.sexItems}", SelectItem[].class);
> 		selectItems.setValueExpression("value", sexItemsValueExpression);
> 		htmlSelectOneRadio.getChildren().add(selectItems);
> 		getChildren().add(htmlSelectOneRadio);
> 	}
> 	public void encodeBegin(FacesContext context) throws IOException {
> 		ResponseWriter writer = context.getResponseWriter();
> 		String clientId = getClientId(context);
> 		writer.startElement("fieldset", this);
> 		writer.startElement("legend", this);
> 		writer.writeText(getAttributes().get("legend"), this, clientId);
> 	}
> 	public void encodeEnd(FacesContext context) throws IOException {
> 		ResponseWriter writer = context.getResponseWriter();
> 		writer.endElement("legend");
> 		writer.endElement("fieldset");
> 	}
> 	public void decode(FacesContext context, UIComponent component) {
> 		EditableValueHolder fieldset = (EditableValueHolder) component;
> 		Map<String, String> requestMap = context.getExternalContext().getRequestParameterMap();
> 		String clientId = component.getClientId(context);
> 		try {
> 			int submittedValue = Integer.parseInt((String) requestMap.get(clientId));
> 			int newValue = 0;
> 			fieldset.setSubmittedValue("" + newValue);
> 			fieldset.setValid(true);
> 		} catch (NumberFormatException ex) {
> 			// let the converter take care of bad input, but we still have
> 			// to set the submitted value, or the converter won't have
> 			// any input to deal with
> 			fieldset.setSubmittedValue((String) requestMap.get(clientId));
> 		}
> 	}
> }
> The exception:
> ava.lang.IndexOutOfBoundsException: Index: 1, Size: 1
>        at java.util.ArrayList.RangeCheck(ArrayList.java:546)
>        at java.util.ArrayList.get(ArrayList.java:321)
>        at javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.java:740)
>        at javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.java:743)
>        at javax.faces.component.UIComponentBase.processRestoreState(UIComponentBase.java:743)
>        at org.apache.myfaces.application.jsp.JspStateManagerImpl.restoreView(JspStateManagerImpl.java:300)
>        at org.apache.myfaces.application.jsp.JspViewHandlerImpl.restoreView(JspViewHandlerImpl.java:354)
>        at org.apache.myfaces.lifecycle.RestoreViewExecutor.execute(RestoreViewExecutor.java:85)
>        at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:95)
>        at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:70)
>        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:137)
>        at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
> I had similar problems using Sun RI jsf-impl 1.2-b19 and jsf-api 1.2_02.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.