struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dale Newfield <D...@Newfield.org>
Subject Re: getting the value of a s:checkbox
Date Wed, 08 Aug 2007 17:15:12 GMT
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: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message