You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by George Christman <gc...@cardaddy.com> on 2012/10/16 02:15:10 UTC

How to remove query parmeter from url string

Hello everyone, I'm working on my new search page which uses tapestry query
parameters. The query parameters are dynamically set from a select menu. So
far it seems to be working, however I do not know how to clear the query
parameter from the url when the select menu is set to blank. I end up
getting a null pointer exception. Below is my code. btw, if anybody sees any
room for performance modifications, feel free to comment. This is very new
to me. Thanks


<html t:type="layout"
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd"
xmlns:p="tapestry:parameter" pageTitle="Used Cars For Sale in region goes
here">
   <br/><br/><br/><br/>
    <t:Form t:id="searchForm">
        <t:Select t:id="searchYear" value="vehicleYear"
model="yearSearchModel"/>
        <t:Select t:id="searchMake" value="vehicleMake"
model="makeSearchModel"/>
        <t:Select t:id="searchModel" value="vehicleModel"
model="modelSearchModel"/>
        <t:Submit/>
    </t:Form>
    
    <t:Loop source="vehicles" value="vehicle">
        <t:PageLink page="used_car_for_sale"
context="vehicle.id">${vehicle.year} ${vehicle.make} ${vehicle.model}
${vehicle.trimLevel}</t:PageLink><br/>
    </t:Loop>
</html>



public class UsedCarsForSale {

    @ActivationRequestParameter(value = "year")
    private String year;  
    @ActivationRequestParameter(value = "make")
    private String make;    
    @ActivationRequestParameter(value = "model")
    private String model;
    
    @Property
    private VehicleYear vehicleYear;
    @Property
    private VehicleMake vehicleMake;
    @Property
    private VehicleModel vehicleModel;

    @Inject
    private YearDAO yearDAO;
    @Inject
    private MakeDAO makeDAO;
    @Inject
    private ModelDAO modelDAO;
    
    @Inject
    private SelectModelFactory selectModelFactory;
    @Property
    private Vehicle vehicle;

    @Inject
    private Session session;

    @Inject
    private PageRenderLinkSource pageRenderLinkSource;
    
    void onPrepareFromSearchForm() {
        System.out.println(year);
        if(this.year != null) {
            this.vehicleYear = this.yearDAO.find(year);
        }        
        if(this.make != null) {
            this.vehicleMake = this.makeDAO.find(make);
        }        
        if(this.model != null) {
            this.vehicleModel = this.modelDAO.find(model);
        }
    }

    Object onSuccess() {
        this.year = vehicleYear.getName();
        this.make = vehicleMake.getName();
        this.model = vehicleModel.getName();
        return pageRenderLinkSource.createPageRenderLink(this.getClass());
    }

    public List<Vehicle> getVehicles() {
        Criteria criteria = this.session.createCriteria(Vehicle.class);
        criteria.createAlias("vehicleYear", "vehicleYear");
        criteria.createAlias("vehicleMake", "vehicleMake");
        criteria.createAlias("vehicleModel", "vehicleModel");
        
        if (year != null) {
            criteria.add(Restrictions.eq("vehicleYear.name", year));
        }
        if (make != null) {
            criteria.add(Restrictions.eq("vehicleMake.name",
make).ignoreCase());
        }
        if (model != null) {
            criteria.add(Restrictions.eq("vehicleModel.name",
model).ignoreCase());
        }
        
        return criteria.list();
    }

    public SelectModel getYearSearchModel() {
        return this.selectModelFactory.create(this.yearDAO.findAll(),
"name");
    }
    
    public SelectModel getMakeSearchModel() {
        return this.selectModelFactory.create(this.makeDAO.findAll(),
"name");
    }
    
    public SelectModel getModelSearchModel() {
        return this.selectModelFactory.create(this.modelDAO.findAll(),
"name");
    }
    
}




--
View this message in context: http://tapestry.1045711.n5.nabble.com/How-to-remove-query-parmeter-from-url-string-tp5716922.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: How to remove query parmeter from url string

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Tue, 16 Oct 2012 10:26:10 -0300, Lance Java <la...@googlemail.com>  
wrote:

> On second thought, return this (aka the current page instance)

I wouldn't return 'this', as it always forces a redirect, and that's not  
what you want in all cases, specially inside onActivate() methods.

George, I think there's no reason to use PageRenderLinkSource to redirect  
to the same page at all. Just return null or make your method return void  
in your event handler methods.

-- 
Thiago H. de Paula Figueiredo

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


Re: How to remove query parmeter from url string

Posted by Lance Java <la...@googlemail.com>.
Since you've got two entry points, I'd probably use @RequestParam in
onActivate() and populate the same render variables that are populated by
submitting the form. 



--
View this message in context: http://tapestry.1045711.n5.nabble.com/How-to-remove-query-parmeter-from-url-string-tp5716922p5716971.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: How to remove query parmeter from url string

Posted by George Christman <gc...@cardaddy.com>.
Would it be better to somehow use @RequestParam inside of onActivate rather
than @ActivationRequestParameter?

BTW, I'll let you know about returning the page instance tonight. Hopefully
that works :)



--
View this message in context: http://tapestry.1045711.n5.nabble.com/How-to-remove-query-parmeter-from-url-string-tp5716922p5716960.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: How to remove query parmeter from url string

Posted by Lance Java <la...@googlemail.com>.
Ok, cool... then your @ActivationRequestParameter approach seems fine to me.
Just checking ;)



--
View this message in context: http://tapestry.1045711.n5.nabble.com/How-to-remove-query-parmeter-from-url-string-tp5716922p5716959.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: How to remove query parmeter from url string

Posted by George Christman <gc...@cardaddy.com>.
Hi Lance, I'd like all the search filters to remain in the URL for book
marking, sharing the URL, and SEO. My goal is for the search page to
function similarly to the ebaymotors search page. The search form resides
directly within the search page. I do however have links from other pages
that will trigger a search. Example, on the home page of my site, you can
click the Nissan link causing a redirect to the search page while populating
the make parameter with Nissan which applies a search filter for make
Nissan. I would rather avoid @Persist if possible due to the fact at times
there are very high server loads. 

In the applications current state, I'm using a key value pair search/0/2
with onActivate(). This does work, however it creates urls that are much
more complex to decode. I figured using query parameters would be much
easier to work with. 



--
View this message in context: http://tapestry.1045711.n5.nabble.com/How-to-remove-query-parmeter-from-url-string-tp5716922p5716956.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: How to remove query parmeter from url string

Posted by Lance Java <la...@googlemail.com>.
George, are you doing all of this to maintain state throughout tapestry's
redirect-after-post?
Or do you actually have two entry points into your search?

If it's the former, have you considered @Persist? You can either use
PersistenceConstants.FLASH to temporarily store in the session or
PersistenceConstants.CLIENT to store in the URL.

http://tapestry.apache.org/persistent-page-data.html



--
View this message in context: http://tapestry.1045711.n5.nabble.com/How-to-remove-query-parmeter-from-url-string-tp5716922p5716943.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: How to remove query parmeter from url string

Posted by Lance Java <la...@googlemail.com>.
To tell the truth you seem to be duplicating to logic normally seen in a
<form method="GET">. It seems that you have two ways to fire your search:

1. onActivate - This is where you are getting request parameters which were
passed to you from another page (or maybe even this page)
2. Search form is posted - Here you are using tapestry's select / textField
to populate form components

For scenario 1, use @RequestParam or request.getparameter() in an onActivate
method
For scenario 2, tapestry will auto populate your variables

If you populate the same render variables in both cases, you can share the
rest of the rendering behaviour.



--
View this message in context: http://tapestry.1045711.n5.nabble.com/How-to-remove-query-parmeter-from-url-string-tp5716922p5716939.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: How to remove query parmeter from url string

Posted by George Christman <gc...@cardaddy.com>.
Okay, so your thinking my issue has to do with my return logic? I'll give
your suggestion a test tonight. Do you see any other issues with me using
this code for filter criteria? Just not sure if it's the most efficient way
to accomplish this task and considering it's the 2nd highest used page on
the site, it tends to concern me. 



--
View this message in context: http://tapestry.1045711.n5.nabble.com/How-to-remove-query-parmeter-from-url-string-tp5716922p5716937.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: How to remove query parmeter from url string

Posted by Lance Java <la...@googlemail.com>.
On second thought, return this (aka the current page instance)



--
View this message in context: http://tapestry.1045711.n5.nabble.com/How-to-remove-query-parmeter-from-url-string-tp5716922p5716936.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: How to remove query parmeter from url string

Posted by Lance Java <la...@googlemail.com>.
You could simply return this or null.



