4 Replies Latest reply on Aug 21, 2008 12:15 AM by svadu

    Warning and Transaction Failed on EntityQuery

    sandman202

      I have a class called CodeList.java that I use to retrieve a listing when I perform a search. On my search CodeList.xhtml when I select both type and active, I receive on the top of the screen is Transaction failed. However, if I select only one of these options, it works just fine. In the log file I also see the following:



      21:58:02,415 WARN  [lifecycle] javax.el.ELException: /CodeList.xhtml @63,65 rendered="#{empty codeList.resultList}": Error reading 'resultList' on type com.ds.artwork.CodeList_$$_javassist_10
      



      CodeList.xhtml


      <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
                                   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
                      xmlns:s="http://jboss.com/products/seam/taglib"
                      xmlns:ui="http://java.sun.com/jsf/facelets"
                      xmlns:f="http://java.sun.com/jsf/core"
                      xmlns:h="http://java.sun.com/jsf/html"
                      xmlns:a="http://richfaces.org/a4j"                
                      xmlns:rich="http://richfaces.org/rich"
                      template="layout/template.xhtml">
                             
      <ui:define name="body">
          
          <h:messages globalOnly="true" styleClass="message"/>
          
          <h:form id="cityStateZipSearch" styleClass="edit">
          
              <rich:simpleTogglePanel label="Code Search Parameters" switchType="ajax">
                                      
                      <s:decorate id="typeDecoration" template="layout/display.xhtml">
                      <ui:define name="label">Type</ui:define>               
                              <h:selectOneMenu value="#{codeList.code.type}" id="codeType" >
                                      <s:selectItems value="#{codeList.codeTypes}" var="_codeType" label="#{_codeType.value}" 
                                                                 noSelectionLabel="Please Select Type... "/>
                                      <s:convertEnum />
                              </h:selectOneMenu>
                      </s:decorate>
                              
                  <s:decorate template="layout/display.xhtml">
                      <ui:define name="label">Code</ui:define>
                      <h:inputText id="code" value="#{codeList.code.code}"/>
                  </s:decorate>
                          
                  <s:decorate template="layout/display.xhtml">
                      <ui:define name="label">Description</ui:define>
                      <h:inputText id="description" value="#{codeList.code.description}"/>
                  </s:decorate>
                          
                  <s:decorate id="activeDecoration" template="layout/display.xhtml">
                      <ui:define name="label">Active</ui:define>               
                              <h:selectOneMenu id="active" 
                                            value="#{codeList.code.strActive}">                               
                                   <f:selectItems value="#{codeList.booleanCodes}" />                                   
                              </h:selectOneMenu>
                      </s:decorate>              
              
              </rich:simpleTogglePanel>
              
              <div class="actionButtons">
                  <h:commandButton id="search" value="Search" action="/CodeList.xhtml"/>
              </div>
              
          </h:form>  
          
              
          
          <rich:panel>
              <f:facet name="header">Code Search Results</f:facet>
              
              <div class="results" id="codeList">
              
                  <h:outputText value="No code exists" 
                             rendered="#{empty codeList.resultList}"/>
                         
                  <rich:dataTable id="codeList" 
                                         var="_code"
                               value="#{codeList.resultList}" 
                            rendered="#{not empty codeList.resultList}">
                         
                              <h:column>
                                  <f:facet name="header">
                                      <s:link styleClass="columnHeader"
                                                   value="Type #{codeList.order=='type.value asc' ? messages.down : ( codeList.order=='type.value desc' ? messages.up : '' )}">
                                          <f:param name="order" value="#{codeList.order=='type.value asc' ? 'type.value desc' : 'type.value asc'}"/>
                                      </s:link>
                                  </f:facet>
                                  #{_code.type}
                              </h:column>
                                 
                              <h:column>
                                  <f:facet name="header">
                                      <s:link styleClass="columnHeader"
                                                   value="Code #{codeList.order=='code asc' ? messages.down : ( codeList.order=='code desc' ? messages.up : '' )}">
                                          <f:param name="order" value="#{codeList.order=='code asc' ? 'code desc' : 'code asc'}"/>
                                      </s:link>
                                  </f:facet>
                                  #{_code.code}
                              </h:column>  
                              
                              <h:column>
                                  <f:facet name="header">
                                      <s:link styleClass="columnHeader"
                                                   value="Description #{codeList.order=='description asc' ? messages.down : ( codeList.order=='description desc' ? messages.up : '' )}">
                                          <f:param name="order" value="#{codeList.order=='description asc' ? 'description desc' : 'description asc'}"/>
                                      </s:link>
                                  </f:facet>
                                  #{_code.description}
                              </h:column>               
                              
                              <h:column>
                                  <f:facet name="header">
                                      <s:link styleClass="columnHeader"
                                                   value="Available #{codeList.order=='active asc' ? messages.down : ( codeList.order=='active desc' ? messages.up : '' )}">
                                          <f:param name="order" value="#{codeList.order=='active asc' ? 'active desc' : 'active asc'}"/>
                                      </s:link>
                                  </f:facet>
                                  #{_code.active}
                              </h:column> 
                              
                      
                                          
                              <h:column>
                                  <f:facet name="header">Action</f:facet>
                                  <s:link view="/#{empty from ? 'Code' : from}.xhtml" 
                                         value="Select" 
                                            id="code">
                                      <f:param name="codeId" 
                                              value="#{_code.id}"/>
                                  </s:link>
                              </h:column>
                              
                  </rich:dataTable>
              
              </div>
              
          </rich:panel>
          
          <s:div styleClass="actionButtons" rendered="#{empty from}">
              <s:button view="/CodeEdit.xhtml"
                          id="create" 
                       value="Create Code">
                  <f:param name="codeId"/>
              </s:button>                         
          </s:div>
          
      </ui:define>
      
      </ui:composition>
      



      CodeList.java


      package com.ds.artwork;
      
      import java.util.ArrayList;
      import java.util.Arrays;
      import java.util.List;
      
      import javax.faces.model.SelectItem;
      
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.framework.EntityQuery;
      
      import com.ds.artwork.entity.Code;
      import com.ds.artwork.entity.Item;
      import com.ds.artwork.utils.CodeType;
      
      @Name("codeList")
      public class CodeList extends EntityQuery<Item> {
      
              private static final long serialVersionUID = 1008397397027179231L;
      
              // @In(required=false) @Out(required=false)
              // private String active = "";
      
              private static final String[] RESTRICTIONS = {
                              "code.type = #{codeList.code.type}",
                              "lower(code.code) like concat(lower(#{codeList.code.code}),'%')",
                              "lower(code.description) like concat(lower(#{codeList.code.description}),'%')", 
                              };
      
              private Code code = new Code();
      
              @Override
              public String getEjbql() {
                      return "select code from Code code";
              }
      
              @Override
              public Integer getMaxResults() {
                      return 25;
              }
      
              public Code getCode() {
                      return code;
              }
      
              @Override
              public List<String> getRestrictions() {
                      // return Arrays.asList(RESTRICTIONS);
                      //List<String> restrictions = Arrays.asList(RESTRICTIONS);
              
                      ArrayList<String> restrictions = new ArrayList<String>(0);
                      restrictions.addAll(Arrays.asList(RESTRICTIONS));
      
                      if (code.getStrActive() != null) {
                              restrictions.add("code.active = #{" + Boolean.valueOf(code.getStrActive()) + "}");
                      }
                      return restrictions;
              }
              
              @Override
              public String getOrder() {
                      if (super.getOrder() == null) {
                              setOrder("type asc");
                      }
                      return super.getOrder();
              }
      
              public CodeType[] getCodeTypes() {
                      return CodeType.values();
              }
      
              @SuppressWarnings("unchecked")
              public List<Code> getBooleanCodes() {
                      // return
                      // this.getEntityManager().createNamedQuery("code.findCodesByType").setParameter("type",
                      // CodeType.BOOLEAN).getResultList();
                      List choices = new ArrayList();
                      choices.add(new SelectItem("", " "));
                      choices.add(new SelectItem("true", "True"));
                      choices.add(new SelectItem("false", "False"));
                      return choices;
              }
      
              @SuppressWarnings("unchecked")
              public List<Code> getEditionCodes() {
                      return this.getEntityManager().createNamedQuery("code.findCodesByType")
                                      .setParameter("type", CodeType.EDITION).getResultList();
              }
      
              @SuppressWarnings("unchecked")
              public List<Code> getMediumCodes() {
                      return this.getEntityManager().createNamedQuery("code.findCodesByType")
                                      .setParameter("type", CodeType.MEDIUM).getResultList();
              }
      
      }
      



      Does anyone know what the problem is?


        • 1. Re: Warning and Transaction Failed on EntityQuery
          sandman202

          I need to clarify what I originally said.


          When I select both active and type, the query works, but I receive the transaction failed on the query screen and I also get the warning in the log file.


          When I select either active or type, the query works without the 2 messages appearing.


          I am using Seam-2.1.0-snapshot.

          • 2. Re: Warning and Transaction Failed on EntityQuery
            sandman202

            It appears the problem is in the getRestrictions method and the adding of another restriction. Going from 3 restrictions to 4, causes the problem.


            So, let me back up and ask this. What is the proper way to handle a Boolean on a search? Initially, when you go to the search screen, the listing displays everything. If you use a checkbox, the selection is true or false. I want the user to be able to select based upon a selectOneMenu one of the following: nothing, true or false.


            I changed my Code.java adding:



                 @Transient
                 public String getStrActive() {
                      if (active == null) {
                           strActive = null;
                      } else if (active.booleanValue()) {
                           strActive = "True";
                      } else {
                           strActive = "False";
                      }
                      return strActive;
                 }
            



            and added to the RESTRICTIONS in CodeList.java



            "code.strActive = #{codeList.code.strActive}",
            



            This is now selecting the data as I would like it. However, when I select the type and active, then search, the value on the active disappears.


            • 3. Re: Warning and Transaction Failed on EntityQuery
              sandman202

              I decided to change the active field to an enum like the type field. It now works as I am wanting.

              • 4. Re: Warning and Transaction Failed on EntityQuery

                Seems to be a known/relevant issue? See JBSEAM-2562