3 Replies Latest reply on Jun 21, 2007 6:01 AM by Ilya Shaikovsky

    Problem with  String index out of range: 0

    Ivan Tufegdzic Newbie

      Hello.
      I have one problem. I am am using seam,facelts,...
      When I click on link (which should open new panel down existing panel), I have a error:

      13:07:06,694 ERROR [STDERR] Jun 20, 2007 1:07:06 PM com.sun.facelets.FaceletViewHandler handleRenderException
      SEVERE: Error Rendering View[/shop/manufacturer/manufacturerdetails.xhtml]
      java.lang.StringIndexOutOfBoundsException: String index out of range: 0
      at java.lang.String.charAt(String.java:558)
      at javax.faces.component.UIComponentBase.findComponent(UIComponentBase.java:557)
      at org.richfaces.renderkit.html.PanelBarRendererBase.expanded(PanelBarRendererBase.java:65)
      at org.richfaces.renderkit.html.PanelBarRenderer.doEncodeEnd(PanelBarRenderer.java:167)
      at org.richfaces.renderkit.html.PanelBarRenderer.doEncodeEnd(PanelBarRenderer.java:182)
      at org.ajax4jsf.framework.renderer.RendererBase.encodeEnd(RendererBase.java:135)
      at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:833)
      at javax.faces.component.UIComponent.encodeAll(UIComponent.java:896)
      at javax.faces.component.UIComponent.encodeAll(UIComponent.java:892)
      at javax.faces.component.UIComponent.encodeAll(UIComponent.java:892)
      at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:571)
      at org.ajax4jsf.framework.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:108)
      at org.ajax4jsf.framework.ajax.AjaxViewHandler.renderView(AjaxViewHandler.java:233)
      at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:106)
      at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
      at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:70)
      at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:64)
      at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:56)
      at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:81)
      at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:56)
      at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:62)
      at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:56)
      at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:47)
      at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:56)
      at org.ajax4jsf.framework.ajax.xmlfilter.BaseFilter.doFilter(BaseFilter.java:293)
      at org.jboss.seam.web.AbstractAjax4jsfFilter.doFilter(AbstractAjax4jsfFilter.java:35)
      at org.jboss.seam.web.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:56)
      at org.jboss.seam.web.SeamFilter.doFilter(SeamFilter.java:127)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:147)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.ajax4jsf.framework.ajax.xmlfilter.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:127)
      at org.ajax4jsf.framework.ajax.xmlfilter.BaseFilter.doFilter(BaseFilter.java:277)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
      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:230)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
      at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
      at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
      at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:241)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:580)
      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
      at java.lang.Thread.run(Thread.java:595)


      But I not use any String in this method. Method which opened that panel is:


      public void toggleProducts() {
      saveObject(manufacturer);
      productsForAddingInManufacturer.refresh();
      openProducts=!openProducts;
      }

      Thanks
      it

        • 1. Re: Problem with  String index out of range: 0
          Ilya Shaikovsky Master

          Please share more complete sources.

          • 2. Re: Problem with  String index out of range: 0
            Ivan Tufegdzic Newbie

            Handler is:
            @Name("groupHandler")
            @Scope(ScopeType.CONVERSATION)
            public class GroupHandlerBean extends CommonManagedBean {

            /**
            *
            */
            private static final long serialVersionUID = 576607068656983177L;

            @Out(required=false,scope=ScopeType.CONVERSATION)
            @In(required=false,scope=ScopeType.CONVERSATION)
            private ProductGroup currentGroup;

            @SuppressWarnings("unused")
            @Out(required=false)
            private List groups;

            private boolean editGroup = false;

            @In(create=true)
            ProductGroupList productGroupList;

            @In(create=true)
            private EntityQuery productsForAddingInGroup;

            /**
            * Return flag for edit/add product group.
            * @return true if is selected action for edit/add product group
            * @author Ivan Tufegdzic
            */
            public boolean isEditGroup() {
            return editGroup;

            }

            /**
            * Factory method creates new product group
            * if it is null.
            * @author Ivan Tufegdzic
            */
            @Factory("currentGroup")
            public void getCurrentGroup() {
            currentGroup=new ProductGroup();
            }

            /**
            * Change boolean value which represents adding group.
            * @author Ivan Tufegdzic
            */
            @Begin(join=true)
            public String toggleGroup() {
            currentGroup=null;
            return "/shop/productgroup/productgroupdetails.xhtml";
            }

            /**
            * Method for redirecting group for editing.
            * @param p the group which will be current group for editing.
            * @author Ivan Tufegdzic
            */
            @Begin(join=true)
            public String redirectGroup(ProductGroup p) {
            currentGroup = p;
            Contexts.getConversationContext().remove("productsOfGroup");
            return "/shop/productgroup/productgroupdetails.xhtml";
            }


            /**
            * Save new group or edit existing.
            * @exception Exception only return without change
            * @author Ivan Tufegdzic
            */
            @End
            public String addGroup() {
            if (currentGroup != null) {
            try {
            saveObject(currentGroup);
            productGroupList.refresh();
            Contexts.getConversationContext().remove("groups");
            editGroup = false;
            } catch (Exception e) {
            return null;
            }
            }
            return "/shop/productgroups/productgroups.xhtml";
            }

            /**
            * Setting product group in product on null, that is cut of relation
            * between this group and product.
            * After this method products for this group will be reloaded again.
            * @param product the product which will be removed from group
            * @author Ivan Tufegdzic
            */
            @SuppressWarnings("unchecked")
            public void removeFromGroup(Product product){
            product.getProductGroup().getProducts().remove(product);
            product.setProductGroup(null);
            product.setModified(new Date());
            productsForAddingInGroup.refresh();
            }

            /**
            * Get all product groups from database, for list in drop down menu
            * @exception Exception if catch exception return new empty list
            * @author Ivan Tufegdzic
            */
            @SuppressWarnings("unchecked")
            @Factory("groups")
            public void getGroups() {
            try {
            groups=(List) entityManager.createQuery("from ProductGroup").getResultList();
            } catch (Exception e) {
            groups=new LinkedList();
            }
            }

            /**
            * Removing one group,but product is still in base, but they have null
            * value on field productGroup,now.
            * @author Ivan Tufegdzic
            */
            @SuppressWarnings("unchecked")
            public void deleteGroups() {
            for(ProductGroup po:(List)productGroupList.getResultList()){
            if(po.isSelected()){
            for (Product p:po.getProducts()) {
            p.setProductGroup(null);
            }
            removeObject(po);
            }
            }
            groups=(List) newHandledEntity();
            productGroupList.refresh();
            }

            public void toggle() {
            saveObject(currentGroup);
            editGroup=!editGroup;
            productsForAddingInGroup.refresh();
            }

            @End(beforeRedirect=true)
            public String goBack(){
            editGroup=false;
            return "/shop/productgroups/productgroups.xhtml";
            }
            }

            Page is:

            <ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
            xmlns:s="http://jboss.com/products/seam/taglib"
            xmlns:f="http://java.sun.com/jsf/core"
            xmlns:h="http://java.sun.com/jsf/html"
            xmlns:t="http://myfaces.apache.org/tomahawk"
            xmlns:rich="http://richfaces.ajax4jsf.org/rich"
            xmlns:ss="http://myfaces.apache.org/sandbox"
            xmlns:a4j="https://ajax4jsf.dev.java.net/ajax"
            template="/layout/templateallpage.xhtml">
            <ui:define name="body">
            <a4j:form>
            <rich:panel>
            <h2 align="center"><h:outputText
            value="#{messages.add} #{messages.group}"
            rendered="#{empty currentGroup.id}" /> <t:outputText
            value="#{messages.administrationtextrule} #{messages.group}"
            rendered="#{not empty currentGroup.id}" /></h2>
            <rich:panel styleClass="inpanelBody2"
            headerClass="standardRich_SortHeader" id="panel">
            <rich:dropSupport id="dropProduct" acceptedTypes="number"
            reRender="productListGroup"
            dropListener="#{dragDropHandler.addProductDraggGroup}">
            </rich:dropSupport>
            <f:facet name="header">
            <t:panelGroup>
            <t:commandLink action="#{groupHandler.toggle}">
            <t:graphicImage value="/images/gtk-new.gif"
            title="#{messages.addproduct}"></t:graphicImage>
            </t:commandLink>
            <t:outputText value="#{currentGroup.name}" />
            </t:panelGroup>
            </f:facet>
            <t:panelGrid columns="2">
            <t:outputText value="#{messages.name}" />
            <t:inputText id="name" value="#{currentGroup.name}" required="true"></t:inputText>
            <t:htmlTag value="br" />
            <t:htmlTag value="br" />
            </t:panelGrid>



            <rich:panelBar>
            <rich:panelBarItem label="#{messages.newUserDescription}">
            <t:inputTextarea id="description"
            value="#{currentGroup.description}">
            </t:inputTextarea>
            </rich:panelBarItem>
            <rich:panelBarItem label="#{messages.products}"
            render="{not empty currentGroup.products}">
            <rich:dataTable width="100%" var="productGroup"
            id="productListGroup" value="#{currentGroup.products}"
            render="{not empty currentGroup.products}">
            <f:facet name="header">

            <rich:columnGroup>
            <rich:column>
            <h:outputText value="#{messages.image}" />
            </rich:column>
            <rich:column>
            <h:outputText value="#{messages.name}"></h:outputText>
            </rich:column>
            <rich:column>
            <h:outputText value="#{messages.newUserDescription}"></h:outputText>
            </rich:column>
            <rich:column>
            <h:outputText value="#{messages.promotion}"></h:outputText>
            </rich:column>
            <rich:column>
            <h:outputText value="#{messages.price}"></h:outputText>
            </rich:column>
            <rich:column>
            <h:outputText value="#{messages.parent}"></h:outputText>
            </rich:column>
            <rich:column>
            <h:outputText value="#{messages.manufacturer}"></h:outputText>
            </rich:column>
            <rich:column>
            <h:outputText value="#{messages.delete}" />
            </rich:column>
            </rich:columnGroup>
            </f:facet>
            <rich:column>
            <t:commandLink
            action="#{selected.redirectProduct(productGroup)}">
            <t:graphicImage width="30" height="30"
            value="#{productGroup.image}" />
            </t:commandLink>
            </rich:column>
            <rich:column>
            <t:commandLink
            action="#{selected.redirectProduct(productGroup)}">
            <h:outputText value="#{productGroup.name}"></h:outputText>
            </t:commandLink>
            </rich:column>
            <rich:column>
            <h:outputText value="#{productGroup.description}"></h:outputText>
            </rich:column>
            <rich:column>
            <h:outputText value="#{productGroup.promotion}"></h:outputText>
            </rich:column>
            <rich:column>
            <h:outputText value="#{productGroup.price}"></h:outputText>
            </rich:column>
            <rich:column>
            <h:outputText value="#{productGroup.category.name}"></h:outputText>
            </rich:column>
            <rich:column>
            <h:outputText value="#{productGroup.manufacturer.name}"></h:outputText>
            </rich:column>
            <rich:column>
            <t:commandLink
            onclick="if(!confirm('#{messages.text24}'))return false"
            action="#{groupHandler.removeFromGroup(productGroup)}">
            <t:graphicImage value="/images/delete.gif"></t:graphicImage>
            </t:commandLink>
            </rich:column>
            </rich:dataTable>
            </rich:panelBarItem>
            </rich:panelBar>
            </rich:panel>
            <rich:panel style="inpanelBody2"
            headerClass="standardRich_SortHeader">
            <f:facet name="header">
            <t:panelGroup>
            <t:commandLink action="#{groupHandler.goBack}">
            <t:graphicImage value="/images/back_gray.gif"></t:graphicImage>
            </t:commandLink>
            <rich:spacer width="10"></rich:spacer>
            <t:commandLink action="#{groupHandler.addGroup}">
            <t:graphicImage value="/images/btn_save_gray.gif"></t:graphicImage>
            </t:commandLink>
            </t:panelGroup>
            </f:facet>
            </rich:panel>

            </rich:panel>
            <rich:panelBar>
            <rich:datascroller for="tableGroup" maxPages="50" id="scroll"
            rendered="#{groupHandler.editGroup}" />
            <rich:spacer height="10" rendered="#{groupHandler.editGroup}" />
            <rich:dragIndicator id="indicatorgroup"></rich:dragIndicator>
            <rich:dataTable width="100%" rows="10"
            rendered="#{groupHandler.editGroup}" columnClasses="col"
            var="product" id="tableGroup" value="#{productsForAddingInGroup.resultList}">
            <f:facet name="header">
            <rich:columnGroup>
            <h:column>
            <h:outputText value="#{messages.image}" />
            </h:column>
            <h:column>
            <h:outputText value="#{messages.product}" />
            </h:column>
            <h:column>
            <h:outputText value="#{messages.price}" />
            </h:column>

            <h:column>
            <h:outputText value="#{messages.newUserDescription}" />
            </h:column>
            <h:column>
            <h:outputText value="#{messages.category}" />
            </h:column>
            </rich:columnGroup>
            </f:facet>
            <h:column>
            <a4j:outputPanel style="border:1px solid gray;padding:2px;"
            layout="block">
            <rich:dragSupport dragIndicator=":indicatorgroup"
            dragType="number" dragValue="#{product.id}">
            <a4j:actionparam value="#{product.id}" name="id" />
            </rich:dragSupport>
            <h:graphicImage width="30" height="30" value="#{product.image}" />
            </a4j:outputPanel>
            </h:column>
            <h:column>
            <t:commandLink action="#{selected.redirectProduct(product)}">
            <h:outputText styleClass="headerText" value="#{product.name}" />
            </t:commandLink>
            </h:column>
            <h:column>
            <h:outputText styleClass="headerText" value="#{product.price}" />
            </h:column>
            <h:column>
            <h:outputText styleClass="headerText"
            value="#{product.description}" />
            </h:column>
            <h:column>
            <h:outputText styleClass="headerText"
            value="#{product.category.name}" />
            </h:column>
            </rich:dataTable>
            </rich:panelBar>
            </a4j:form>
            </ui:define>
            </ui:composition>

            On early version ajax and rich, everything is worked fine.Now I have newest version.
            Thanks.
            it

            • 3. Re: Problem with  String index out of range: 0
              Ilya Shaikovsky Master

              Your second Panel Bar has no items - it isn't designed to be used in this way.