• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

CheckBox Getting Unchecked

 
Praveen Banthia
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys this is silly question but I need help
In my project I am developing a game where end user rolls five dice's and can choose to not spin any one of five dices he want.
Problem is my program submits to server after every roll and and I created checkbox which when selected does not roll the dice
Works GREAT but one problem every time I submit form and it is redirected to same page the checkbox gets unclicked .

How can I make sure that the check box stays checked even after the rolling the dice again redirects to same page
 
Mansukhdeep Thind
Ranch Hand
Posts: 1158
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whenever the user selects a checkbox, you store that as an attribute or a flag in the session object. Then, when the response is generated and sent back to the client, retrieve that same value from the session for that particular checkbox ID and mark it as checked. You would have to do some scripting.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As noted in the other thread, the OP does not want to use JavaScript for this ( ) so everything has to be done on the server with JSP. Very 1998, but it can be done.

The session is not necessary and overkill. Whether the checkbox has been checked or not is submitted in the request as part of the form. No session necessary.

When formatting the pages, just use JSP's JSTL and EL to add the checked attribute on the checkbox when necessary.

Having to recreate page state over and over and over again is one of the many reasons that this sort of application is best handled without full-page refreshes.
 
Mansukhdeep Thind
Ranch Hand
Posts: 1158
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But I do not understand why is Praveen shying way from JavaScript usage. How else do you gauge client actions?
 
Mansukhdeep Thind
Ranch Hand
Posts: 1158
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote: When formatting the pages, just use JSP's JSTL and EL to add the checked attribute on the checkbox when necessary.


Which library would one use Bear? Core?

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mansukhdeep Thind wrote:Which library would one use Bear? Core?

Perhaps; if the JSTL is used at all. It depends how he goes about it; but it can easily be done with the just the EL:



Mansukhdeep Thind wrote:But I do not understand why is Praveen shying way from JavaScript usage.

See his other post. He feels that he must avoid JavaScript in order to avoid "security issues". If the use of JavaScript automatically introduced security issues, 99% of the useful sites on the web, including this one, would likely not exist. Like any other tool, it's all in how you use it.
 
Mansukhdeep Thind
Ranch Hand
Posts: 1158
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote: See his other post. He feels that he must avoid JavaScript in order to avoid "security issues". If the use of JavaScript automatically introduced security issues, 99% of the useful sites on the web, including this one, would likely not exist. Like any other tool, it's all in how you use it.


I hope he changes this viewpoint soon. Life will be much easier.
 
Praveen Banthia
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This whole project of mine is to change the view point.
I am not against javascript and I am a newbie in this and nothing is easeir than javascript but then that is also a problem nothing is easier to break also.
I am trying to get the view of a malacious user who wants to screw with my system, then he disables my javascript and violaa my site is dead . I can use javascript but I will have to validate the input from servler side.

However in case of the checkbox I think I can use javascript to remember the choice of end user as if malacious person disables my javascript the best he will get is all the dices will roll which is not a harm

So for this case can someone give me an example of javascript which will keep my checkbox enabled even after page submit pleaseee as it will be redirected to same page.
 
Mansukhdeep Thind
Ranch Hand
Posts: 1158
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Praveen Banthia wrote: So for this case can someone give me an example of javascript which will keep my checkbox enabled even after page submit pleaseee as it will be redirected to same page.


You have to introduce some JavaScript function () that :

a) gets called onSelect(there could be a more appropriate event handler, you will have to check that) of a check box,

b) flags it as checked using some attribute,

c) stores the attribute in session and

d) retrieve that attribute when the final response is being generated and sent back to the client.

This way you will be able to persist the checked value of a check box across multiple requests / responses

Are you with me on this Praveen?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Praveen Banthia wrote:I can use javascript but I will have to validate the input from servler side.

You have to do that anyways. If someone turns JavaScript off, they can't use the site. Simple as that. It is in no way "malicious".

If the user can do something on the client, regardless of whether your pages use JavaScript or not, that compromises the server-side state, then the server-side code is broken!

So for this case can someone give me an example of javascript which will keep my checkbox enabled even after page submit

No. The whole point of using JavaScript is to avoid the page submission in the first place so that state is never lost.
 
Praveen Banthia
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bieaber
I just wanted to add this feature so that the end user does not need to click the checkbox after every roll. It is something I want to do for convienient of end user and so some example would be appreciated to keep checkboxes checed even after submission. If this is not possible then I can leave it off
 
Mansukhdeep Thind
Ranch Hand
Posts: 1158
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Praveen Banthia wrote:Hi Bieaber
I just wanted to add this feature so that the end user does not need to click the checkbox after every roll. It is something I want to do for convienient of end user and so some example would be appreciated to keep checkboxes checed even after submission. If this is not possible then I can leave it off


What do you mean by
does not need to click the checkbox after every roll.
keep it checked permanently for that user? Isn't that what you have been trying all along?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You already have two solutions: submit the page and re-create the state using the JSP EL, or don't submit the page at all and not have to worry about it having to be re-created in the first place. Which approach you choose fundamentally affects how you write your app.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic