You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Michael Engelhart <me...@mac.com> on 2004/11/30 21:52:42 UTC

Form level validation help

Hi -
I have a form that as a text field that takes a city name and  when  
submitted needs to query a database to determine if there are multiple  
cities that match that name.   If there are then the page redisplays  
and a PropertySelection is rendered with the list of cities that match  
the city name.
I'm trying to use the Validation subsystem to make the FieldLabel's  
render with my custom delegate but can only get the errors that apply  
to the TextField to render.     I'm attaching  the template, page and  
snippets of java code since it's easier to show it that way.
I'm using the technique that's described in the Tapestry in Action.

Basically the output of the form error at the top of the page works  
fine so the delegate is successfully recording the error but the City:  
field label doesn't get wrapped in the span from my delegate's  
writeLabelPrefix()/writeLabelSuffix method.    When I do this identical  
thing but pass in a say an empty field which in turn redisplays the  
page with the TextField component rather then the PropertySelection  
component, the field label gets wrapped in the <span> and shows up red.

Thanks for any help as what I may be doing wrong.    My only guess so  
far is that maybe it has something to do with the contrib:Choose  
component but since I'm new to tapestry I don't understand enough about  
how it works to do much detective work.

Mike
************** Search. Page ****************
<bean name="delegate"  
class="com.earthtrip.site.PropertyCitySearchDelegate" />

<component id="ValidSearchLocationTextField" type="TextField">
	<binding name="value" expression="searchRequest.cityName"/>
</component>
	<component id="ValidSearchLocationPropertySelection"  
type="PropertySelection">
	<binding name="value" expression="searchRequest.cityName"/>
	<binding name="size" expression="4" />
	<binding name="model" expression="locationSelect" />
</component>

*************** Search.html  **************
<span jwcid="@contrib:Choose">
<span jwcid="@contrib:When" condition="ognl:locationSelect.locations ==  
null">
	<td class="AlignRight">
			<span jwcid="@FieldLabel" displayName="message:city-field-label"  
field="ognl:components.ValidSearchLocationTextField">City:</span>
	 </td>
		<td>   							
			<input type="text" jwcid="ValidSearchLocationTextField" size="30" />
	  </td>
</span>
<span jwcid="@contrib:When"  
condition="ognl:locationSelect.displayAsList">
	<td class="VerticalAlignTopRight">
			<span jwcid="@FieldLabel" displayName="message:city-field-label"  
field="ognl:components.ValidSearchLocationPropertySelection">City:</ 
span>
	  </td>
		<td class="VerticalAlignTop">   							
		<select jwcid="ValidSearchLocationPropertySelection">
				<option value="">Boston, MA, US</option>
			  <option value="">Tampa, FL, US</option>
			  <option value="">New York, NY, US</option>
			  <option value="">Los Angeles, CA, US</option>
		  </select>
		 <!--
		 <span jwcid="@Conditional" condition="ognl:beans.delegate.inError">
			 <span jwcid="@Insert" style="font-size:24px; color:red" value="*" />
		 </span>
		 -->						
	  </td>
</span>
	<span jwcid="@contrib:Otherwise">
		<!-- this is a radio group that's equal to the PropertySelection  
above but using a group 3 radio buttons instead of a propertySelection  
-->
	 </span>
</span>
</span>

************* Search.java *********************
public void validateCitySearch( IValidationDelegate delegate) {
	// SNIP - database related searching which isn't really relevant to  
the problem of field validation
	// results is a java.util.List returned from the database with city  
names
	if (results.size() > 0) {
		error = getString("multiple-city-locations-match");
		recordError(delegate, "ValidSearchLocationPropertySelection", error,  
null);
	} else {
		locationSelect.setLocations(null);
		error = getString("no-city-locations-match");
		recordError(delegate, "ValidSearchLocationTextField", error, null);
		// allows the page to redisplay a single city search textfield with  
invalid city name intact
	}
}

protected void recordError(IValidationDelegate delegate, String  
componentId, String message, ValidationConstraint constraint) {
	IFormComponent component = (IFormComponent) getComponent(componentId);
	delegate.setFormComponent(component);
	delegate.record(message, constraint);
}


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


Re: Form level validation help

Posted by Michael Engelhart <me...@mac.com>.
Thanks John.  I guess I don't understand what you mean by having 2 
forms since I don't create a Validator with my method either.   I just 
use the method of validating my fields in the listeners submit method 
and then if there are errors, notify the delegate of them and redisplay 
the page (exactly how it's described in the book).   The method you're 
describing sounds like it  requires a lot of duplicate code (does it?) 
but I really am not sure what you  meant.   Either way I have this page 
working perfectly except for this bit of field tracking that's not 
rendering correctly.   If you approached it your way because it's not 
possible to do what I'm trying to do then I'd be glad to hear more 
about the how/why of your method.

Anyway, my question remains if anyone has any insight into what I may 
be doing wrong that's causing this particular field to not render from 
my delegate when it's been recorded as having an error.

Thanks
Mike
On Nov 30, 2004, at 4:13 PM, John Studarus wrote:

>
> I normally do this with two forms.  The first form
> generates the values for the second form.  Then you
> don't need to worry about creating your own validator.
>  Just have the submit listener on the first form
> perform all the work to populate the second form.
>
>         John
>
>
> --- Michael Engelhart <me...@mac.com> wrote:
>
>> Hi -
>> I have a form that as a text field that takes a city
>> name and  when
>> submitted needs to query a database to determine if
>> there are multiple
>> cities that match that name.   If there are then the
>> page redisplays
>> and a PropertySelection is rendered with the list of
>> cities that match
>> the city name.
>> I'm trying to use the Validation subsystem to make
>> the FieldLabel's
>> render with my custom delegate but can only get the
>> errors that apply
>> to the TextField to render.     I'm attaching  the
>> template, page and
>> snippets of java code since it's easier to show it
>> that way.
>> I'm using the technique that's described in the
>> Tapestry in Action.
>>
>> Basically the output of the form error at the top of
>> the page works
>> fine so the delegate is successfully recording the
>> error but the City:
>> field label doesn't get wrapped in the span from my
>> delegate's
>> writeLabelPrefix()/writeLabelSuffix method.    When
>> I do this identical
>> thing but pass in a say an empty field which in turn
>> redisplays the
>> page with the TextField component rather then the
>> PropertySelection
>> component, the field label gets wrapped in the
>> <span> and shows up red.
>>
>> Thanks for any help as what I may be doing wrong.
>> My only guess so
>> far is that maybe it has something to do with the
>> contrib:Choose
>> component but since I'm new to tapestry I don't
>> understand enough about
>> how it works to do much detective work.
>>
>> Mike
>> ************** Search. Page ****************
>> <bean name="delegate"
>>
> class="com.earthtrip.site.PropertyCitySearchDelegate"
>> />
>>
>> <component id="ValidSearchLocationTextField"
>> type="TextField">
>> 	<binding name="value"
>> expression="searchRequest.cityName"/>
>> </component>
>> 	<component
>> id="ValidSearchLocationPropertySelection"
>> type="PropertySelection">
>> 	<binding name="value"
>> expression="searchRequest.cityName"/>
>> 	<binding name="size" expression="4" />
>> 	<binding name="model" expression="locationSelect"
>> />
>> </component>
>>
>> *************** Search.html  **************
>> <span jwcid="@contrib:Choose">
>> <span jwcid="@contrib:When"
>> condition="ognl:locationSelect.locations ==
>> null">
>> 	<td class="AlignRight">
>> 			<span jwcid="@FieldLabel"
>> displayName="message:city-field-label"
>>
> field="ognl:components.ValidSearchLocationTextField">City:</span>
>> 	 </td>
>> 		<td>   							
>> 			<input type="text"
>> jwcid="ValidSearchLocationTextField" size="30" />
>> 	  </td>
>> </span>
>> <span jwcid="@contrib:When"
>> condition="ognl:locationSelect.displayAsList">
>> 	<td class="VerticalAlignTopRight">
>> 			<span jwcid="@FieldLabel"
>> displayName="message:city-field-label"
>>
> field="ognl:components.ValidSearchLocationPropertySelection">City:</
>>
>> span>
>> 	  </td>
>> 		<td class="VerticalAlignTop">   							
>> 		<select
>> jwcid="ValidSearchLocationPropertySelection">
>> 				<option value="">Boston, MA, US</option>
>> 			  <option value="">Tampa, FL, US</option>
>> 			  <option value="">New York, NY, US</option>
>> 			  <option value="">Los Angeles, CA, US</option>
>> 		  </select>
>> 		 <!--
>> 		 <span jwcid="@Conditional"
>> condition="ognl:beans.delegate.inError">
>> 			 <span jwcid="@Insert" style="font-size:24px;
>> color:red" value="*" />
>> 		 </span>
>> 		 -->						
>> 	  </td>
>> </span>
>> 	<span jwcid="@contrib:Otherwise">
>> 		<!-- this is a radio group that's equal to the
>> PropertySelection
>> above but using a group 3 radio buttons instead of a
>> propertySelection
>> -->
>> 	 </span>
>> </span>
>> </span>
>>
>> ************* Search.java *********************
>> public void validateCitySearch( IValidationDelegate
>> delegate) {
>> 	// SNIP - database related searching which isn't
>> really relevant to
>> the problem of field validation
>> 	// results is a java.util.List returned from the
>> database with city
>> names
>> 	if (results.size() > 0) {
>> 		error =
>> getString("multiple-city-locations-match");
>> 		recordError(delegate,
>> "ValidSearchLocationPropertySelection", error,
>> null);
>> 	} else {
>> 		locationSelect.setLocations(null);
>> 		error = getString("no-city-locations-match");
>> 		recordError(delegate,
>> "ValidSearchLocationTextField", error, null);
>> 		// allows the page to redisplay a single city
>> search textfield with
>> invalid city name intact
>> 	}
>> }
>>
>> protected void recordError(IValidationDelegate
>> delegate, String
>> componentId, String message, ValidationConstraint
>> constraint) {
>> 	IFormComponent component = (IFormComponent)
>> getComponent(componentId);
>> 	delegate.setFormComponent(component);
>> 	delegate.record(message, constraint);
>> }
>>
>>
>>
> ---------------------------------------------------------------------
>> To unsubscribe, e-mail:
>> tapestry-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail:
>> tapestry-user-help@jakarta.apache.org
>>
>>
>
>
>
> 		
> __________________________________
> Do you Yahoo!?
> Read only the mail you want - Yahoo! Mail SpamGuard.
> http://promotions.yahoo.com/new_mail
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>


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


Re: Form level validation help

Posted by John Studarus <jo...@yahoo.com>.
I normally do this with two forms.  The first form
generates the values for the second form.  Then you
don't need to worry about creating your own validator.
 Just have the submit listener on the first form
perform all the work to populate the second form.

        John


--- Michael Engelhart <me...@mac.com> wrote:

> Hi -
> I have a form that as a text field that takes a city
> name and  when  
> submitted needs to query a database to determine if
> there are multiple  
> cities that match that name.   If there are then the
> page redisplays  
> and a PropertySelection is rendered with the list of
> cities that match  
> the city name.
> I'm trying to use the Validation subsystem to make
> the FieldLabel's  
> render with my custom delegate but can only get the
> errors that apply  
> to the TextField to render.     I'm attaching  the
> template, page and  
> snippets of java code since it's easier to show it
> that way.
> I'm using the technique that's described in the
> Tapestry in Action.
> 
> Basically the output of the form error at the top of
> the page works  
> fine so the delegate is successfully recording the
> error but the City:  
> field label doesn't get wrapped in the span from my
> delegate's  
> writeLabelPrefix()/writeLabelSuffix method.    When
> I do this identical  
> thing but pass in a say an empty field which in turn
> redisplays the  
> page with the TextField component rather then the
> PropertySelection  
> component, the field label gets wrapped in the
> <span> and shows up red.
> 
> Thanks for any help as what I may be doing wrong.   
> My only guess so  
> far is that maybe it has something to do with the
> contrib:Choose  
> component but since I'm new to tapestry I don't
> understand enough about  
> how it works to do much detective work.
> 
> Mike
> ************** Search. Page ****************
> <bean name="delegate"  
>
class="com.earthtrip.site.PropertyCitySearchDelegate"
> />
> 
> <component id="ValidSearchLocationTextField"
> type="TextField">
> 	<binding name="value"
> expression="searchRequest.cityName"/>
> </component>
> 	<component
> id="ValidSearchLocationPropertySelection"  
> type="PropertySelection">
> 	<binding name="value"
> expression="searchRequest.cityName"/>
> 	<binding name="size" expression="4" />
> 	<binding name="model" expression="locationSelect"
> />
> </component>
> 
> *************** Search.html  **************
> <span jwcid="@contrib:Choose">
> <span jwcid="@contrib:When"
> condition="ognl:locationSelect.locations ==  
> null">
> 	<td class="AlignRight">
> 			<span jwcid="@FieldLabel"
> displayName="message:city-field-label"  
>
field="ognl:components.ValidSearchLocationTextField">City:</span>
> 	 </td>
> 		<td>   							
> 			<input type="text"
> jwcid="ValidSearchLocationTextField" size="30" />
> 	  </td>
> </span>
> <span jwcid="@contrib:When"  
> condition="ognl:locationSelect.displayAsList">
> 	<td class="VerticalAlignTopRight">
> 			<span jwcid="@FieldLabel"
> displayName="message:city-field-label"  
>
field="ognl:components.ValidSearchLocationPropertySelection">City:</
> 
> span>
> 	  </td>
> 		<td class="VerticalAlignTop">   							
> 		<select
> jwcid="ValidSearchLocationPropertySelection">
> 				<option value="">Boston, MA, US</option>
> 			  <option value="">Tampa, FL, US</option>
> 			  <option value="">New York, NY, US</option>
> 			  <option value="">Los Angeles, CA, US</option>
> 		  </select>
> 		 <!--
> 		 <span jwcid="@Conditional"
> condition="ognl:beans.delegate.inError">
> 			 <span jwcid="@Insert" style="font-size:24px;
> color:red" value="*" />
> 		 </span>
> 		 -->						
> 	  </td>
> </span>
> 	<span jwcid="@contrib:Otherwise">
> 		<!-- this is a radio group that's equal to the
> PropertySelection  
> above but using a group 3 radio buttons instead of a
> propertySelection  
> -->
> 	 </span>
> </span>
> </span>
> 
> ************* Search.java *********************
> public void validateCitySearch( IValidationDelegate
> delegate) {
> 	// SNIP - database related searching which isn't
> really relevant to  
> the problem of field validation
> 	// results is a java.util.List returned from the
> database with city  
> names
> 	if (results.size() > 0) {
> 		error =
> getString("multiple-city-locations-match");
> 		recordError(delegate,
> "ValidSearchLocationPropertySelection", error,  
> null);
> 	} else {
> 		locationSelect.setLocations(null);
> 		error = getString("no-city-locations-match");
> 		recordError(delegate,
> "ValidSearchLocationTextField", error, null);
> 		// allows the page to redisplay a single city
> search textfield with  
> invalid city name intact
> 	}
> }
> 
> protected void recordError(IValidationDelegate
> delegate, String  
> componentId, String message, ValidationConstraint
> constraint) {
> 	IFormComponent component = (IFormComponent)
> getComponent(componentId);
> 	delegate.setFormComponent(component);
> 	delegate.record(message, constraint);
> }
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> tapestry-user-help@jakarta.apache.org
> 
> 



		
__________________________________ 
Do you Yahoo!? 
Read only the mail you want - Yahoo! Mail SpamGuard. 
http://promotions.yahoo.com/new_mail 

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