Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8070771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:30:21+00:00 2026-06-05T13:30:21+00:00

I’m using JBoss6.1.Final, JSF 2.0 (Mojarra), Weld CDI, MyFaces CODI 1.0.5 (for view-access-scoped) I’m

  • 0

I’m using JBoss6.1.Final, JSF 2.0 (Mojarra), Weld CDI, MyFaces CODI 1.0.5 (for view-access-scoped)

I’m using something like the Gateway Pattern from Real World Java EE Patterns Rethinking Best Practices (unfortunately I don’t have it with me, so I may have screwed something up here). Basically, the application allows a user to go into “edit mode” and edit a List of people (create, edit, remove) maintained in a @ViewAccessScoped backing bean with an extended persistence context and then click a “save” command link that flushes all their changes to the database. At first I was having a problem with ViewExpiredExceptions (if the browser was idle past the session-timeout period and then further requests are performed), but I added some jQuery to make a get request to a servlet that keeps the session alive (called 10 seconds before session-timeout). This seems to be working but now I have another problem, the backing bean is also a SFSB and after some idle time, it is being removed resulting in the following error message being logged (and all ajax rendered data disappears) when I attempt to perform more edits …

13:06:22,063 SEVERE [javax.enterprise.resource.webcontainer.jsf.context] javax.el.ELException: /index.xhtml @27,81 rendered=”#{!conversationBean.editMode}”: javax.ejb.NoSuchEJBException: Could not find stateful bean: 43h1h2f-9c7qkb-h34t0f34-1-h34teo9p-de

Any ideas on how I could prevent SFSB removal or at least handle it more gracefully?

Here’s my backing bean:

package com.ray.named;

import java.io.Serializable;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.ejb.EJBTransactionRolledbackException;
import javax.ejb.Stateful;
import javax.ejb.TransactionAttribute;
import javax.inject.Named;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceContextType;

import org.apache.myfaces.extensions.cdi.core.api.scope.conversation.ViewAccessScoped;

import com.ray.model.Person;

@Named
@Stateful
@ViewAccessScoped
@TransactionAttribute(javax.ejb.TransactionAttributeType.NEVER)
public class ConversationBean implements Serializable {
  private static final long serialVersionUID = 1L;
  //properties
  private List<Person> people;
  private String name;
  private Boolean editMode;

  @PersistenceContext(type=PersistenceContextType.EXTENDED)
  private EntityManager em;

  @PostConstruct
  public void init() {
    people = em.createNamedQuery("Person.findAll", Person.class).getResultList();
    setEditMode(false);
  }

  //event listeners
  public void beginEdits() {
    setEditMode(true);
  }

  public void addPerson() {
    Person p = new Person(name);
    em.persist(p);
    people.add(p);
    name = null;
  }

  public void removePerson(Person p) {
    people.remove(people.indexOf(p));
    em.remove(p);
  }

  //this method flushes the persistence context to the database
  @TransactionAttribute(javax.ejb.TransactionAttributeType.REQUIRES_NEW)
  public void saveEdits() {
    setEditMode(false);
  }

  //getters/setters
  public List<Person> getPeople() {
    return people;
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public Boolean getEditMode() {
    return editMode;
  }

  public void setEditMode(Boolean editMode) {
    this.editMode = editMode;
  }
}

Here’s the Person entity bean:

package com.ray.model;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Version;

@Entity
@NamedQueries({
  @NamedQuery(name="Person.findAll",
              query="SELECT p FROM Person p")
})
public class Person {
  @Id @GeneratedValue(strategy=GenerationType.IDENTITY) 
  private Integer id;
  private String name;
  @Version
  private int version;

  public Person() { }

  public Person(String name) {
    setName(name);
  }

  public boolean equals(Object o) {
    if (!(o instanceof Person)) {
      return false;
    }
    return id == ((Person)o).id;
  }

  //getters/setters
  public String getName() {
    return name;
  }
  public void setName(String name) {
    this.name = name;
  }

  public Integer getId() {
    return id;
  }

  public int getVersion() {
    return version;
  }

  public void setVersion(int version) {
    this.version = version;
  }
}

Here’s the view:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
  <script src="http://code.jquery.com/jquery-latest.min.js"></script>
  <script>
  $(document).ready(function() {
    setInterval(function() {
      $.get("#{request.contextPath}/poll");
    }, #{(session.maxInactiveInterval - 10) * 1000});
  });
  </script>
  <title>Conversation Test</title>
</h:head>
<h:body>
  <h:form>
    <h:commandLink value="Begin Edits" rendered="#{!conversationBean.editMode}">
      <f:ajax render="@form" listener="#{conversationBean.beginEdits}"/>
    </h:commandLink>
    <h:commandLink value="Save" rendered="#{conversationBean.editMode}">
      <f:ajax render="@form" listener="#{conversationBean.saveEdits}"/>
    </h:commandLink>
    <h:dataTable id="peopleTable" value="#{conversationBean.people}" var="person">
      <h:column>
        <f:facet name="header">Name</f:facet>
        <h:panelGroup>
          <h:inputText value="#{person.name}" disabled="#{!conversationBean.editMode}">
            <f:ajax/>
          </h:inputText>
          <h:commandLink value="X" disabled="#{!conversationBean.editMode}">
            <f:ajax render="@form" listener="#{conversationBean.removePerson(person)}"/>
          </h:commandLink>
        </h:panelGroup>
      </h:column>
    </h:dataTable>
    <h:panelGrid columns="2">
      <h:outputLabel for="name">Name:</h:outputLabel>
      <h:inputText id="name" value="#{conversationBean.name}" disabled="#{!conversationBean.editMode}"/>
    </h:panelGrid>
    <h:commandButton value="Add" disabled="#{!conversationBean.editMode}">
      <f:ajax execute="@form" render="@form" listener="#{conversationBean.addPerson}"/>
    </h:commandButton>
  </h:form>
</h:body>
</html>

Here’s a servlet used to keep the session alive (called by jQuery ajax get request 10 seconds before session expires):

package com.ray.web;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class PollServlet extends HttpServlet {
  private static final long serialVersionUID = 1L;

  public void init() throws ServletException {
  }

  public String getServletInfo() {
    return null;
  }

  public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    request.getSession(); //Keep session alive
  }

  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
  }

  public void destroy() {
  }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T13:30:23+00:00Added an answer on June 5, 2026 at 1:30 pm

    Any ideas on how I could prevent SFSB removal or at least handle it
    more gracefully?

    To investigate further I would recommend to take a look at the EJB lifecycle hooks for passivation and add some debug output there.

    Should that be the source of the problem you will be able to configure / deactivate passivation – but scalability might come up as an issue.

    Honestly, this scenario seems quite uncommon to me. In general I would expect requests / conversations / sessions to be working more or less in the default boundaries – should you find yourself writing code that circumvents this can it be that you are better off with a RESTful / stateless approach…?

    Please update the question with further information if available.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the
I've got a string that has curly quotes in it. I'd like to replace
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.