You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Peter Dawn <pe...@gmail.com> on 2006/09/07 06:17:30 UTC

Obtaining check box data from a form

guys,

i am trying to implement a big form within my web app. in the form the
user is able to select through checkboxes what information they want
viewed. now each checkbox has a corresponding value associated with
it.

now when the user clicks on the submit button, i want to pass on the
values of all checked checkboxes to my java code (the value of
unchecked boxes should not be passed).

I have been working on it all morning now. can somebody help me out
with this. i am using tap3.

thanks.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Re: Obtaining check box data from a form

Posted by Sam Gendler <sg...@ideasculptor.com>.
The Tapestry Checkbox component doesn't offer a way to do what you
want but it is possible to do it.  If you have multiple input fields
with the same name, the servlet spec says that you can call
request.getParameters("fieldName") and receive an array of strings.

So here's how I solved this:

Write some code that renders a plain <input type="checkbox"
name="myName" value="someValue"/> rather than using Tapestry Checkbox
component.  If you want to make it a component, one very similar to
existing Checkbox, then so much the better.

Now make another component called CheckboxGroup.  Include a listener
method which will get executed whenever the CheckboxGroup is rewound.
Your custom Checkbox component can check if the current Container is a
CheckboxGroup.  if it is, get the name from the CheckboxGroup.  Then,
in your Group listener, call getWebRequest().getParameters("myName")
to retrieve a String[] of values. Now, if necessary, convert the
string to an actual object.  Then assign the array to the appropriate
place. html would look something like this:

<span jwcid="@lib:CheckboxGroup" name="literal:someObject.someEntitySet" >
  <span jwcid="@lib:CustomCheckbox" value="ognl:someValue"/>
  <span jwcid="@lib:CustomCheckbox" value="ognl:someOtherValue"/>
</span>

Although in our case, we skipped the CustomCheckbox component
entirely.  We just pass a SelectionModel to the CheckboxGroup, and use
the label and value properties to render a checkbox from the render
method of the CheckboxGroup.  We can fetch the values during the
rewind method of the same component.  And some simple ognl
manipulations on the name parameter can allow you to assign the
resulting values to the named object/property.

Of course, I have no idea if any of this will work in Tap3, but in my
case, it was only a couple of hours in Tap4, mostly spent figuring out
what changes I needed to make to the contrib:MultiplePropertySelection
and contrib:CheckBoxMultiplePropertySelectionRenderer.  The code was
easy enough to understand and modify to my own needs.

--sam


On 9/6/06, Peter Dawn <pe...@gmail.com> wrote:
> ok. the only other way for me to obtain a users selection would a
> radio button. might try that.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


RE: Obtaining check box data from a form

Posted by Mark Stang <ms...@pingidentity.com>.
The example in the Component Reference doesn't provide the simplest example...


Name: Mark J. Stang
Title: Senior Engineer/Architect
office: +1 303.468.2900
mobile: +1 303.507.2833
Ping Identity



-----Original Message-----
From: Peter Dawn [mailto:petedawn@gmail.com]
Sent: Thu 9/7/2006 4:38 PM
To: Tapestry users
Subject: Re: Obtaining check box data from a form
 
Mark, so as per your example, if i am understanding it corrently, i
can only retrieve the boolean value and not the corresponding string
associated with the checkbox.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org



RE: Obtaining check box data from a form

Posted by Mark Stang <ms...@pingidentity.com>.
Pretty much.  There may be a way, but it is coded in the HTML.  However, I don't think you need to do so.  Or rather I don't think you should need the values that were displayed, they should be hard-coded text in an HTML form.  Why do you need the text that is in the HTML?

Name: Mark J. Stang
Title: Senior Engineer/Architect
office: +1 303.468.2900
mobile: +1 303.507.2833
Ping Identity



-----Original Message-----
From: Peter Dawn [mailto:petedawn@gmail.com]
Sent: Thu 9/7/2006 4:38 PM
To: Tapestry users
Subject: Re: Obtaining check box data from a form
 
Mark, so as per your example, if i am understanding it corrently, i
can only retrieve the boolean value and not the corresponding string
associated with the checkbox.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org



