Can't access database in rendered attribute
bogdanminciu.bogdan.minciu.yahoo.com Apr 20, 2008 2:53 PMHello 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.