--
View this message in context: http://tapestry.1045711.n5.nabble.com/How-to-remove-query-parmeter-from-url-string-tp5716922p5716935.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: How to remove query parmeter from url string

Posted by George Christman <gc...@cardaddy.com>.
I've tried setting the @ActivationRequestParameter to null, however when the
page reloads the parameter still exist in the URL. 

Do you guys think the URL remains intact do to how I'm reloading the page
using  pageRenderLinkSource.createPageRenderLink(this.getClass()); ?



--
View this message in context: http://tapestry.1045711.n5.nabble.com/How-to-remove-query-parmeter-from-url-string-tp5716922p5716934.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: How to remove query parmeter from url string

Posted by Lance Java <la...@googlemail.com>.
Ah, I get it now... sorry. I've not needed to do this but can you set your
@ActivationRequestParameter values to null?



--
View this message in context: http://tapestry.1045711.n5.nabble.com/How-to-remove-query-parmeter-from-url-string-tp5716922p5716933.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: How to remove query parmeter from url string

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
Have you tried setting the corresponding fields to null?

On Tue, 16 Oct 2012 09:46:44 -0300, George Christman  
<gc...@cardaddy.com> wrote:

> Hi Guys, I'm confused now. I decided to use query parameters in my page  
> URL
> over key/pair parameters.
>
> Example
> http://cardaddy.com/used_cars_for_sale?year=2009&make=Nissan&model=GTR
>
> The query parameters are set based on year make model options selected  
> from
> select menu then submitted. This part seems to work fine.
>
> The issue, if the user decides to set a select menu to blank ie making an
> option null. I'd like to remove that parameter from the URL.
>
> Example
> The year select menu is set to null by the user and the form is  
> submitted,
> I'd like to remove ?year=2009 from the query string if it exist  
> resulting in
> the following URL.
>
> http://cardaddy.com/used_cars_for_sale?make=Nissan&model=GTR
>
> I'm basing the overall design on Geoff example,
> http://jumpstart.doublenegative.com.au/jumpstart/examples/state/passingbyquerystring?first=Humpty&last=Dumpty
>
>
>
>
> --
> View this message in context:  
> http://tapestry.1045711.n5.nabble.com/How-to-remove-query-parmeter-from-url-string-tp5716922p5716931.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>


-- 
Thiago H. de Paula Figueiredo

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


Re: How to remove query parmeter from url string

Posted by George Christman <gc...@cardaddy.com>.
Hi Guys, I'm confused now. I decided to use query parameters in my page URL
over key/pair parameters. 

Example 
http://cardaddy.com/used_cars_for_sale?year=2009&make=Nissan&model=GTR

The query parameters are set based on year make model options selected from
select menu then submitted. This part seems to work fine. 

The issue, if the user decides to set a select menu to blank ie making an
option null. I'd like to remove that parameter from the URL. 

Example
The year select menu is set to null by the user and the form is submitted,
I'd like to remove ?year=2009 from the query string if it exist resulting in
the following URL. 

http://cardaddy.com/used_cars_for_sale?make=Nissan&model=GTR

I'm basing the overall design on Geoff example, 
http://jumpstart.doublenegative.com.au/jumpstart/examples/state/passingbyquerystring?first=Humpty&last=Dumpty




--
View this message in context: http://tapestry.1045711.n5.nabble.com/How-to-remove-query-parmeter-from-url-string-tp5716922p5716931.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: How to remove query parmeter from url string

Posted by Lance Java <la...@googlemail.com>.
Most of the time in tapestry, you will never need to access request
parameters yourself. Tapestry's form/input components get and set values on
your pages / components for you. Tapestry pages can use the activation
context and events can use the event context. It's only very rarely that you
should touch request parameters, mostly in cases where you are integrating
with 3rd party libraries.

http://tapestry.apache.org/forms-and-validation.html



--
View this message in context: http://tapestry.1045711.n5.nabble.com/How-to-remove-query-parmeter-from-url-string-tp5716922p5716930.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: How to remove query parmeter from url string

Posted by Alejandro Scandroli <al...@gmail.com>.
Hi George

I have a similar scenario, but the main difference is that I don't
know before hand the names of the query parameters.
I only have one page with this particular requirement so I do all the
URL query parameters encoding directly in the same page using the
events: DECORATE_PAGE_RENDER_LINK and DECORATE_COMPONENT_EVENT_LINK

Here is how my code looks like:

@OnEvent(EventConstants.ACTIVATE)
void activate(EventContext context)
{
	filters = new ArrayList<Filter>();
	decodeFiltersFromRequest(request);
}

@OnEvent(EventConstants.DECORATE_PAGE_RENDER_LINK)
void decoratePageRenderLink(Link link, PageRenderRequestParameters parameters)
{
	encodeFiltersIntoLink(link);
}

@OnEvent(EventConstants.DECORATE_COMPONENT_EVENT_LINK)
void decorateComponentEventLink(Link link,
ComponentEventRequestParameters parameters)
{
	encodeFiltersIntoLink(link);
}

private void encodeFiltersIntoLink(Link link)
{
	if (filters != null) {
		for (Filter filter : filters)
		{
			link.addParameter(filter.getAttribute().getId(),
urlEncoder.encode(filter.getValue()));
		}
	}
}

private void decodeFiltersFromRequest(Request request)
{
	for (String parameter : request.getParameterNames())
	{
		// do not care about tapestry internal form parameters
		// && do not care about page form parameters
		// && DO NOT care about chenillekit's AbstractEventMixin "value" parameter
		if (!parameter.startsWith("t:") && !parameter.startsWith("f_") &&
!"value".equals(parameter))
		{
			FilterAttribute attribute = session.get(FilterAttribute.class, parameter);
			if (attribute != null)
			{
				String[] params = request.getParameters(parameter);
				for (String param : params)
				{
					filters.add(new Filter(attribute, urlEncoder.decode(param)));
				}
			} else {
				// do something else
				logger.error("weird request parameters names: " +
request.getParameterNames().toString());
			}
		}
	}
}


I hope it helps.

Cheers.
Alejandro.

On Wed, Oct 17, 2012 at 4:11 PM, George Christman
<gc...@cardaddy.com> wrote:
> As always, thanks Lance / Thiago, I think at this point you guys have
> answered all my base questions. As far as my logic question, I think that it
> is probably best suited for stack overflow as it doesn't completely relate
> to tapestry. Hopefully this post will help others in the future who may be
> trying to build some sort of eCommerce site.
>
>
>
> --
> View this message in context: http://tapestry.1045711.n5.nabble.com/How-to-remove-query-parmeter-from-url-string-tp5716922p5717007.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> 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: How to remove query parmeter from url string

Posted by George Christman <gc...@cardaddy.com>.
As always, thanks Lance / Thiago, I think at this point you guys have
answered all my base questions. As far as my logic question, I think that it
is probably best suited for stack overflow as it doesn't completely relate
to tapestry. Hopefully this post will help others in the future who may be
trying to build some sort of eCommerce site. 



--
View this message in context: http://tapestry.1045711.n5.nabble.com/How-to-remove-query-parmeter-from-url-string-tp5716922p5717007.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: How to remove query parmeter from url string

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Wed, 17 Oct 2012 10:36:46 -0300, George Christman  
<gc...@cardaddy.com> wrote:

> So I think this is my last question in regards to this topic. If your  
> doing your calculations on the fly, example converting aston marton to
> aston-martin which would mean you would later need to convert it back to
> aston marton to do the query, what do you do when the string naturally
> contains a dash. Example blue-purple, no spaces, but when decoded it  
> would be decoded as blue purple with the assumption we replace dashes  
> with space.

This is some logic you need to do yourself.

> If I go the encoder route, I'd probably want something that handles all  
> my parameter strings. It would be nice if tapestry offered you the  
> ability to easily change it's encoder strategy. Example uses dashes  
> instead of the
> zeros.

There is already: override the URLEncoder service. Or override the default  
ValueEncoder for String, as Lance suggested.

-- 
Thiago H. de Paula Figueiredo

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


Re: How to remove query parmeter from url string

Posted by Lance Java <la...@googlemail.com>.
> It would be nice if tapestry offered you the ability to easily change it's
encoder strategy. Example uses dashes instead of the zeros.
Download the tapestry sources and check out URLEncoderImpl. Use this as a
basis to override the default URLEncoder.



--
View this message in context: http://tapestry.1045711.n5.nabble.com/How-to-remove-query-parmeter-from-url-string-tp5716922p5717006.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: How to remove query parmeter from url string

Posted by George Christman <gc...@cardaddy.com>.
So I think this is my last question in regards to this topic. If your doing
your calculations on the fly, example converting aston marton to
aston-martin which would mean you would later need to convert it back to
aston marton to do the query, what do you do when the string naturally
contains a dash. Example blue-purple, no spaces, but when decoded it would
be decoded as blue purple with the assumption we replace dashes with space. 

If I go the encoder route, I'd probably want something that handles all my
parameter strings. It would be nice if tapestry offered you the ability to
easily change it's encoder strategy. Example uses dashes instead of the
zeros. 



--
View this message in context: http://tapestry.1045711.n5.nabble.com/How-to-remove-query-parmeter-from-url-string-tp5716922p5717004.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: How to remove query parmeter from url string

Posted by Lance Java <la...@googlemail.com>.
> is returning a link in onSuccess the right way to build the URL
If you're using @ActivationRequestParam then as Thiago said a void return is
probably best. If you're not using  @ActivationRequestParam you will either
need to build a link or use @Persist (lets not discuss activation context
here).

> you'll notice in onSuccess I'm getting the objects name and then passing
> the string name
Ah yeah... I can see that now. So it's using the String ValueEncoder not the
hibernate ValueEncoder.

> should I create some sort of encoder
That's exactly what i'd do

> should I do the work up front and store a column in the database
I'd never store a value that can be calculated. It's unnecessary
maintenance.

I guess a question you want to ask yourself is should your custom encoder be
global or just for these few selects? If it's global, you might want to
consider overriding the default string ValueEncoder.



--
View this message in context: http://tapestry.1045711.n5.nabble.com/How-to-remove-query-parmeter-from-url-string-tp5716922p5717001.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: How to remove query parmeter from url string

Posted by George Christman <gc...@cardaddy.com>.
Hi Lance, yes using @ActivationRequestParam was deffinately much cleaner
since I didn't need an onActivate nor did I need to return a Link in
onSuccess. BTW, is returning a link in onSuccess the right way to build the
URL?

A problem I found with @ActivationRequestParam is my inability to handle
exceptions properly. If someone puts a bunch of garbage in the URL, it
results in an exception. Perhaps I just don't know how to handle them with
@ActivationRequestParam, but at least I know with onActivate, I can handle
them. 

My pk's are in fact longs, so my table structure is pk type long, name type
string. I'm passing the object into my select menu, then when a user selects
an item from the select menu and submits the results, you'll notice in
onSuccess I'm getting the objects name and then passing the string name into
the URL rather than the pk. I'm doing it this way because I didn't want pk's
in my URLs, I'd prefer readable URLs for SEO. So as you can see, it
unfortunately adds a lot more complexity to the code. So the question is
should I create some sort of encoder that encodes all spaces with either an
underscore or dash then later decodes it back?, or should I do the work up
front and store a column in the database that already has either an
underscore or a dash in place of a space? Option two seems like the better
solution IMHO eliminating the chance of damaging a name that may by default
contain those chars. 

Thanks Lance. 



--
View this message in context: http://tapestry.1045711.n5.nabble.com/How-to-remove-query-parmeter-from-url-string-tp5716922p5716998.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: How to remove query parmeter from url string

Posted by Lance Java <la...@googlemail.com>.
Since you're using tapestry-hibernate, you will be using an auto-generated
ValueEncoder under the hood to convert to/from clientside strings to your
entities. So this seems to lead to the fact that "Aston Martin" is a primary
key in you database. If this is the case it's probably a bad idea to have
spaces in primary keys.




--
View this message in context: http://tapestry.1045711.n5.nabble.com/How-to-remove-query-parmeter-from-url-string-tp5716922p5716990.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: How to remove query parmeter from url string

Posted by Lance Java <la...@googlemail.com>.
> tell me if I'm using the RequestParameters properly now?
Looks good to me. I guess it's a judgement call as to whether @RequestParam
is cleaner than @ActivationRequestParam. With @ActivationRequestParam I'm
guessing that onSuccess() was a bit cleaner  with a void return? It's up to
you in the end

> Also, how do you typically handle spaces in the URL parameters
Tapestry converts your entities to client side strings using an encoder @see
<t:select encoder="..." />






--
View this message in context: http://tapestry.1045711.n5.nabble.com/How-to-remove-query-parmeter-from-url-string-tp5716922p5716987.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: How to remove query parmeter from url string

