• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to display questions in several pages?

 
Ranch Hand
Posts: 243
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I'm trying to do a sample survey application,which has got a few questions.I have the questions stored in the database.My current JSP displays all the questions in the same page,rather i would like to have a single question in a page and a next button to go to the next question.How do i do this?

Regards,
Srikkanth.M
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're going to need to be more specific about what's confusing you. I mean, it's easy to create as many pages as you want each with one question. What's the confusion?
 
Srikkanth Mohanasundaram
Ranch Hand
Posts: 243
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
How do i display a single question in a page?
If i click on next i should get the next question,so where should i redirect?

And where should i save the user's responses? (I think i should save it in session attributes)
Currently i have all the questions with options in the same page..but that does'nt look right( 30 questions in a same page)

Thanks,
Srikkanth
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Srikkanth Mohanasundaram:
Hi,
How do i display a single question in a page?

Don't put more than one on a page.

If i click on next i should get the next question,so where should i redirect?

To the page with the next question.

And where should i save the user's responses?

Wherever you want. The session? The database? it depends how you want to use the answers.
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are many ways to do "pagination". Do a search on google or this forum to get some good results
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by John Meyers:
There are many ways to do "pagination". Do a search on google or this forum to get some good results



That will yield hundreds of thousands of results all pertaining to pagination of database records. Which is not what I think that the OP is asking about.

My confusion is still: why is the OP confused as to how not to put more on the page than intended?
[ April 30, 2007: Message edited by: Bear Bibeault ]
 
Deepak Bala
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bear Bibeault:


That will yield hundreds of thousands of results all pertaining to pagination of database records. Which is not what I think that the OP is asking about.

My confusion is still: why is the OP confused as to how not to put more on the page than intended?

[ April 30, 2007: Message edited by: Bear Bibeault ]



Srikkanth are you looking to put more than one question on a page (say 5) or just one question on a page ? Either way it should be simple. If its just one question you want to put on the page can you be more specific about what it is that you want to know ? Reducing the view to just one question from 30 should be pretty simple to do. The "next" button can fetch the next question from the database based on session attributes or parameters. You can save the results however you like, like Bear suggested.
 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you can use the following steps:

1) Get all the questions from the database and save each question to a different instance of the same JavaBean object. As you do it, keep adding each JavaBean object to a vector object.
2) Save the vector object in the HttpSession object.
3) In each JSP page, access only one JavaBean object from the vector from the session object and retrive the data.
4) Go to next JSP page and repeat the step 3 and so on.

I hope it works.
 
Srikkanth Mohanasundaram
Ranch Hand
Posts: 243
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everybody,
I currently use the resultset from the database to create Simple Javabean question objects.And i populate a list with these question objects.
From my servlet i set this list as a request attribute and access the list of question objects in the JSP.

Suppose i have 30 question objects in my List.. do i need to have 30 JSP pages?
What should be the "target" of the next button? Can i send it to the same JSP, if so how should the list be accessed so that i don't repeat the questions?(Should i delete the question object from the list once i have displayed it,Is that the way to go about it?)

Thanks for your replies,

Srikkanth.M

Regards
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, now that you've added a little more substance to your question we can get to work!

Originally posted by Srikkanth Mohanasundaram:
Hi everybody,
Suppose i have 30 question objects in my List.. do i need to have 30 JSP pages?



Of course not. That's exactly what the dynamic nature of JSP is for. A single page should do.

What should be the "target" of the next button? Can i send it to the same JSP, if so how should the list be accessed so that i don't repeat the questions?



As was mentioned earlier, storing the list in the session will let you access the list in each request. You can also maintain a counter in the session that identifies the "current question". A next operation merely incrementes the count and accesses the next question. This would also allow you to imlement a back operation easily, if desired.

(Should i delete the question object from the list once i have displayed it,Is that the way to go about it?)



No, it's not ncessary and will just introduce the possibility of problems.
[ April 30, 2007: Message edited by: Bear Bibeault ]
 
Srikkanth Mohanasundaram
Ranch Hand
Posts: 243
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bear,

Thanks for your reply I'll try out that logic and get back to you.

Regards,
Srikkanth.M
 
Srikkanth Mohanasundaram
Ranch Hand
Posts: 243
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bear,

Now i have one question per page,but how do i save the user's responses?

I mean how to save the user's answers.
Do i have to do the processing in the JSP?
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Srikkanth Mohanasundaram:

Do i have to do the processing in the JSP?



No. In fact, it's considered a poor practice to perform processing in a JSP.

Rather, your JSP should submit to a servlet that does the processing (in this case, saving the answers in the DB or to file or whatever) and then to forward to the next JSP.

This article might be helpful in understanding the flow patterns.
[ May 01, 2007: Message edited by: Bear Bibeault ]
 
Srikkanth Mohanasundaram
Ranch Hand
Posts: 243
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bear,
That article was helpful.

Regards,
Srikkanth.M
 
Srikkanth Mohanasundaram
Ranch Hand
Posts: 243
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bear,
I often end up using scriptlets in my page.I have two attributes set in my Session(one is the counter and other is the actual list)
What i wanted is:

The EL expression didnt work and i had to use something like this

I know this isn't the right way to go about it...

Regards,
Srikkanth.M
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
list.size will not work in the EL since size is not a proper bean-patterned property of the collection classes. Assuming that you are using JSP 2.0 and JSTL 1.1, you should use the fn:length() function to obtain the size of a collection.
 
Srikkanth Mohanasundaram
Ranch Hand
Posts: 243
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wow that's cool.
Then it becomes simple to get the size and compare using EL.

Bear thanks for your valuable suggestion.

Regards,
Srikkanth.M
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Srikkanth Mohanasundaram:
Then it becomes simple to get the size and compare using EL.

Exactly. The test becomes:



(don't forget proper quoting).
 
Srikkanth Mohanasundaram
Ranch Hand
Posts: 243
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bear,

How do i eliminate the scriplet from this piece of code?


li is a List(session attribute) that contains Question Objects and counter is a session attribute.
Regards,
Srikkanth.M
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"li"? Not very readable. Let's call it questions.



Now is the time for you to make sure that you have copies of the JSP Spec (as an EL reference) and a copy of the JSTL Spec.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The only thing that puzzles me is the cast to Person. What's up with that?
 
Srikkanth Mohanasundaram
Ranch Hand
Posts: 243
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bear,
Sorry that was a typo
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Be careful with that. Typos like that can lead to a lot of wasted time. Please read this.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic