getting the value of a s:checkbox

2007-08-08 Thread Session A Mwamufiya
Hi,

I have the following checkbox in my jsp:
s:checkbox key=overwriteCheckbox name=overwriteFlag labelposition=left 
onclick=if (this.checked) {javascript:return 
confirm('%{getText('elementOverwriteConfirmation')}')} /

In my action, I have defined overwriteFlag as a String variable, and have a 
getter and a setter for it.  Nevertheless, when I submit the form, I always get 
null when I try to check the value.

Any ideas what I could be doing wrong?

Thanks,
Session


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: getting the value of a s:checkbox

2007-08-08 Thread Dale Newfield

Session A Mwamufiya wrote:

s:checkbox key=overwriteCheckbox name=overwriteFlag


Isn't key a shorthand for name, value, and label?  If so, I'm not sure 
which of name and key will win.  Look in the generated html--is the name 
attribute of the corresponding input tag overwriteCheckbox or overwriteFlag?


-Dale

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: getting the value of a s:checkbox

2007-08-08 Thread Session A Mwamufiya
The name appears as overwriteFlag, so the name took precedence.  I used the key 
to get the label text from a properties file.

Interestingly, the html source code shows the value as true, even if it is not 
checked when displayed.

The action variable should be a String or a boolean?  I tried both, and neither 
worked.

Thanks,
Session


 Session A Mwamufiya wrote:
 s:checkbox key=overwriteCheckbox name=overwriteFlag
 
 Isn't key a shorthand for name, value, and label?  If so, I'm not sure 
 which of name and key will win.  Look in the generated html--is the name 
 attribute of the corresponding input tag overwriteCheckbox or
 overwriteFlag?
 
 -Dale
 
 - To
 unsubscribe, e-mail: [EMAIL PROTECTED] For additional
 commands, e-mail: [EMAIL PROTECTED]
 
 
 


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: getting the value of a s:checkbox

2007-08-08 Thread Dave Newton
--- Session A Mwamufiya wrote:
 Interestingly, the html source code shows the value
 as true, even if it is not checked when displayed.

Not relevant; the only time the value matters is on
submission--The value has to be set so the browser
knows what to send on submission.

d.



  

Park yourself in front of a world of choices in alternative vehicles. Visit the 
Yahoo! Auto Green Center.
http://autos.yahoo.com/green_center/ 

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: getting the value of a s:checkbox

2007-08-08 Thread Dale Newfield

Session A Mwamufiya wrote:

I used the key to get the label text from a properties file.


If that's the only reason you used it, then the label attribute is more 
appropriate.



Interestingly, the html source code shows the value as true, even if it is not 
checked when displayed.


That means the value passed for the checkbox *when checked* will be 
true.  When checkboxes are not checked the parameter is simply missing 
in the request.  There's an interceptor called checkbox that does some 
hidden magic to make it appear that the checkbox sends true or false 
depending upon whether or not it is checked.  (Make sure this is before 
parameters in the stack.)



The action variable should be a String or a boolean?  I tried both, and neither 
worked.


The problem is that you don't break down the problems before posting. 
There are lots of places you can get clues as to what's happening, but 
you have to understand that different parts of the process happen on 
different machines.


Request cycle:

(Let's start with a form already being viewed in a browser)
This page only contains (x)html components, and maybe javascript.
The browser handles getting all the right data into the right parameters 
and submits the values.


You can look at the generated html (view source) to see if it contains 
what you expect.  If you're using complicated tools (like ajax 
components), those might be added to the page after it's initially 
generated, and the firebug extension might help you see what's really 
there.  The page info option in firefox can help you see what the 
form's current values are.


OK--the browser submits the form.  Often this is sent using post (look 
in the form tag) which hides the values, but if you want to see what 
was submitted right in the url, you can (temporarily) change this to get.


OK--now this request goes to your server.  Hopefully eventually to 
struts.  Struts then steps through the interceptors and eventually calls 
your action.  The action does it's thing and selects a result.


The result often is a .jsp page, which may have s:FOO tags in it. 
These get executed on the server and output the html that is sent to the 
browser.