Re: Obtaining check box data from a form

Posted by Peter Dawn <pe...@gmail.com>.
Mark, so as per your example, if i am understanding it corrently, i
can only retrieve the boolean value and not the corresponding string
associated with the checkbox.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


RE: Obtaining check box data from a form

Posted by Mark Stang <ms...@pingidentity.com>.
Peter,
Checkboxes are like any other field.

HTML:
<html>
<head>
    <title>
        Allowable SAML Bindings
    </title>
	<link rel="stylesheet" type="text/css" media="screen" href="../../images/style.css" />
</head>
<body>
    <span jwcid="$content$">
		<table class="interior">
			<tr>
	            <td>
    	            <span jwcid="artifact@thirdparty:AnySubmit"><input jwcid="artifactCheckbox" type="checkbox"/></span>Artifact
     	       </td>
            </tr>
			<span jwcid="showPost">
	            <tr>
		    		<td>
		    			<input jwcid="postCheckbox" type="checkbox"/>POST
		    		</td>
			    </tr>
            </span>
			<span jwcid="showRedirect">
                <tr>
		    		<td>
		    			<input jwcid="redirectCheckbox" type="checkbox"/>Redirect
		    		</td>
                </tr>
            </span>
			<span jwcid="showSoap">
                <tr>
		    		<td>
	    	            <span jwcid="soap@thirdparty:AnySubmit"><input jwcid="soapCheckbox" type="checkbox"/></span>SOAP
		    		</td>
                </tr>
            </span>
		 </table>
   </span>
</body>
</html>

JWC:
    <component id="artifactCheckbox" type="Checkbox">
    	<binding name="selected" expression="page.visit.currentState.artifactBinding"/>
    </component>

    <component id="postCheckbox" type="Checkbox">
        <binding name="selected" expression="page.visit.currentState.postBinding"/>
    </component>
    
    <component id="showPost" type="Conditional">
        <binding name="condition" expression="page.visit.currentState.showPostChoice()"/>
    </component>

     <component id="showRedirect" type="Conditional">
        <binding name="condition" expression="page.visit.currentState.showRedirectChoice()"/>
    </component>
     
    <component id="redirectCheckbox" type="Checkbox">
    	<binding name="selected" expression="page.visit.currentState.redirectBinding"/>
    </component>
    
    <component id="showSoap" type="Conditional">
        <binding name="condition" expression="page.visit.currentState.showSoapChoice()"/>
    </component>
     
    <component id="soapCheckbox" type="Checkbox">
        <binding name="selected" expression="page.visit.currentState.soapBinding"/>
    </component>

JAVA:
    private boolean artifactBinding = true;
    private boolean postBinding = true;
    private boolean redirectBinding = true;
    private boolean soapBinding = true;

    public boolean isArtifactBinding()
    {
        return artifactBinding;
    }

    public void setArtifactBinding(boolean artifactBinding)
    {
        this.artifactBinding = artifactBinding;
    }

    public boolean isPostBinding()
    {
        return postBinding;
    }

    public void setPostBinding(boolean postBinding)
    {
        this.postBinding = postBinding;
    }

    public boolean isRedirectBinding()
    {
        return redirectBinding;
    }

    public void setRedirectBinding(boolean redirectBinding)
    {
        this.redirectBinding = redirectBinding;
    }

    public boolean isSoapBinding()
    {
        return soapBinding;
    }

    public void setSoapBinding(boolean soapBinding)
    {
        this.soapBinding = soapBinding;
    }

All you have to do is put 1-n in an HTML template.  I have mine declared in the .jwc, but you could just put it in the HTML.  Then link them to some method in a java class somewhere. I have mine updating a visit object value "currentState".  "Current State" is the users "current state".  Pick a java object somewhere.

The values of the boolean values will be displayed as checked or unchecked just as the data is in the java object.  If the user checks or unchecks a checkbox and submits it then the java method is called.  The end result is that the java boolean values are displayed and modifiable by your users.  When submitted they automatically populate your java values.  No different than a Text Input Field.

hth,

Mark

