2 Replies Latest reply on Apr 20, 2008 4:13 PM by bogdanminciu.bogdan.minciu.yahoo.com

    Can't access database in rendered attribute

    bogdanminciu.bogdan.minciu.yahoo.com

      Hello guys and girls,


      I have this piece of code in my page:


      <h:dataTable id="zonesDT" value="#{zones}" var="zone">
        <h:column>
          <h:outputText rendered="#{pageView.embedsOpportunity(zone)}" value="This zone embeds an opportunity"/>
        </h:column>
      </h:dataTable>
      



      And this bean:


      @Stateful
      @Name("pageView")
      @Scope(ScopeType.CONVERSATION)
      public class PageViewBean implements LocalPageView {
      
          @DataModel
          private List<Zone> zones;
      ...
          public Boolean embedsOpportunity(Zone zone) {
              if(zone.getContentTypeFQDN().equals("com.brit.xcms.community.Opportunity"))
                  return true;
              return true;
          }
      ...
      }
      



      Well, the problem that I am stuck to is that during render phase (I guess) the JSF can't access the database in order to execute the zone.getContentTypeFQDN() method from the method in the bean. This is the exception (if you think it helps, I can provide the whole stack):


      15:31:24,171 WARN  [JDBCExceptionReporter] SQL Error: 0, SQLState: null
      15:31:24,171 ERROR [JDBCExceptionReporter] Transaction is not active: tx=TransactionImple < ac, BasicAction: a000063:48c:480b34da:131 status: ActionStatus.ABORT_ONLY >; - nested throwable: (javax.resource.ResourceException: Transaction is not active: tx=TransactionImple < ac, BasicAction: a000063:48c:480b34da:131 status: ActionStatus.ABORT_ONLY >)
      15:31:24,171 ERROR [STDERR] Apr 20, 2008 3:31:24 PM com.sun.facelets.FaceletViewHandler handleRenderException
      SEVERE: Error Rendering View[/xcms/cms/page/edit.xhtml]
      javax.faces.FacesException: javax.el.ELException: /xcms/cms/page/edit.xhtml @19,88 value="#{pageList.getName(currentPage)}": javax.ejb.EJBTransactionRolledbackException: org.hibernate.exception.GenericJDBCException: Cannot open connection
      ...
      



      The thing that I spotted at first was that the exception is thrown trying to access another part of the page, not the one that introduced the problem: /xcms/cms/page/edit.xhtml @19,88 value="#{pageList.getName(currentPage)}" and not as expected: rendered="#{pageView.embedsOpportunity(zone)}"


      On the other hand, this code works very well displaying true in the page:


      <h:outputText value="#{pageView.embedsOpportunity(zone)}" />
      



      Since the bean is scoped to CONVERSATION, I even tried to start(or join) a new conversation, with no success. I am new to Seam and even JSF, so I don't seem to understand the cause of this problem, and neither to find a workaround for it. Could anyone please post a hint on this?


      Thank you in advance,
      Bogdan.

        • 1. Re: Can't access database in rendered attribute

          Hi!
          I see no relation between the error you posted, and the code you posted (your error doesn't even  mention the method embedsOpportunity so I do not get why do you think it has anything to do with it...


          I may be helpful if you poste the whole stack...


          Regards,

          • 2. Re: Can't access database in rendered attribute
            bogdanminciu.bogdan.minciu.yahoo.com

            Thank you Francisco for your fast reply,


            I am sure it has something to do with pageView.embedsOpportunity(zone) call because if I delete that h:outputText or even if I place the method call on the value attribute everything works fine:


            <h:outputText rendered="#{pageView.embedsOpportunity(zone)}" value="This zone embeds an opportunity" /> --- NOT working: causing exception
            <h:outputText value="#{pageView.embedsOpportunity(zone)}" />                                            --- working: displaying 'true'
            



            I presume that during rendering phase, jsf or seam first executes the methods inside rendered attributes of each tag: <h:outputText rendered="#{pageView.embedsOpportunity(zone)}" value="This zone embeds an opportunity"/>. If these methods calls the database, jsf or seam somehow closes the database session. When it comes to displaying the page, the first database call from my xhtml page is the method from the exception stack: pageList.getName(currentPage)


            I don't know how to prevent this.


            Please excuse me if I am very wrong presuming this, but I am kind of new to this technology and I try to understand it. Thank you.