The browser gets this html, executes any javascript, and displays the 
results.  The cycle is complete.  At any point in the cycle you should 
be able to verify that things are doing what you expect, but you need to 
know where to expect them.


For example, you asked last week about having the action pop up alert 
boxes for validation.  You probably didn't get any responses because the 
question doesn't make sense.  By the time the action is running it is 
already too late for the browser to do what you wanted.  The popups you 
wanted must be generated by the browser before submitting the request to 
the server, and so must be handled by javascript.  There are some tools 
in struts to generate client side validation which means javascript to 
verify stuff before submitting, but there's no magic--that validation 
logic must be in the page being displayed, and therefore debugable 
separately from the rest.


-Dale

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: getting the value of a s:checkbox

2007-08-08 Thread Dale Newfield

Dale Newfield wrote:
OK--now this request goes to your server.  Hopefully eventually to 
struts.  Struts then steps through the interceptors and eventually calls 
your action.  The action does it's thing and selects a result.


And this whole process can generate as many logs as you have log4j set 
up to generate.  For example, here's a piece from a log (in this case 
generated because the request was multipart/included an upload) in my 
app showing that there were two parameters found in the request 
corresponding with the form's single checkbox:


MultiPartRequest.parse(94) | Found item user.commentsPlain
MultiPartRequest.parse(96) | Item is a normal form field
MultiPartRequest.parse(94) | Found item __checkbox_user.commentsPlain
MultiPartRequest.parse(96) | Item is a normal form field

Why were there two?  Because s:checkbox generated not only an input of 
type checkbox, but also an input of type hidden.  These are both 
visible in the html of the page with the form.


How does having the __checkbox_user.commentsPlain parameter help?  Well, 
the checkbox interceptor notices that it's there, and if 
user.commentsPlain is not, it does whatever it needs to to make the rest 
of the process do the right thing.


-Dale

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: getting the value of a s:checkbox

2007-08-08 Thread Session A Mwamufiya
I appreciate the explanation on how it's all supposed to work, but given my 
limited experience with struts 2 and this type of framework as a whole, I am 
not yet proficient enough to figure out where things are being generated.  I 
use log4j to log a number of events in my code, but I don't even know how to 
display this type of request object logging you're presenting.  I need examples 
to run with and understand how things work; going through this was helpful to 
get a big view, and I don't mean to be rude, but it still doesn't help me read 
the checkbox value.

Is there a simple example I can follow?  That's the best way I learn.

Thanks,
Session


 Dale Newfield wrote:
 OK--now this request goes to your server.  Hopefully eventually to 
 struts.  Struts then steps through the interceptors and eventually
 calls your action.  The action does it's thing and selects a result.
 
 And this whole process can generate as many logs as you have log4j set up
 to generate.  For example, here's a piece from a log (in this case 
 generated because the request was multipart/included an upload) in my app
 showing that there were two parameters found in the request corresponding
 with the form's single checkbox:
 
 MultiPartRequest.parse(94) | Found item user.commentsPlain 
 MultiPartRequest.parse(96) | Item is a normal form field 
 MultiPartRequest.parse(94) | Found item __checkbox_user.commentsPlain 
 MultiPartRequest.parse(96) | Item is a normal form field
 
 Why were there two?  Because s:checkbox generated not only an input of 
 type checkbox, but also an input of type hidden.  These are both visible
 in the html of the page with the form.
 
 How does having the __checkbox_user.commentsPlain parameter help?  Well, 
 the checkbox interceptor notices that it's there, and if 
 user.commentsPlain is not, it does whatever it needs to to make the rest 
 of the process do the right thing.
 
 -Dale
 
 - To
 unsubscribe, e-mail: [EMAIL PROTECTED] For additional
 commands, e-mail: [EMAIL PROTECTED]
 
 
 


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: getting the value of a s:checkbox

2007-08-08 Thread Dale Newfield

Session A Mwamufiya wrote:

Is there a simple example I can follow?  That's the best way I learn.


http://struts.apache.org/2.x/docs/using-checkboxes.html includes a 
detailed example.


-Dale

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]