3 Replies Latest reply on Oct 28, 2005 6:09 AM by Gavin King

    Contexts question

    drapierwimATgmailDOTcom Newbie

      I'm having some problems with the different contexts that are not clear to me.

      First my EntityBean is scoped with 'session' an SFSB scoped also 'session' this SFSB has a method that returns a collection of my entitybeans.

      When I write my test I can't find my object in the session context, but instead it's found in the conversation context. This I do not understand.

      Below is the code in case...

      public class JournalAccount extends DetailAccount {
       private Collection<Transaction> transactions;
       public JournalAccount() { }
       * @return Returns the posts.
       public Collection<Transaction> getTransactions() {
       return transactions;
       * @param posts The posts to set.
       public void setTransactions(Collection<Transaction> posts) {
       this.transactions = posts;

      public class AccountingServiceBean implements AccountingService {
       private static final Logger logger = Logger.getLogger(AccountingServiceBean.class);
       private EntityManager em;
       private List<JournalAccount> journals;
       private int journalIndex;
       private JournalAccount journal;
       public String getJournals() {
       journal = null;
       journals = em.createQuery("from JournalAccount")
       logger.info(journals.size() + " Journals found");
       return "journals";
       public String selectJournal() {
       if(journals == null) return "main";
       return "selected";
       @Destroy @Remove
       public void destroy() {
       private void setJournal() {
       journal = journals.get(journalIndex);
       logger.info("Selected journal has tableindex " + journalIndex +
       " -> " + journal.getNumber() +
       "," + journal.getDescription());

      String id = new Script() {
       AccountingService accountingService;
       protected void applyRequestValues() throws Exception {
       Contexts.getSessionContext().set("loggedIn", true);
       Contexts.getSessionContext().set("user", new User("Gavin King", "foobar", "gavin"));
       protected void invokeApplication() throws Exception {
       accountingService = (AccountingService) Component.getInstance("accountingService", true);
       String outcome = accountingService.getJournals();
       assert "journals".equals(outcome);
       protected void renderResponse() throws Exception {
       DataModel journals = (DataModel) Contexts.getSessionContext().get("journals");
       assert journals.getRowCount() == 4;
       assert ((JournalAccount) journals.getRowData()).getNumber() == 700000;
       assert Manager.instance().isLongRunningConversation();