Name: Mark J. Stang
Title: Senior Engineer/Architect
office: +1 303.468.2900
mobile: +1 303.507.2833
Ping Identity



-----Original Message-----
From: Peter Dawn [mailto:petedawn@gmail.com]
Sent: Wed 9/6/2006 11:56 PM
To: Tapestry users
Subject: Re: Obtaining check box data from a form
 
ok. the only other way for me to obtain a users selection would a
radio button. might try that.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org



Re: Obtaining check box data from a form

Posted by Peter Dawn <pe...@gmail.com>.
ok. the only other way for me to obtain a users selection would a
radio button. might try that.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Obtaining check box data from a form

Posted by Jesse Kuhnert <jk...@gmail.com>.
Most of the time a checkbox - by definition - is more of a boolean operation
than value...But far be it from me to argue with semantics that do work..

If you want to just get past the problem and move on you can always call
IRequestCycle.getParameterValues("thenameyou gaveallofyourcheckboxes");

On 9/7/06, Peter Dawn <pe...@gmail.com> wrote:
>
> just to clarify again, i want to gather the underlying value of each
> checkbox and not its label.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Jesse Kuhnert
Tapestry/Dojo/(and a dash of TestNG), team member/developer

Open source based consulting work centered around
dojo/tapestry/tacos/hivemind. http://blog.opencomponentry.com

Re: Obtaining check box data from a form

Posted by Peter Dawn <pe...@gmail.com>.
just to clarify again, i want to gather the underlying value of each
checkbox and not its label.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Obtaining check box data from a form

Posted by Peter Dawn <pe...@gmail.com>.
ok i will try again.

i have a bunch of options which the user can select from. they are all
checkboxes (approx say 25). based on this user selection i display
corresponding information on the next page.

now first thing,
1. how should i group these checkboxes, individually, within a span or
something else (multiplepropertyselection)
2. once the user selects their options and presses submit, i want to
gather the data from all selected checkboxes.

i hope this is better.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Obtaining check box data from a form

Posted by Nick Westgate <ni...@key-planning.co.jp>.
Hi Peter.

Your explanation is rather vague, but if you want to treat the checkboxes
as a group, you might want to look at the contrib MultiplePropertySelection:
http://tapestry.apache.org/tapestry3/doc/api/org/apache/tapestry/contrib/form/MultiplePropertySelection.html

Note that all the html docs are included in the Tapestry download.

Cheers,
Nick.


Peter Dawn wrote:
> may be i should put everything within a span and then pass on values
> of checked checkboxes. but how do i group them together. if they were
> radio buttons i would have selected RadioGroup.
> 
> any help guys.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Obtaining check box data from a form

Posted by Peter Dawn <pe...@gmail.com>.
may be i should put everything within a span and then pass on values
of checked checkboxes. but how do i group them together. if they were
radio buttons i would have selected RadioGroup.

any help guys.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Obtaining check box data from a form

Posted by Peter Dawn <pe...@gmail.com>.
i can pass a boolean fine. but how do i pass on the value of the
checkbox on a submit.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Obtaining check box data from a form

Posted by Peter Dawn <pe...@gmail.com>.
its good for a start. how come i couldnt find it. but thanks anyways.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Obtaining check box data from a form

Posted by Jesse Kuhnert <jk...@gmail.com>.
Does this help?

http://tapestry.apache.org/tapestry3/doc/ComponentReference/Checkbox.html

On 9/7/06, Peter Dawn <pe...@gmail.com> wrote:
>
> guys,
>
> i am trying to implement a big form within my web app. in the form the
> user is able to select through checkboxes what information they want
> viewed. now each checkbox has a corresponding value associated with
> it.
>
> now when the user clicks on the submit button, i want to pass on the
> values of all checked checkboxes to my java code (the value of
> unchecked boxes should not be passed).
>
> I have been working on it all morning now. can somebody help me out
> with this. i am using tap3.
>
> thanks.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Jesse Kuhnert
Tapestry/Dojo/(and a dash of TestNG), team member/developer

Open source based consulting work centered around
dojo/tapestry/tacos/hivemind. http://blog.opencomponentry.com