4

currently i am trying to remove a ConversationScoped Stateful Session Bean (SFSB). The ConversationScope is managed by the CDI Container and the lifecycle of the SFSB is managed by the EJB Container. Is this correct?

In my Controller i'm trying to end the conversation by calling a method of the SFSB and to call the @Remove annotated method to destroy the SFSB.

The conversation can be end without any problems but i am not able to destroy the SFSB.

A Code example from Weld Reference Guide (WELD Conversation Scope):

@ConversationScoped @Stateful
public class OrderBuilder {

   private Order order;
   private @Inject Conversation conversation;
   private @PersistenceContext(type = EXTENDED) EntityManager em;

   @Produces public Order getOrder() {
      return order;
   }


   public Order createOrder() {
      order = new Order();
      conversation.begin();
      return order;
   }

   public void addLineItem(Product product, int quantity) {
      order.add(new LineItem(product, quantity));
   }


   public void saveOrder(Order order) {
      em.persist(order);
      conversation.end();
   }

   @Remove
   public void destroy() {}

}

The controller:

@Named
@SessionScoped
public class TestController implements Serializable{

  @Inject
  private OrderBuilder orderBuilder;

  ...

  public String checkout(Order order){
    orderBuilder.saveOrder(order);
    orderBuilder.destroy();
    return "success";
  }
}

After i have called testController.checkout(order), i'am getting this exception:

javax.servlet.ServletException: java.lang.reflect.InvocationTargetException javax.faces.webapp.FacesServlet.service(FacesServlet.java:321) org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:67) root cause

javax.faces.el.EvaluationException:

java.lang.reflect.InvocationTargetException javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:98) com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:98) javax.faces.component.UICommand.broadcast(UICommand.java:311) javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:781) javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1246) com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:77) com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97) com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:114) javax.faces.webapp.FacesServlet.service(FacesServlet.java:308) org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:67)

Any ideas?

THX

ich-bin-drin
  • 543
  • 3
  • 12
  • 23

2 Answers2

3

You should end the CDI conversation and CDI will call the @Remove method.

Have a look in Weld documentation : " Stateful session beans may define a remove method, annotated @Remove, that is used by the application to indicate that an instance should be destroyed. However, for a contextual instance of the bean—an instance under the control of CDI—this method may only be called by the application if the bean has scope @Dependent. For beans with other scopes, the application must let the container destroy the bean. "

-1

JSF 1.2 or 2.0 does not support expression like methods with parameter obj.method(parameter) JSF supoorts only method without parameter like obj.method() Seam 2,3 build in supports this kind of expreesions but if you are using only weld (CDI support of seam, core of seam) without other seam jars, you can not have this ability. But it is possible to give this kind of ability to JSF. Adding this to jar project you can use methods with parameters. If you are using maven u can use code below or. Download jars manually in lib folder.

     <dependency>
        <groupId>javax.el</groupId>
        <artifactId>el-api</artifactId>
        <version>2.2</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.web</groupId>
        <artifactId>el-impl</artifactId>
        <version>2.2</version>
    </dependency>

Additionally, I tested it with tomcat worked fine, but in jetty some conflicts happen with the other jars. May be it is about my project.

Add this to web xml

<context-param>
        <param-name>com.sun.faces.expressionFactory</param-name>
        <param-value>com.sun.el.ExpressionFactoryImpl</param-value>
</context-param>