You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Lance Java <la...@googlemail.com> on 2013/01/22 18:51:15 UTC

form method="GET"

I have a search form in my application and I'd like to use a <form
method="GET"> since the form does not change serverside state. This is
perfectly legal in normal (non-tapestry) HTML.

The tapestry form component (and related field components) require that the
form submits via "POST" and also causes a redirect-after-post. Does anyone
have a solution to use a <form method="GET"> but still benefit from the
field bindings / validation etc that tapestry provides?

I'm trying to avoid flash persistance at all cost. I'm currently considering
client persistence or a complex onActivate / onPassivate pair but I'd prefer
a simple <form method="GET" />

Suggestions welcome.




--
View this message in context: http://tapestry.1045711.n5.nabble.com/form-method-GET-tp5719423.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: form method="GET"

Posted by Lance Java <la...@googlemail.com>.
I'd be very surprised if a mixin would work. Tapestry's form is hard-coded to
require post

Form.java
=======
    private void executeStoredActions()
    {
        String[] values = request.getParameters(FORM_DATA);

        if (!request.getMethod().equals("POST") || values == null)
            throw new
RuntimeException(messages.format("core-invalid-form-request", FORM_DATA));



--
View this message in context: http://tapestry.1045711.n5.nabble.com/form-method-GET-tp5719423p5719440.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: form method="GET"

Posted by Lance Java <la...@googlemail.com>.
Alejandro, you mentioned @ActivationRequestParameter which I was confusing
with @PageActivationContext which you can only have one of. I think I can
get it to work with multiple @ActivationRequestParameter for each filter
field.

Thanks.

I'm still of the opinion that tapestry should support <form method="GET" />
as it's a valid use-case. Google uses a "GET" for search.



--
View this message in context: http://tapestry.1045711.n5.nabble.com/form-method-GET-tp5719423p5719443.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: form method="GET"

Posted by Lance Java <la...@googlemail.com>.
You're right... the hidden field would be ugly in the URL. I can get by with
@ActivationRequestParamater or @PageActivationContext and some form of
BeanValueEncoder.



--
View this message in context: http://tapestry.1045711.n5.nabble.com/form-method-GET-tp5719423p5719469.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: form method="GET"

Posted by trsvax <tr...@gmail.com>.
I did some testing and while I can see a reason to support GET, I think
the way forms currently work make @ActivationRequestParamater along
with the redirect a better choice because Tapestry uses a hidden field
to map the form data to the Java parameters and I don't think you want
that in the URL. The only real drawback to POST this is the 302 redirect but 
also happens on event links. If you don't care about bookmarks you can
use a zone which eleminates the need for the redirect. 

That's the way i've implemented bookmarkable no session searches and
it seems easy enough. In your case having a filter object complicates things
a bit because you have to move data in a out of the filter object but you 
could create a ValueEncoder for that.



--
View this message in context: http://tapestry.1045711.n5.nabble.com/form-method-GET-tp5719423p5719461.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: form method="GET"

Posted by Lance Java <la...@googlemail.com>.
The fact that I have mentioned two of the biggest sites on the internet,
google and ebay, using <form method="GET" /> flags to me that this should be
supported in tapestry. Should I file a jira for this or is it a conscious
decision made in tapestry to NOT support "GET"?

To clarify, I think that tapestry should redirect-after-post if the method
is "POST", or it should continue with the response for "GET" (similar to how
errors work).



--
View this message in context: http://tapestry.1045711.n5.nabble.com/form-method-GET-tp5719423p5719447.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: form method="GET"

Posted by Lance Java <la...@googlemail.com>.
I'm trying to avoid session creation (ie flash persistance). At the moment, a
session is only created at login but users can perform a search without
being logged in.

In eBay, for instance, I can see the advanced search is backed by a <form
method="GET" />



--
View this message in context: http://tapestry.1045711.n5.nabble.com/form-method-GET-tp5719423p5719446.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: form method="GET"

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Wed, 23 Jan 2013 08:53:42 -0200, Lance Java <la...@googlemail.com>  
wrote:

> As I mentioned in my original post, I could use onActivate / onPassivate
> which is equivalent to @ActivationRequestParameter but I would prefer  
> <form method="GET" />.

Why? You have a lot of fields, so you'll end up with a long, ugly URL, and  
some browsers (specially IE) have low maximum URL length limits.

-- 
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: form method="GET"

Posted by Lance Java <la...@googlemail.com>.
Hi Alejandro, my search is an advanced search and has much more than a simple
"q" parameter. I have fields for category, query, location, min price, max
price etc etc etc. I have encapsulated all of these fields into a bean named
SearchFilter.

As I mentioned in my original post, I could use onActivate / onPassivate
which is equivalent to @ActivationRequestParameter but I would prefer <form
method="GET" />.







--
View this message in context: http://tapestry.1045711.n5.nabble.com/form-method-GET-tp5719423p5719441.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: form method="GET"

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

Can you tell us more about what are you trying to achieve with using
the GET method?

If you are after bookmarkability and persistence after refresh then I
think that @ActivationRequestParameter is a good option, as Barry
said.

My approach is to do the filtering during the setupRender and I don't
use the same property for the request parameter and the form field.
Something like this:

@ActivationRequestParameter
private String q;

@Property
private String qField;

@SetupRender
void setup()
{
    source = new HibernateGridDataSource(session, beanType)
    {
        protected void applyAdditionalConstraints(Criteria crit)
        {
            if (q != null && !q.isEmpty()) {
// filter your criteria in here...
            }
        }
    };
}


@OnEvent(EventConstants.SUCCESS)
void search()
{
    q = qField;
}


I hope it helps.
Cheers.
Alejandro.


On Wed, Jan 23, 2013 at 3:00 AM, trsvax <tr...@gmail.com> wrote:
> I'd write a mixin that just changes the method from POST to GET on the form
> element. You might need to put in a different URL if Tapestry gets confused
> about the form URL being a GET. Then just attach that mixin to the form
> component. I've thought about this for searches but I just put
> @ActivationRequestParameter on the values for the form inputs. The only
> drawback is the extra redirect after the POST.
>
>
>
> --
> View this message in context: http://tapestry.1045711.n5.nabble.com/form-method-GET-tp5719423p5719433.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: form method="GET"

Posted by trsvax <tr...@gmail.com>.
I'd write a mixin that just changes the method from POST to GET on the form
element. You might need to put in a different URL if Tapestry gets confused
about the form URL being a GET. Then just attach that mixin to the form
component. I've thought about this for searches but I just put
@ActivationRequestParameter on the values for the form inputs. The only
drawback is the extra redirect after the POST.



--
View this message in context: http://tapestry.1045711.n5.nabble.com/form-method-GET-tp5719423p5719433.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