Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

jstl, multiple forms per page and scopes  RSS feed

 
Jeff Pollet
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,
I'm uncertain which forum to post this in, actually, because it deals with both the HTML <form> tag and the jstl <c: out> tag, but I'll put it here in the hopes that it will be moved appropriately without too much trouble for our esteemed moderators.

I'm new to programming, as will be readily apparent, I'm sure. I've been slowly learning some Java stuff using HeadFirst Java, but mostly the actual playing around with code-ish stuff I've been doing has been doing simple little .jsp pages using only JSTL.

I have a page which has one form to start with, and then, based on that selection, a second form. The input from the first form is passed to the second form as a parameter. After the second form is submitted, some output is meant to happen, based on info given in both the first and second forms. However, when the second form is submitted, for some reason the input parameters from the first form are reset to null. I've tried using <c:set> to turn the input parameters into applicationSession variables just after they're created, but this still doesn't keep the value of the variable from going to null when the second form is submitted. Is there something inherent in having two forms in one .jsp page that keeps a variable from being sustained throughout?

I can supply the code, but it's ugly beginner code, and I wasn't sure if it would really help.

Any assistance would be appreciated, though I know it's almost lunchtime on a Friday, so I'm asking a lot.

Jeff
[ May 19, 2006: Message edited by: Jeff Pollet ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand the need for, or interaction regarding, the two forms. Why two forms?

And yes, when you submit the second form, none of the elements of the first form will be submitted. One form per request only.

(I'm off to the airport in a few mins so may not be able to reponse again 'til later the eve).
[ May 19, 2006: Message edited by: Bear Bibeault ]
 
Jeff Pollet
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear--

Thanks for the quick response.

One one level, there *is* no need for the two forms to be on one page. I like the way it looks, and I like to have the first form to remain on the page so the user *can* use that form again if they want...but this is just a learning exercise, so it doesn't have to be that way.

I understand that the first form isn't submitted when the second form is--but if I take the input from the first form and create an application-scoped variable with it, how come the page can't use *that* after the second form is set? That is, if I take the result of the input of the first form, which can be accessed with jstl as a parameter, and use <c:set> to create an application-wide scoped variable, shouldn't the page have access to that variable no matter how many subsequent forms are used? Other pages would have access to it in that way (which sort of relates to your question: If I put these forms on different pages, I suspect I'd have no problem.) Hopefully this question makes more sense.

Thanks again for your help.
 
Jeff Pollet
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My guess is that I'm now the only person who will ever read this, but it turns out that (1)I did have to use <c:set> because of the way <form> works with variables. I had tried using <c:set>, but I did it wrong, a simple typo killed me, as per usual.

Thanks for your help regardless!

I do think it's interesting (and I don't yet understand why) that submitting a form sets various param's to null. But I may be misundrstanding that as well.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jeff Pollet:
I do think it's interesting (and I don't yet understand why) that submitting a form sets various param's to null. But I may be misundrstanding that as well.


I believe so. Whatever the values of the form elements within the form are set to is what will be submitted.
 
Jeff Pollet
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The interesting thing though is that even elements that aren't part of the form are set to null; so it really works this way: Only elements submitted within the form are passed. Anyway, there's an easy way 'round it, and there are probably myriad good reasons it works that way that I'm ignorant of...
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jeff Pollet:
The interesting thing though is that even elements that aren't part of the form are set to null


There's your sticking point. Elements that aren't part of the form don't get set to null, they don't even exist!

So when ask for the value of something that doesn't exist, you get null as the result. Did you expect something different?
 
Jeff Pollet
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Very good point indeed, and it makes a lot of sense now that you put it that way. I suppose I'm still having some difficulty understanding the relationship between how the basic html works and how the jstl stuff works. That is, how <form> elements work within the framework of jstl scopes.

Or, likely, I just need more practice to understand it better. And need to look at the API more.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jeff Pollet:
That is, how <form> elements work within the framework of jstl scopes.


Simple. They don't.

Scoped variables and request parameters are distinct and separate concepts.
 
Jeff Pollet
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I really appreciate the schoolin'--I know this is simple stuff. But don't request parameters have scopes, too?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jeff Pollet:
But don't request parameters have scopes, too?


Nope.
 
Jeff Pollet
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's amazing how long it took me to figure that out. Thanks again for your help.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!