Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Messing with the checkbox (one)

 
Thomas Byrne
Greenhorn
Posts: 16
Mac OS X Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi fellows,

I'm wondering if someone could help me. I am currently trying to create a simple registration form, however, even if it's simple it does't works for me.
Lets see:

form.jsp:


validator:

I'm lost here, in the validator, because in my understanding:
1. If I select the checkbox (form.jsp) and press Apply, then first of all the request.getParameter("_theatre") will be read and session will be set up.
2. So, before the session will be set up, only status of the checkbox have to be tested.
3. Next, after Apply, data will be transferred to confirm.jsp page, where session attribute will be displayed.
4. No, If I press "Edit" button to start everything from the beginning (back to form.jsp), I have check not only status of the checkbox but also status of the session, right?

The logic I should use for that is out of my mind, so please, give me some suggestions how to do that.

confirm.jsp:

Cheers,
Big Bill
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1.Let's correct your test condition in EL
there is not a equals method in EL, so condition should like below


2'nd point

when you check the check box the value *active* sent to servlet and you are setting into session.
similar fashion, dont you required to remove when you dont get the checkbox value at the time of user uncheck?
(may be in else condition) because session is represents a user hence shared between web components till in his scope.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch Big Bill

and avoid giving capital letter as first letter to variable name. this habit may leads you in trouble,
since this variable might be collide with some other class name in your code.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65225
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The session is maintained for you by the container. You don't have to do anything overt to create or maintain it.
 
Thomas Byrne
Greenhorn
Posts: 16
Mac OS X Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi fellows,

Thank you for your suggestion but so far no luck. Still something is wrong because as far as I stay on the same page (form.jsp) I can see that session attribute for theatre changes according to the checkbox. But, as soon as I left this page and move to the next page confirm.jsp and on this page (still can see that everything with checkbox is OK) press button "Edit" to come back to form.jsp page to start all over again, the checkbox on the form.jsp is unchecked again. Shouldn't be checked if the last time was selected?
What I did:

form.jsp:
validator:

Cheers,
Thomas
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65225
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A couple of things:

What's up with this scriptlet in the JSP?

<% String stheatre = (String) session.getAttribute("stheatre"); %>

Not only is it a poor practice to still be using scriptlets, it's an even poorer practice to mix them in with the EL. And on top of all that, it's completely useless. Why is it there?

Your page-relative action:

<form action="validator"

is a bug waiting to happen. Use server-relative URLs that start with the context path.

Debugging: Rather than just seeing if the checkbox is checked, have you verified what the exact value of stheatre is on the second run?
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear already pointed out why you did not get the session value in your EL. *EL evaluates(read only) variables from scope.*

also you should change this to

so that control flow will not come.
 
Thomas Byrne
Greenhorn
Posts: 16
Mac OS X Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi fellows,
Thanks for you help.
Bear Bibeault wrote:A couple of things:
<% String stheatre = (String) session.getAttribute("stheatre"); %>
Why is it there?

For this?
Your page-relative action:
<form action="validator"
is a bug waiting to happen. Use server-relative URLs that start with the context path.

I'm just beginner and so far this is only way I know so forgive me my ignorance.

Debugging: Rather than just seeing if the checkbox is checked, have you verified what the exact value of stheatre is on the second run?

By observing I mean printing session attributes on screen by:Cheers,
Thomas
 
Thomas Byrne
Greenhorn
Posts: 16
Mac OS X Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi fellows,
Looks like this made my day. After that everything works like expected (expected by me only).
Seetharaman Venkatasamy wrote:so that control flow will not come.

I know guys that my coding style is far away to be even only good enough but I'm just at the beginning of my path so I'm open for any suggestions.
Cheers,
Thomas
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65225
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thomas Byrne wrote:
For this?

Nope. Not needed. It's completely superflous. The El deals with scoped variables, not scripting variables (which are defunct as of 2002).

I'm just beginner and so far this is only way I know so forgive me my ignorance.

Understood. That's why advice is being offered.

So you are saying that ${(stheatre eq "Oh yes!")} evaluates to true? Have you verified this?

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65225
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And I just noticed this on your submit button: onclick="location.href='form.jsp'"



What on earth is that doing there? The only purpose for a submit button is to submit the form. What are you trying to accomplish with the click handler?
 
Thomas Byrne
Greenhorn
Posts: 16
Mac OS X Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:And I just noticed this on your submit button: onclick="location.href='form.jsp'"What on earth is that doing there? The only purpose for a submit button is to submit the form. What are you trying to accomplish with the click handler?


I don't like it too, so for sure I will try to eliminate that.

Cheers,
Thomas
 
Thomas Byrne
Greenhorn
Posts: 16
Mac OS X Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi fellows,

Thank you for your help.
Bear Bibeault wrote:Nope. Not needed. It's completely superflous. The El deals with scoped variables, not scripting variables (which are defunct as of 2002).

You see, this is what happen if you read book from 2001 (Callaway, DR 2001, Inside servlets: Server-side programming for the Java platform, 2nd edn, Addison Wesley, Boston, MA.) That wasn't my choice, the Uni recommended this book for the course.

How I can do that in proper way?
So you are saying that ${(stheatre eq "Oh yes!")} evaluates to true? Have you verified this?

Now I'm a bit confused because it work so I supposed it is OK, but obviously it's not?

Cheers,
Thomas
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65225
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If a scoped variable named fred exists, then you just refer to it as fred in the EL expression. No nonsense scriptlets are necessary.

A book from 2001 is worse than useless. It'll fill your head with all sorts of trash that's no longer true.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65225
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thomas Byrne wrote:Now I'm a bit confused because it work so I supposed it is OK, but obviously it's not?

I don't know what you mean by this.
 
Thomas Byrne
Greenhorn
Posts: 16
Mac OS X Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:A book from 2001 is worse than useless. It'll fill your head with all sorts of trash that's no longer true.

Thats true. I bought today a quite modern books about the subject, Murach's Java Servlets and JSP, 2nd Ed., by Mike Murach & Associates (2008) and
Guide to Web Development with Java: Understanding Website Creation, 2nd by Tim Downey (2012). Now, I can see see difference.
I'm gonna rewrite everything from scratch.

Thank you for your time and support.

Cheers,
Thomas
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65225
95
IntelliJ IDE Java jQuery Mac Mac OS X
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic