You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Eric Jain <Er...@isb-sib.ch> on 2004/06/03 12:25:32 UTC

Override form action URL

I have:

<html:form action="/search" method="get">
   <html:text property="query"/>
   <html:hidden property="dataset" value="a"/>
<html:form>

which generates:

<form name="form" action="/test/search" method="get">
   <input type="text" name="query">
   <input type="hidden" name="dataset" value="a">
</form>

This works, but I would like to avoid exposing the action URL and return
this instead:

<form name="form" action="/test/a/" method="get">
   <input type="text" name="query">
</form>

There is a servlet filter that will internally forward '/test/a/' to
'/test/search?dataset=a'.

An obvious solution would be:

<form action="/test/a/" method="get">
   <html:text property="query"/>
<form>

Unfortunately this does not work as the html:text tag looks for a scoped
attribute that is set by the html:form tag.

Is there an alternative to html:form, that sets the same attributes,
but does not print anything?

<html:action action="/search">
   <form action="/test/a/" method="get">
     <html:text property="query"/>
   <form>
</html:action>

Or could the generated action URL be overridden somehow?

<html:form action="/search" url="/test/a/" method="get">
   <html:text property="query"/>
<html:form>

There must be a way...



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


Re: Override form action URL

Posted by Niall Pemberton <ni...@blueyonder.co.uk>.
Assuming you could do this, how then does struts know when you submit to
"/test/a/" what action to run and for what reason "would like to avoid
exposing the action URL"?

Niall

----- Original Message ----- 
From: "Eric Jain" <Er...@isb-sib.ch>
To: <us...@struts.apache.org>
Sent: Thursday, June 03, 2004 11:25 AM
Subject: Override form action URL


> I have:
>
> <html:form action="/search" method="get">
>    <html:text property="query"/>
>    <html:hidden property="dataset" value="a"/>
> <html:form>
>
> which generates:
>
> <form name="form" action="/test/search" method="get">
>    <input type="text" name="query">
>    <input type="hidden" name="dataset" value="a">
> </form>
>
> This works, but I would like to avoid exposing the action URL and return
> this instead:
>
> <form name="form" action="/test/a/" method="get">
>    <input type="text" name="query">
> </form>
>
> There is a servlet filter that will internally forward '/test/a/' to
> '/test/search?dataset=a'.
>
> An obvious solution would be:
>
> <form action="/test/a/" method="get">
>    <html:text property="query"/>
> <form>
>
> Unfortunately this does not work as the html:text tag looks for a scoped
> attribute that is set by the html:form tag.
>
> Is there an alternative to html:form, that sets the same attributes,
> but does not print anything?
>
> <html:action action="/search">
>    <form action="/test/a/" method="get">
>      <html:text property="query"/>
>    <form>
> </html:action>
>
> Or could the generated action URL be overridden somehow?
>
> <html:form action="/search" url="/test/a/" method="get">
>    <html:text property="query"/>
> <html:form>
>
> There must be a way...
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


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


Re: Override form action URL

Posted by Niall Pemberton <ni...@blueyonder.co.uk>.
Its context relative...from the user guide...

"action - Use the value of this attribute as the name of a Action to be
looked up, and use the module-relative or context-relative URI found there.
"

http://jakarta.apache.org/struts/userGuide/struts-html.html#link

Niall

----- Original Message ----- 
From: "Eric Jain" <Er...@isb-sib.ch>
To: "Struts Users Mailing List" <us...@struts.apache.org>
Sent: Thursday, June 03, 2004 3:20 PM
Subject: Re: Override form action URL


> > If so you can define a dummy action to which your form points. In the
> > dummy just forward to your actual action. In the rendered jsp/html page
> > you will see the dummy action.
>
> Thanks, unfortunately the example I gave was somewhat simplified. I'd
> rather avoid having to configure dozens of dummy actions. Furthermore,
> Struts will insist that actions mapped to nested paths be put in their
> own subapplications. And finally, the following mapping would not be
> possible:
>
>    /test/a/ -> /test/search?dataset=a
>    /test/a/1 -> /test/retrieve?id=1
>
> In the end, as far as I can see, all I need is a way to override the URL
> that is generated by the html:form tag. I just opened a feature request,
> see http://issues.apache.org/bugzilla/show_bug.cgi?id=29363.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


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


Re: Override form action URL

Posted by Eric Jain <Er...@isb-sib.ch>.
> If so you can define a dummy action to which your form points. In the 
> dummy just forward to your actual action. In the rendered jsp/html page 
> you will see the dummy action.

Thanks, unfortunately the example I gave was somewhat simplified. I'd 
rather avoid having to configure dozens of dummy actions. Furthermore, 
Struts will insist that actions mapped to nested paths be put in their 
own subapplications. And finally, the following mapping would not be 
possible:

   /test/a/ -> /test/search?dataset=a
   /test/a/1 -> /test/retrieve?id=1

In the end, as far as I can see, all I need is a way to override the URL 
that is generated by the html:form tag. I just opened a feature request, 
see http://issues.apache.org/bugzilla/show_bug.cgi?id=29363.

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


Re: Override form action URL

Posted by br...@tcs.com.
I donot know whether I have understood this properly but are you trying to 
mask your actual action mapping?
If so you can define a dummy action to which your form points. In the 
dummy just forward to your actual action. In the rendered jsp/html page 
you will see the dummy action.

Brati Sankar Ghosh
Tata Consultancy Services
Mailto: brati.sankarghosh@tcs.com
Website: http://www.tcs.com



Eric Jain <Er...@isb-sib.ch> 
06/03/2004 03:55 PM

Please respond to
"Struts Users Mailing List" <us...@struts.apache.org>


To
user@struts.apache.org
cc

Subject
Override form action URL






I have:

<html:form action="/search" method="get">
   <html:text property="query"/>
   <html:hidden property="dataset" value="a"/>
<html:form>

which generates:

<form name="form" action="/test/search" method="get">
   <input type="text" name="query">
   <input type="hidden" name="dataset" value="a">
</form>

This works, but I would like to avoid exposing the action URL and return
this instead:

<form name="form" action="/test/a/" method="get">
   <input type="text" name="query">
</form>

There is a servlet filter that will internally forward '/test/a/' to
'/test/search?dataset=a'.

An obvious solution would be:

<form action="/test/a/" method="get">
   <html:text property="query"/>
<form>

Unfortunately this does not work as the html:text tag looks for a scoped
attribute that is set by the html:form tag.

Is there an alternative to html:form, that sets the same attributes,
but does not print anything?

<html:action action="/search">
   <form action="/test/a/" method="get">
     <html:text property="query"/>
   <form>
</html:action>

Or could the generated action URL be overridden somehow?

<html:form action="/search" url="/test/a/" method="get">
   <html:text property="query"/>
<html:form>

There must be a way...



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


ForwardSourceID:NT0000A926