3 Replies Latest reply on Jun 19, 2007 1:35 PM by Jason Thiesse

    Validation Error on Simple a4j:support Call

    Jason Thiesse Newbie

      I am trying to add an a4j call to an existing Faces form. I am getting two errors and not sure if the are related.

      The errors:

      [6/19/07 8:59:21:958 CDT] 00000025 jsf E com.sun.faces.context.FacesContextImpl addMessage Adding Message[sourceId=docedit:tier1,summary=Validation Error: Value is not valid)
      [6/19/07 8:59:21:958 CDT] 00000025 ServletWrappe E SRVE0068E: Could not invoke the service() method on servlet FacesServlet. Exception thrown : java.lang.StringIndexOutOfBoundsException: String index out of range: 0
       at java.lang.String.charAt(String.java(Compiled Code))
       at org.ajax4jsf.framework.ajax.AjaxContext.convertId(AjaxContext.java:698)
       at org.ajax4jsf.framework.ajax.AjaxContext.addRegionsFromComponent(AjaxContext.java:683)
       at org.ajax4jsf.framework.ajax.AjaxActionComponent.setupReRender(AjaxActionComponent.java:72)
       at org.ajax4jsf.framework.ajax.AjaxActionComponent.broadcast(AjaxActionComponent.java:51)
       at org.ajax4jsf.framework.ajax.AjaxViewRoot.processEvents(AjaxViewRoot.java:180)
       at org.ajax4jsf.framework.ajax.AjaxViewRoot.broadcastAjaxEvents(AjaxViewRoot.java:198)
       at org.ajax4jsf.framework.ajax.AjaxViewHandler.processAjaxEvents(AjaxViewHandler.java:270)
       at org.ajax4jsf.framework.ajax.AjaxViewHandler.renderView(AjaxViewHandler.java:226)
       at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:87)
       at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:220)
       at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:118)
       at javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)
       at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1282)
      at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1239)
      ...
      


      The JSP where the form resides:

      <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
      <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
      <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
      <%@ taglib uri="https://ajax4jsf.dev.java.net/ajax" prefix="a4j"%>
      
      ...
      
      <body>
      <f:view>
      ...
      
       <h:form id="docedit">
      ...
      
       <fieldset><legend>Organization & Functional Information</legend>
      
       <label for="docedit:tier1">Tier 1:</label>
       <a4j:region selfRendered="true">
       <h:selectOneMenu id="tier1" value="#{pc_DocumentEdit.selectedTier1}" required="false" styleClass="input-width-dropdown-reg">
       <f:selectItems value="#{pc_DocumentEdit.referenceTier1}"/>
       <a4j:support event="onchange" action="#{pc_DocumentEdit.tier1Change}" ajaxSingle="true" reRender="" immediate="false" />
       </h:selectOneMenu>
      
       </a4j:region>
       <br/>
      
       </fieldset>
      
      
       <h:commandButton type="submit" id="docupdate" action="#{pc_DocumentEdit.update}" value="Save Document"/>
      
       </h:form>
      ...
      
      </f:view>
      </body>
      </html>
      
      


      I have the following in my faces-config.xml file:

      <managed-bean>
       <managed-bean-name>pc_TiersAndLevels</managed-bean-name>
       <managed-bean-class>TiersAndLevels</managed-bean-class>
       <managed-bean-scope>session</managed-bean-scope>
       </managed-bean>
      
       <managed-bean>
       <managed-bean-name>pc_DocumentEdit</managed-bean-name>
       <managed-bean-class>DocumentEdit</managed-bean-class>
       <managed-bean-scope>request</managed-bean-scope>
       <managed-property>
       <property-name>docid</property-name>
       <value>#{param.docid}</value>
       </managed-property>
       <managed-property>
       <property-name>tiersAndLevels</property-name>
       <property-class>TiersAndLevels</property-class>
       <value>#{pc_TiersAndLevels}</value>
       </managed-property>
       </managed-bean>
      



      And the important parts of the backing bean:

      /*
       * Auto-generated by AppFactory tool on Mon Jun 11 12:32:46 CDT 2007
       *
       */
      
      import java.sql.SQLException;
      import java.util.ArrayList;
      
      import javax.faces.model.SelectItem;
      
      import PageCodeBase;
      import Util;
      
      public class DocumentEdit extends PageCodeBase
      {
      
       //Member variables
       private DocumentBean documentBean;
      
       private SelectItem[] referenceTypes;
       private SelectItem[] referenceStatuses;
       private SelectItem[] referenceMonths;
      
       /*
       * Tier and Level Stuff
       */
       private TiersAndLevels tiersAndLevels;
       private SelectItem[] referenceTier1;
       private String selectedTier1;
      
       private String docid;
      
      
       public DocumentEdit()
       {
       documentBean = new DocumentBean();
       }
      
      ...
      
       /*
       * @return Returns the referenceTier1.
       */
       public SelectItem[] getReferenceTier1()
       {
       if (referenceTier1 == null)
       {
       referenceTier1 = new SelectItem[1];
      
       ArrayList tiers = getTiersAndLevels().getTier1List();
      
       if ((tiers != null) && (tiers.size() > 0))
       {
       referenceTier1 = new SelectItem[tiers.size() + 1];
      
       for (int i = 0; i < tiers.size(); i++)
       {
       referenceTier1[i + 1] = new SelectItem(((TierRefBean) tiers
       .get(i)).getTierIk(), ((TierRefBean) tiers
       .get(i)).getTierName());
       }
      
       referenceTier1[0] = new SelectItem("-1", ">> Select Tier <<");
       }
       }
      
       return referenceTier1;
       }
       /**
       * @param referenceTier1 The referenceTier1 to set.
       */
       public void setReferenceTier1(SelectItem[] referenceTier1)
       {
       this.referenceTier1 = referenceTier1;
       }
       /**
       * @return Returns the selectedTier1.
       */
       public String getSelectedTier1()
       {
       return selectedTier1;
       }
       /**
       * @param selectedTier1 The selectedTier1 to set.
       */
       public void setSelectedTier1(String selectedTier1)
       {
      System.out.println("JASON >>> DocumentEdit.setSelectedTier1: " + selectedTier1);
       this.selectedTier1 = selectedTier1;
       }
      
       public String tier1Change()
       {
      System.out.println("JASON >>> DocumentEdit.tier1Change >>> Selected Tier1: " + selectedTier1);
       return null;
       }
       /**
       * @return Returns the tiersAndLevels.
       */
       public TiersAndLevels getTiersAndLevels()
       {
       return tiersAndLevels;
       }
       /**
       * @param tiersAndLevels The tiersAndLevels to set.
       */
       public void setTiersAndLevels(TiersAndLevels tiersAndLevels)
       {
       this.tiersAndLevels = tiersAndLevels;
       }
      }
      


      Thanks in advance for any help.

        • 1. Re: Validation Error on Simple a4j:support Call
          Jason Thiesse Newbie

          Little bit of an update. If I create my drop down using the following I do not get the validation error on the a4j:support call:

          referenceTier1 = new SelectItem[2];
          referenceTier1[0] = new SelectItem("-1", ">> Select Tier <<");
          referenceTier1[1] = new SelectItem("1", ">> Junk <<");
          


          rather than:

          referenceTier1 = new SelectItem[1];
          
          ArrayList tiers = getTiersAndLevels().getTier1List();
          
          if ((tiers != null) && (tiers.size() > 0))
          {
           referenceTier1 = new SelectItem[tiers.size() + 1];
          
           for (int i = 0; i < tiers.size(); i++)
           {
           referenceTier1[i + 1] = new SelectItem(((TierRefBean) tiers
           .get(i)).getTierIk(), ((TierRefBean) tiers
           .get(i)).getTierName());
           }
           referenceTier1[0] = new SelectItem("-1", ">> Select Tier <<");
          }
          else
          {
           referenceTier1[0] = new SelectItem("-1", ">> No Listed Tiers <<");
          }
          


          Maybe this is where I do not under stand the life cycle of Faces well enough. Why does Faces need to original component to properly pass the value from the form?

          The bad news is I am still getting the following exception after my .change() method is called:

          [6/19/07 10:12:40:999 CDT] 00000027 ServletWrappe E SRVE0068E: Could not invoke the service() method on servlet FacesServlet. Exception thrown : java.lang.StringIndexOutOfBoundsException: String index out of range: 0
           at java.lang.String.charAt(String.java(Compiled Code))
           at org.ajax4jsf.framework.ajax.AjaxContext.convertId(AjaxContext.java:698)
           at org.ajax4jsf.framework.ajax.AjaxContext.addRegionsFromComponent(AjaxContext.java:683)
           at org.ajax4jsf.framework.ajax.AjaxActionComponent.setupReRender(AjaxActionComponent.java:72)
           at org.ajax4jsf.framework.ajax.AjaxActionComponent.broadcast(AjaxActionComponent.java:51)
           at org.ajax4jsf.framework.ajax.AjaxViewRoot.processEvents(AjaxViewRoot.java:180)
           at org.ajax4jsf.framework.ajax.AjaxViewRoot.broadcastAjaxEvents(AjaxViewRoot.java:198)
           at org.ajax4jsf.framework.ajax.AjaxViewHandler.processAjaxEvents(AjaxViewHandler.java:270)
           at org.ajax4jsf.framework.ajax.AjaxViewHandler.renderView(AjaxViewHandler.java:226)
           at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:87)
           at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:220)
           at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:118)
           at javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)
           at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1282)
           at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1239)
           at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:136)
           at org.ajax4jsf.framework.ajax.xmlfilter.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:96)
           at org.ajax4jsf.framework.ajax.xmlfilter.BaseFilter.doFilter(BaseFilter.java:220)
           at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:142)
           at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:121)
           at edu.mayo.security.WatchDogFilter.doFilter(WatchDogFilter.java:157)
           at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:142)
           at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:121)
           at com.ibm.ws.webcontainer.filter.WebAppFilterChain._doFilter(WebAppFilterChain.java:82)
           at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:670)
           at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:89)
           at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:1878)
           at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:84)
           at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:472)
           at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:411)
           at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:101)
           at com.ibm.ws.tcp.channel.impl.WorkQueueManager.requestComplete(WorkQueueManager.java:566)
           at com.ibm.ws.tcp.channel.impl.WorkQueueManager.attemptIO(WorkQueueManager.java:619)
           at com.ibm.ws.tcp.channel.impl.WorkQueueManager.workerRun(WorkQueueManager.java:952)
           at com.ibm.ws.tcp.channel.impl.WorkQueueManager$Worker.run(WorkQueueManager.java:1039)
           at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java(Compiled Code))
          


          • 2. Re: Validation Error on Simple a4j:support Call
            Jason Thiesse Newbie

            Another update: I have solved the "java.lang.StringIndexOutOfBoundsException" error. I had an empty "reRender" attribute on my :support tag. Kind of sounds like a bug or at best a not nice feature.

            I am still battling with my drop down list. Is there anyone using :support tag with a h:selectOneMenu?

            • 3. Re: Validation Error on Simple a4j:support Call
              Jason Thiesse Newbie

              Problem SOLVED:

              I had my value type incorrect on my h:selectOneItem. I had it set as a String but was populating the SelectItem objects with an Integer for the first parameter.

              A lot of posts for a simple mistake but hopefully it will help others running into the same type of issue.