Posted by George Christman <gc...@cardaddy.com>.
Hi Lance, setting the variables to null resolved my issue. Not sure what I
was doing last night that wouldn't allow it to work. Anyhow Lance, would you
take a look at my code below and tell me if I'm using the RequestParameters
properly now? Also, how do you typically handle spaces in the URL
parameters, example 
Aston Martin is being converted to Aston$0020Martin rather than
Aston_Martin. 

Code sample using request parameters. Once again guys, I really appreciate
all your help. 

    <t:Form t:id="searchForm">        
        <t:Select t:id="searchYear" value="vehicleYear"
model="yearSearchModel"/><br/>
        <t:Select t:id="searchMake" zone="searchModelZone"
value="vehicleMake" model="makeSearchModel"/>
        <t:Zone t:id="searchModelZone">
            <t:Select t:id="searchModel" value="vehicleModel"
model="modelSearchModel"/>
        </t:Zone>
        <t:Submit/>
    </t:Form>


public class Used_Cars_For_SaleIndex {
    
    @Component(id = "searchForm")
    @Property
    private Form form;    
    @Inject
    private Session session;
    
    private String year;
    private String make;
    private String model;
    
    @Property
    private Vehicle vehicle;
    @Property
    private VehicleYear vehicleYear;
    @Property
    private VehicleMake vehicleMake;
    @Property
    private VehicleModel vehicleModel;
    
    @Inject
    private YearDAO yearDAO;
    @Inject
    private MakeDAO makeDAO;
    @Inject
    private ModelDAO modelDAO;
    @Inject
    private VehicleConfigurationDAO vehicleConfigurationDAO;
    
    @Property
    private SelectModel modelSearchModel;
    @Inject
    private SelectModelFactory selectModelFactory;
    
    @Inject
    private PageRenderLinkSource pageRenderLinkSource;
    @InjectComponent
    private Zone searchModelZone;
    @Inject
    private PageRenderLinkSource linkSource;
    
    void onActivate(@RequestParameter(value="year", allowBlank = true)
String year,
            @RequestParameter(value="make", allowBlank = true) String make,
            @RequestParameter(value="model", allowBlank = true) String
model) {
        this.year = year;
        this.make = make;
        this.model = model;
    }

    void onPrepareForRenderFromSearchForm() {  
        this.modelSearchModel =
this.selectModelFactory.create(this.vehicleConfigurationDAO.getModels(this.makeDAO.find(this.make)),
"name");
    }
    
    void onPrepareFromSearchForm() {       
        this.vehicleYear = this.yearDAO.find(year);
        this.vehicleMake = this.makeDAO.find(make);
        this.vehicleModel = this.modelDAO.find(model);        
    }

    Link onSuccess() {     
        Link link =
linkSource.createPageRenderLink(Used_Cars_For_SaleIndex.class);       
        if(vehicleYear != null) link.addParameterValue("year",
vehicleYear.getName());
        if(vehicleMake != null) link.addParameterValue("make",
vehicleMake.getName());
        if(vehicleModel != null) link.addParameterValue("model",
vehicleModel.getName());
        return link;
    }

    public List<Vehicle> getVehicles() {
        Criteria criteria = this.session.createCriteria(Vehicle.class);
        criteria.createAlias("vehicleYear", "vehicleYear");
        criteria.createAlias("vehicleMake", "vehicleMake");
        criteria.createAlias("vehicleModel", "vehicleModel");

        if (year != null) criteria.add(Restrictions.eq("vehicleYear.name",
year));        
        if (make != null) criteria.add(Restrictions.eq("vehicleMake.name",
make).ignoreCase());       
        if (model != null) criteria.add(Restrictions.eq("vehicleModel.name",
model).ignoreCase());        

        return criteria.list();
    }

    public SelectModel getYearSearchModel() {
        return this.selectModelFactory.create(this.yearDAO.findAll(),
"name");
    }

    public SelectModel getMakeSearchModel() {
        return this.selectModelFactory.create(this.makeDAO.findAll(),
"name");
    }
    
    public Object onValueChangedFromSearchMake(VehicleMake make) {
        this.modelSearchModel =
this.selectModelFactory.create(this.vehicleConfigurationDAO.getModels(make),
"name");
        return searchModelZone.getBody();
    }
}




--
View this message in context: http://tapestry.1045711.n5.nabble.com/How-to-remove-query-parmeter-from-url-string-tp5716922p5716985.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: How to remove query parmeter from url string

