3 Replies Latest reply on Feb 5, 2007 11:36 AM by Stefan Frank

    Remoting-Calls to SSB are not stateful

    Stefan Frank Newbie

      I have some troubles with my very naive approach to use a Stateful Session Bean together with Seam.Remoting:

      The Scenario:
      User loads Page with a Multiple-Choice-Test. All questions are fetched from the server, each question is setup via javascript on the client. Each answer is sent to the server. At the end of the test, we redirect to a page to display the test-results.

      We try to implement this using:
      - Seam.Remoting to make up the Connection
      - Javascript to setup the questions
      - A stateful session Bean to hold the test and the results.
      - A conversation to demarcate start and end of the test.

      Alas, this does not work out-of-the-box: The problem is, that the remoting does not reconnect to the SSB, but instead starts new SSB's. Here is a rough sketch of the code:

      the SSB:

      @Name ("examManager")
      public class ExamManagerBean implements ExamManager {
       public Test startTest(int testId) {
       public void sendAnswer(int questionId, int answerId){
       public String getResults(){

      with all three Methods exposed in the ExamManager via @WebRemote.

      The javascript:

      var remoteManager = Seam.Component.getInstance("examManager");
      remoteManager.startTest(id, testLoaded)
      function testLoaded(test){
      function evaluateAnswer(){
       remoteManager.sendAnswer(test.questions[questionIdx].id, answerId, answerCallback);

      The Test is fetched correctly and the first two calls to remoteManager.sendAnswer go to the same SSB with which the Test was started, the third call goes to another SSB and fails there, becaus the startTest() was never called and therefore the test not initialized.

      I checked via Seam.Remoting.getContext().getConversationId() that every Remoting-Call happens within the same context, so I'm puzzled and can't figure out, why the SSB-references are not stable in between the remoting calls... Is there something fundamentally wrong with this approach or am I simply missing a switch here somehwhere??!

      Thx for any hint&help