icefaces lazy initialization problem
nepveul May 14, 2008 1:54 PMI'm using seam and icefaces.
I'm having lazy initialization problems.
I have two facelet views and one stateful bean:
routine list:
<!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:ice="http://www.icesoft.com/icefaces/component"
template="layout/template.xhtml">
<ui:define name="body">
<h:messages globalOnly="true" styleClass="message"/>
<ice:dataTable var="routine"
value="#{routineList}">
<ice:column>
<f:facet name="header">Id</f:facet>
<ice:outputText value="#{routine.id}" />
</ice:column>
<ice:column>
<f:facet name="header">Description</f:facet>
<s:link id="routineLink" view="/routine.xhtml"
value="#{routine.description}"/>
</ice:column>
</ice:dataTable>
</ui:define>
</ui:composition>
view routine:
<!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:ice="http://www.icesoft.com/icefaces/component"
template="layout/template.xhtml">
<ui:define name="body">
<h:messages globalOnly="true" styleClass="message"/>
<ice:outputText value="#{routineManager.routine.id}" />
<ice:outputText value="#{routineManager.routine.description}" />
<h:form id="test">
<ice:panelGroup style="border: 1px solid black; position: relative; width: 1000px; height: 600px;">
<ice:panelGroup style="border: 1px solid black; position: absolute; top: 0px; left: 0px; width: 400px; height: 50px;">
<ice:outputText value="#{routineManager.routine.days}" />
</ice:panelGroup>
<ice:panelGroup style="border: 1px solid black; position: absolute; top: 50px; left: 0px; width: 200px; height: 50px;">
</ice:panelGroup>
<ice:panelGroup style="border: 1px solid black; position: absolute; top: 50px; left: 200px; width: 200px; height: 50px;">
</ice:panelGroup>
<ice:panelGroup style="border: 1px solid black; position: absolute; top: 100px; left: 0px; width: 400px; height: 450px;">
<ice:dataTable scrollable="true"
columnWidths="130px,300px"
scrollHeight="415px"
var="exercise" cellpadding="0"
value="#{exerciseQuery.resultList}">
<ice:column>
<f:facet name="header">Id</f:facet>
<ice:outputText value="#{exercise.id}" />
</ice:column>
<ice:column>
<f:facet name="header">Description</f:facet>
<ice:outputText value="#{exercise.description}" />
</ice:column>
</ice:dataTable>
</ice:panelGroup>
<ice:panelGroup style="border: 1px solid black; position: absolute; top: 550px; left: 0px; width: 400px; height: 50px;">
</ice:panelGroup>
<ice:panelGroup style="border: 1px solid black; position: absolute; top: 0px; left: 400px; width: 600px; height: 600px;">
<ice:panelTabSet selectedIndex="1" tabPlacement="top">
<ice:panelTab label="Tab 1">Hello 1
</ice:panelTab>
<ice:panelTab label="Tab 2">Hello 2
</ice:panelTab>
<ice:panelTab label="Tab 3">Hello 3
</ice:panelTab>
</ice:panelTabSet>
<!-- ice:panelTabSet var="day" value="#{routine.days}">
<ice:panelTab label="#{day.label}">
<ice:outputText value="#{day.label}"/>
</ice:panelTab>
</ice:panelTabSet-->
</ice:panelGroup>
</ice:panelGroup>
</h:form>
<div style="clear:both"/>
</ui:define>
</ui:composition>
stateful bean:
package com.blisslogik.fbo.beans;
import java.util.List;
import javax.ejb.Remove;
import javax.ejb.Stateful;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceContextType;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Destroy;
import org.jboss.seam.annotations.Factory;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Out;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.datamodel.DataModel;
import org.jboss.seam.annotations.datamodel.DataModelSelection;
import com.blisslogik.fbo.entity.Routine;
import com.blisslogik.fbo.entity.RoutineQuery;
@Stateful
@Scope(ScopeType.SESSION)
@Name("routineManager")
public class RoutineManagerBean implements RoutineManager {
@DataModel
private List<Routine> routineList;
@DataModelSelection
@Out(required=false)
private Routine routine;
@PersistenceContext(type=PersistenceContextType.EXTENDED)
private EntityManager em;
@In(create=true)
private RoutineQuery routineQuery;
public void delete() {
routineList.remove(routine);
routine = em.merge(routine);
em.remove(routine);
routine=null;
}
@Factory("routineList")
public void loadRoutines()
{
routineList = routineQuery.getResultList();
}
@Remove @Destroy
public void destroy() {}
public void select() {
System.out.println("SELECT!!!!");
}
public void merge() {
routine = em.merge(routine);
}
public void refresh() {
loadRoutines();
}
public Routine getRoutine() {
return routine;
}
}
When I tried to view a routine, I have thew following error: