Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Reentrant page question.  RSS feed

 
Darrin Smith
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there anything "special" you have to do to get a page to refresh itself with new data?

I am trying to build a test site where a question will be asked on a page then submitted, then the next question will show up on that same page then submitted, until all of the questions are answered.

Since each question can have a variable number of answers, I dynamicaly build the answer list as a group of radio buttons. The first time I come to the test page, everything works just fine. The question along with the radio buttons that correspond to the possible answers show up, but when the user hits submit, instead of the next question showing up, the same one continues to display every time.

I verify that in the test page's constructor the next question is being loaded and the old components are cleared out before I rebuild them.

The entire code in the test page's constructor looks something like this:




Note that I am using Java Studio Creator for this and have posted a similar question (http://swforum.sun.com/jive/thread.jspa?threadID=93475)on that forum since I first thought it might be a JSC thing, but now I'm thinking more like it is some sort of JSF rule I need to adhere to.

Note that I tried returning both null and a unbound string (unbound meaning not in the mapping) in the submit button handler...same thing happened each time, the page submits, the consructor gets called, and the new question gets loaded along with the new components, but the old question and answers still show up.
 
Darrin Smith
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmm...has anyone ever even tried doing this with JSF?
 
Gerardo Tasistro
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well I think the problem here is that you're doing that stuff in the page's constructor if I read you well. And that shouldn't be done. You should manage your questions in the managed bean. Remember a JSF file gets converted to servlet in the end and all thread issues with servlets apply.

Now in terms of your managed bean. I wouldn't put the load question code in the constructor either. Since it is only called once. When the bean is created for the session. Set that in the method you call when the button gets clicked.
 
Darrin Smith
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Gerardo Tasistro:
Well I think the problem here is that you're doing that stuff in the page's constructor if I read you well. And that shouldn't be done. You should manage your questions in the managed bean. Remember a JSF file gets converted to servlet in the end and all thread issues with servlets apply.


Actually, the code is in the managed bean.

Now in terms of your managed bean. I wouldn't put the load question code in the constructor either. Since it is only called once. When the bean is created for the session. Set that in the method you call when the button gets clicked.



I could move it from the constructor, but the constructor does get called each time (it is not in session scope)...that I have verified!
 
Gerardo Tasistro
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How does it know it is in question one and needs to move to question two and then in two to move to three if it keeps going bye bye since it isn't in session scope?
 
Darrin Smith
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Gerardo Tasistro:
How does it know it is in question one and needs to move to question two and then in two to move to three if it keeps going bye bye since it isn't in session scope?


The current question index is in session scope. It retrieves the correct question from a list of questions based on that index.
 
Gerardo Tasistro
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where are you incrementing that index and storing it back in session?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!