myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul van Rossem <p...@timeware.nl>
Subject <tr:selectOneListbox> throws on empty map
Date Tue, 04 Mar 2008 19:39:40 GMT
If the last item in a selectOneListbox is removed the renderer throws.
But an empty list should be allowed.
Also the exception message makes no sense (submittedValue's index "0" 
should be between "0" and "-1").
The same holds for selectOneChoice.

Example jsf file:

<?xml version="1.0" encoding="UTF-8" ?>
<jsp:root version="2.0"
  xmlns:jsp="http://java.sun.com/JSP/Page"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:h="http://java.sun.com/jsf/html"
   xmlns:tr="http://myfaces.apache.org/trinidad">
<jsp:directive.page contentType="text/html; charset=utf-8"/>
  <f:view>
    <tr:document title="selectOneListbox exception">
      <tr:outputText value="Please select the item in the list and then 
click delete"/>
      <tr:form>
        <tr:panelFormLayout>
          <tr:selectOneListbox label="Items:" value="#{bean.item}" 
size="4" autoSubmit="true">
            <f:selectItems value="#{bean.items}"/>
          </tr:selectOneListbox>
          <tr:commandButton text="Delete Selected Item" 
actionListener="#{bean.deleteItem}"
              immediate="true"/>
        </tr:panelFormLayout>
      </tr:form>
    </tr:document>
  </f:view>
</jsp:root>

Corresponding bean:

package nl.timeware.vrtsim.beans;
import java.util.*;
import javax.faces.event.ActionEvent;

public class Bean
{ 
  private int numberItems = 1;  // start with 1 item
  public int getItem()
  {  return numberItems == 1 ? 1 : -1; // either 1 or no items
  }
  public void setItem(int id)
  { 
  }
  public Map<String, Integer> getItems()
  {  System.out.println("Bean.getItems(): loading list with " + 
numberItems + " items");
    Map<String, Integer> itemMap = new TreeMap<String, Integer>();
    if (numberItems > 0)
      itemMap.put("Item 1", 1);
    return itemMap;
  }
  public void deleteItem(ActionEvent event)
  {  numberItems = 0;  // remove item
  }
}

Exception thrown:

Mar 4, 2008 7:57:35 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet Faces Servlet threw exception
java.lang.IndexOutOfBoundsException: SelectOne submittedValue's index 0 
is out of bounds. It should be between 0 and -1
    at 
org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.SimpleSelectOneRenderer.__getIndex(SimpleSelectOneRenderer.java:403)
    at 
org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.SimpleSelectOneRenderer._getSelectedIndex(SimpleSelectOneRenderer.java:470)
    at 
org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.SimpleSelectOneRenderer.encodeAllAsElement(SimpleSelectOneRenderer.java:259)
    at 
org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.FormElementRenderer.encodeAll(FormElementRenderer.java:109)
    at 
org.apache.myfaces.trinidad.render.CoreRenderer.delegateRenderer(CoreRenderer.java:335)
    at 
org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.InputLabelAndMessageRenderer.renderFieldCellContents(InputLabelAndMessageRenderer.java:146)
    at 
org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.LabelAndMessageRenderer._renderFieldCell(LabelAndMessageRenderer.java:387)
    at 
org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.LabelAndMessageRenderer.encodeAll(LabelAndMessageRenderer.java:282)
    at 
org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.InputLabelAndMessageRenderer.encodeAll(InputLabelAndMessageRenderer.java:124)
    at 
org.apache.myfaces.trinidad.render.CoreRenderer.encodeEnd(CoreRenderer.java:224)
    at 
org.apache.myfaces.trinidad.component.UIXComponentBase.encodeEnd(UIXComponentBase.java:751)
    at 
org.apache.myfaces.trinidad.render.CoreRenderer.encodeChild(CoreRenderer.java:304)
    at 
org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.PanelFormLayoutRenderer._encodeFormItem(PanelFormLayoutRenderer.java:746)
    at 
org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.PanelFormLayoutRenderer._encodeFormColumns(PanelFormLayoutRenderer.java:672)
    at 
org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.PanelFormLayoutRenderer._encodeChildren(PanelFormLayoutRenderer.java:313)
    at 
org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.PanelFormLayoutRenderer.encodeAll(PanelFormLayoutRenderer.java:199)
    at 
org.apache.myfaces.trinidad.render.CoreRenderer.encodeEnd(CoreRenderer.java:224)
    at 
org.apache.myfaces.trinidad.component.UIXComponentBase.encodeEnd(UIXComponentBase.java:751)
    at 
org.apache.myfaces.trinidad.render.RenderUtils.encodeRecursive(RenderUtils.java:68)
    at 
org.apache.myfaces.trinidad.render.CoreRenderer.encodeChild(CoreRenderer.java:299)
    at 
org.apache.myfaces.trinidad.render.CoreRenderer.encodeAllChildren(CoreRenderer.java:321)
    at 
org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.PanelPartialRootRenderer.renderContent(PanelPartialRootRenderer.java:64)
    at 
org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.BodyRenderer.renderContent(BodyRenderer.java:139)
    at 
org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.PanelPartialRootRenderer.encodeAll(PanelPartialRootRenderer.java:119)
    at 
org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.BodyRenderer.encodeAll(BodyRenderer.java:79)
    at 
org.apache.myfaces.trinidad.render.CoreRenderer.delegateRenderer(CoreRenderer.java:335)
    at 
org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.DocumentRenderer.encodeAll(DocumentRenderer.java:80)
    at 
org.apache.myfaces.trinidad.render.CoreRenderer.encodeEnd(CoreRenderer.java:224)
    at 
org.apache.myfaces.trinidad.component.UIXComponentBase.encodeEnd(UIXComponentBase.java:751)
    at 
org.apache.myfaces.trinidad.component.UIXComponentBase.__encodeRecursive(UIXComponentBase.java:1339)
    at 
org.apache.myfaces.trinidad.component.UIXComponentBase.encodeAll(UIXComponentBase.java:771)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:942)
    at 
com.sun.faces.application.ViewHandlerImpl.doRenderView(ViewHandlerImpl.java:273)
    at 
com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:204)
    at 
javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:189)
    at 
org.apache.myfaces.trinidadinternal.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:176)
    at 
com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:110)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
    at 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at 
org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl._invokeDoFilter(TrinidadFilterImpl.java:238)
    at 
org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl._doFilterImpl(TrinidadFilterImpl.java:195)
    at 
org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl.doFilter(TrinidadFilterImpl.java:138)
    at 
org.apache.myfaces.trinidad.webapp.TrinidadFilter.doFilter(TrinidadFilter.java:92)
    at 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at 
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at 
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at 
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    at 
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at 
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at 
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
    at 
org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:856)
    at 
org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:565)
    at 
org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1509)
    at java.lang.Thread.run(Unknown Source)


Mime
View raw message