Posted by William Lopes <wi...@gmail.com>.
Sorry, I don't know if I understand your problem, however you can use a
verification in onActivate or setupRender, no?

The exception happen when?

2012/10/15 George Christman <gc...@cardaddy.com>

> Hello everyone, I'm working on my new search page which uses tapestry query
> parameters. The query parameters are dynamically set from a select menu. So
> far it seems to be working, however I do not know how to clear the query
> parameter from the url when the select menu is set to blank. I end up
> getting a null pointer exception. Below is my code. btw, if anybody sees
> any
> room for performance modifications, feel free to comment. This is very new
> to me. Thanks
>
>
> <html t:type="layout"
> xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd"
> xmlns:p="tapestry:parameter" pageTitle="Used Cars For Sale in region goes
> here">
>    <br/><br/><br/><br/>
>     <t:Form t:id="searchForm">
>         <t:Select t:id="searchYear" value="vehicleYear"
> model="yearSearchModel"/>
>         <t:Select t:id="searchMake" value="vehicleMake"
> model="makeSearchModel"/>
>         <t:Select t:id="searchModel" value="vehicleModel"
> model="modelSearchModel"/>
>         <t:Submit/>
>     </t:Form>
>
>     <t:Loop source="vehicles" value="vehicle">
>         <t:PageLink page="used_car_for_sale"
> context="vehicle.id">${vehicle.year} ${vehicle.make} ${vehicle.model}
> ${vehicle.trimLevel}</t:PageLink><br/>
>     </t:Loop>
> </html>
>
>
>
> public class UsedCarsForSale {
>
>     @ActivationRequestParameter(value = "year")
>     private String year;
>     @ActivationRequestParameter(value = "make")
>     private String make;
>     @ActivationRequestParameter(value = "model")
>     private String model;
>
>     @Property
>     private VehicleYear vehicleYear;
>     @Property
>     private VehicleMake vehicleMake;
>     @Property
>     private VehicleModel vehicleModel;
>
>     @Inject
>     private YearDAO yearDAO;
>     @Inject
>     private MakeDAO makeDAO;
>     @Inject
>     private ModelDAO modelDAO;
>
>     @Inject
>     private SelectModelFactory selectModelFactory;
>     @Property
>     private Vehicle vehicle;
>
>     @Inject
>     private Session session;
>
>     @Inject
>     private PageRenderLinkSource pageRenderLinkSource;
>
>     void onPrepareFromSearchForm() {
>         System.out.println(year);
>         if(this.year != null) {
>             this.vehicleYear = this.yearDAO.find(year);
>         }
>         if(this.make != null) {
>             this.vehicleMake = this.makeDAO.find(make);
>         }
>         if(this.model != null) {
>             this.vehicleModel = this.modelDAO.find(model);
>         }
>     }
>
>     Object onSuccess() {
>         this.year = vehicleYear.getName();
>         this.make = vehicleMake.getName();
>         this.model = vehicleModel.getName();
>         return pageRenderLinkSource.createPageRenderLink(this.getClass());
>     }
>
>     public List<Vehicle> getVehicles() {
>         Criteria criteria = this.session.createCriteria(Vehicle.class);
>         criteria.createAlias("vehicleYear", "vehicleYear");
>         criteria.createAlias("vehicleMake", "vehicleMake");
>         criteria.createAlias("vehicleModel", "vehicleModel");
>
>         if (year != null) {
>             criteria.add(Restrictions.eq("vehicleYear.name", year));
>         }
>         if (make != null) {
>             criteria.add(Restrictions.eq("vehicleMake.name",
> make).ignoreCase());
>         }
>         if (model != null) {
>             criteria.add(Restrictions.eq("vehicleModel.name",
> model).ignoreCase());
>         }
>
>         return criteria.list();
>     }
>
>     public SelectModel getYearSearchModel() {
>         return this.selectModelFactory.create(this.yearDAO.findAll(),
> "name");
>     }
>
>     public SelectModel getMakeSearchModel() {
>         return this.selectModelFactory.create(this.makeDAO.findAll(),
> "name");
>     }
>
>     public SelectModel getModelSearchModel() {
>         return this.selectModelFactory.create(this.modelDAO.findAll(),
> "name");
>     }
>
> }
>
>
>
>
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/How-to-remove-query-parmeter-from-url-string-tp5716922.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>