You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Erik Weber <er...@mindspring.com> on 2004/07/23 04:34:27 UTC

Portability & extension vs path mapping

I choose to use path mapping, but it's not always my decision, so I'm 
trying to generate some hyperlinks in such a way as to make them 
completely portable, whether path mapping or extension mapping is used.

Let's say I have a hyperlink to the action that is mapped to 
"/actor/viewsearch".

If I use this construct, where controllerPath is equal to whatever would 
cause the controller servlet to be invoked, say "/control":

<html:link page="${controllerPath}/actor/viewsearch">

I have complete success when path mapping is used. Let's say someone 
maps the controller to "/", I just set controllerPath to "", and it 
still works. Also, it still works whether the application itself has a 
named context or is in the default context.

Now, let's say we switch to extension mapping. Now the controller 
servlet is invoked by "*.do". I set my controllerPath variable again to 
be "", and all works great, except for one thing.

When you set the action parameter to html:form to "/actor/viewsearch", 
the html:form tag properly appends the .do suffix to this, making the 
action URI "/actor/viewsearch.do" -- the way it should be. However, the 
above html:link tag does not do this. So I would need to manually go 
through and change that hyperlink to 
"${controllerPath}/actor/viewsearch.do". If the extension was changed, 
my hyperlink would need to change again.

I have a feeling I am missing something here. I tried fiddling with the 
action attribute to html:link, rather than the page attribute, but that 
didn't seem to do it. . . . . Or am I thinking about extension mapping 
the wrong way?


Erik

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


Re: Portability & extension vs path mapping

Posted by Erik Weber <er...@mindspring.com>.
Obviously in the example below, since we are talking about extension 
mapping here, the "controllerPath" variable is set to the empty string.

Just wanted to avoid any confusion.

Erik



Erik Weber wrote:

> Craig, this is exactly what I was looking for, except, I need 
> html:rewrite instead of html:link, because many hyperlinks are 
> unfortunately embedded in JavaScript functions. Any suggestions?
>
> I can't quite figure out html:rewrite. The docs (1.1) seem to explain 
> that it works exactly like html:link, leading me to believe that the 
> "action" parameter is acceptable. This is from the html:rewrite 
> section of struts-html.html, in the entry for the "href" attribute:
>
> "You must specify exactly one of the action attribute, the forward 
> attribute, the href attribute, or the page attribute."
>
> But when I try to use the "action" attribute, I get this error:
>
> Attribute action invalid for tag rewrite according to TLD
>
>
> I also notice that the rewrite section of that doc, despite that quote 
> above, has no entry for the "action" attribute as the html:link 
> section does. I am using html-el if that makes a difference. Perhaps 
> this is a bug, and the "action" parameter should be available to 
> html:rewrite as well as html:link? I haven't dug into the tld yet . . .
>
> This is my JavaScript syntax:
>
> location='<html:rewrite action="${controllerPath}/actor/usecase"/>'
>
> Again, this works with html:link.
>
> Any thoughts on that?
>
>
> Thanks,
> Erik
>
>
>
>
> Craig McClanahan wrote:
>
>> On Fri, 23 Jul 2004 15:36:34 -0400, Erik Weber 
>> <er...@mindspring.com> wrote:
>>
>>
>>> Ah, you're probably right, the path mappings might not need to change
>>> very often, but on the other hand, I thought, if the html:form tag
>>> appends the (.do) extension for you, it isn't far-fetched to think that
>>> another tag would do the equivalent for hyperlinks.
>>>
>>>
>>
>> According to the documentation,
>>
>> <link ... action="/foo" ... />
>>
>> should do what you want (i.e. hyperlink to action "/foo", no matter
>> which mapping you are using). Doesn't that work?
>>
>>
>>
>>> Erik
>>>
>>
>> Craig
>>
>> ---------------------------------------------------------------------
>> 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
>
>

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


Re: Portability & extension vs path mapping

Posted by Erik Weber <er...@mindspring.com>.
Thanks Niall, I will appreciate having that.

Erik



Niall Pemberton wrote:

>The "action" attribute has only been available in Struts since version
>1.2.0 - so if you want it either switch to Struts 1.2.1 beta version or wait
>for the next Struts release - hopefully that isn't too far away - talk on
>the dev list is for a vote on Monday.
>
>I did update the docs in CVS recently to indicate "since 1.2.0" for the
>action attribute, but I didn't refresh the web site.
>
>Niall
>
>----- Original Message ----- 
>From: "Erik Weber" <er...@mindspring.com>
>To: "Struts Users Mailing List" <us...@struts.apache.org>
>Sent: Saturday, July 24, 2004 12:15 AM
>Subject: Re: Portability & extension vs path mapping
>
>
>  
>
>>Craig, this is exactly what I was looking for, except, I need
>>html:rewrite instead of html:link, because many hyperlinks are
>>unfortunately embedded in JavaScript functions. Any suggestions?
>>
>>I can't quite figure out html:rewrite. The docs (1.1) seem to explain
>>that it works exactly like html:link, leading me to believe that the
>>"action" parameter is acceptable. This is from the html:rewrite section
>>of struts-html.html, in the entry for the "href" attribute:
>>
>>"You must specify exactly one of the action attribute, the forward
>>attribute, the href attribute, or the page attribute."
>>
>>But when I try to use the "action" attribute, I get this error:
>>
>>Attribute action invalid for tag rewrite according to TLD
>>
>>
>>I also notice that the rewrite section of that doc, despite that quote
>>above, has no entry for the "action" attribute as the html:link section
>>does. I am using html-el if that makes a difference. Perhaps this is a
>>bug, and the "action" parameter should be available to html:rewrite as
>>well as html:link? I haven't dug into the tld yet . . .
>>
>>This is my JavaScript syntax:
>>
>>location='<html:rewrite action="${controllerPath}/actor/usecase"/>'
>>
>>Again, this works with html:link.
>>
>>Any thoughts on that?
>>
>>
>>Thanks,
>>Erik
>>
>>
>>
>>
>>Craig McClanahan wrote:
>>
>>    
>>
>>>On Fri, 23 Jul 2004 15:36:34 -0400, Erik Weber <er...@mindspring.com>
>>>      
>>>
>wrote:
>  
>
>>>      
>>>
>>>>Ah, you're probably right, the path mappings might not need to change
>>>>very often, but on the other hand, I thought, if the html:form tag
>>>>appends the (.do) extension for you, it isn't far-fetched to think that
>>>>another tag would do the equivalent for hyperlinks.
>>>>
>>>>
>>>>
>>>>        
>>>>
>>>According to the documentation,
>>>
>>> <link ... action="/foo" ... />
>>>
>>>should do what you want (i.e. hyperlink to action "/foo", no matter
>>>which mapping you are using).  Doesn't that work?
>>>
>>>
>>>
>>>      
>>>
>>>>Erik
>>>>
>>>>
>>>>        
>>>>
>>>Craig
>>>
>>>---------------------------------------------------------------------
>>>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
>>
>>
>>
>>    
>>
>
>
>
>---------------------------------------------------------------------
>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: Portability & extension vs path mapping

Posted by Niall Pemberton <ni...@blueyonder.co.uk>.
The "action" attribute has only been available in Struts since version
1.2.0 - so if you want it either switch to Struts 1.2.1 beta version or wait
for the next Struts release - hopefully that isn't too far away - talk on
the dev list is for a vote on Monday.

I did update the docs in CVS recently to indicate "since 1.2.0" for the
action attribute, but I didn't refresh the web site.

Niall

----- Original Message ----- 
From: "Erik Weber" <er...@mindspring.com>
To: "Struts Users Mailing List" <us...@struts.apache.org>
Sent: Saturday, July 24, 2004 12:15 AM
Subject: Re: Portability & extension vs path mapping


> Craig, this is exactly what I was looking for, except, I need
> html:rewrite instead of html:link, because many hyperlinks are
> unfortunately embedded in JavaScript functions. Any suggestions?
>
> I can't quite figure out html:rewrite. The docs (1.1) seem to explain
> that it works exactly like html:link, leading me to believe that the
> "action" parameter is acceptable. This is from the html:rewrite section
> of struts-html.html, in the entry for the "href" attribute:
>
> "You must specify exactly one of the action attribute, the forward
> attribute, the href attribute, or the page attribute."
>
> But when I try to use the "action" attribute, I get this error:
>
> Attribute action invalid for tag rewrite according to TLD
>
>
> I also notice that the rewrite section of that doc, despite that quote
> above, has no entry for the "action" attribute as the html:link section
> does. I am using html-el if that makes a difference. Perhaps this is a
> bug, and the "action" parameter should be available to html:rewrite as
> well as html:link? I haven't dug into the tld yet . . .
>
> This is my JavaScript syntax:
>
> location='<html:rewrite action="${controllerPath}/actor/usecase"/>'
>
> Again, this works with html:link.
>
> Any thoughts on that?
>
>
> Thanks,
> Erik
>
>
>
>
> Craig McClanahan wrote:
>
> >On Fri, 23 Jul 2004 15:36:34 -0400, Erik Weber <er...@mindspring.com>
wrote:
> >
> >
> >>Ah, you're probably right, the path mappings might not need to change
> >>very often, but on the other hand, I thought, if the html:form tag
> >>appends the (.do) extension for you, it isn't far-fetched to think that
> >>another tag would do the equivalent for hyperlinks.
> >>
> >>
> >>
> >
> >According to the documentation,
> >
> >  <link ... action="/foo" ... />
> >
> >should do what you want (i.e. hyperlink to action "/foo", no matter
> >which mapping you are using).  Doesn't that work?
> >
> >
> >
> >>Erik
> >>
> >>
> >
> >Craig
> >
> >---------------------------------------------------------------------
> >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
>
>
>



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


Re: Portability & extension vs path mapping

Posted by Erik Weber <er...@mindspring.com>.
Craig, this is exactly what I was looking for, except, I need 
html:rewrite instead of html:link, because many hyperlinks are 
unfortunately embedded in JavaScript functions. Any suggestions?

I can't quite figure out html:rewrite. The docs (1.1) seem to explain 
that it works exactly like html:link, leading me to believe that the 
"action" parameter is acceptable. This is from the html:rewrite section 
of struts-html.html, in the entry for the "href" attribute:

"You must specify exactly one of the action attribute, the forward 
attribute, the href attribute, or the page attribute."

But when I try to use the "action" attribute, I get this error:

Attribute action invalid for tag rewrite according to TLD


I also notice that the rewrite section of that doc, despite that quote 
above, has no entry for the "action" attribute as the html:link section 
does. I am using html-el if that makes a difference. Perhaps this is a 
bug, and the "action" parameter should be available to html:rewrite as 
well as html:link? I haven't dug into the tld yet . . .

This is my JavaScript syntax:

location='<html:rewrite action="${controllerPath}/actor/usecase"/>'

Again, this works with html:link.

Any thoughts on that?


Thanks,
Erik




Craig McClanahan wrote:

>On Fri, 23 Jul 2004 15:36:34 -0400, Erik Weber <er...@mindspring.com> wrote:
>  
>
>>Ah, you're probably right, the path mappings might not need to change
>>very often, but on the other hand, I thought, if the html:form tag
>>appends the (.do) extension for you, it isn't far-fetched to think that
>>another tag would do the equivalent for hyperlinks.
>>
>>    
>>
>
>According to the documentation,
>
>  <link ... action="/foo" ... />
>
>should do what you want (i.e. hyperlink to action "/foo", no matter
>which mapping you are using).  Doesn't that work?
>
>  
>
>>Erik
>>    
>>
>
>Craig
>
>---------------------------------------------------------------------
>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: Portability & extension vs path mapping

Posted by Craig McClanahan <cr...@gmail.com>.
On Fri, 23 Jul 2004 15:36:34 -0400, Erik Weber <er...@mindspring.com> wrote:
> Ah, you're probably right, the path mappings might not need to change
> very often, but on the other hand, I thought, if the html:form tag
> appends the (.do) extension for you, it isn't far-fetched to think that
> another tag would do the equivalent for hyperlinks.
> 

According to the documentation,

  <link ... action="/foo" ... />

should do what you want (i.e. hyperlink to action "/foo", no matter
which mapping you are using).  Doesn't that work?

> Erik

Craig

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


Re: Portability & extension vs path mapping

Posted by Erik Weber <er...@mindspring.com>.
Ah, you're probably right, the path mappings might not need to change 
very often, but on the other hand, I thought, if the html:form tag 
appends the (.do) extension for you, it isn't far-fetched to think that 
another tag would do the equivalent for hyperlinks.

Erik



Rick Reumann wrote:

> Erik Weber wrote:
>
>> I have a feeling I am missing something here. I tried fiddling with 
>> the action attribute to html:link, rather than the page attribute, 
>> but that didn't seem to do it. . . . . Or am I thinking about 
>> extension mapping the wrong way?
>
>
> Why not just always use the mapping /do/* then it won't matter if you 
> decide later to use an extension or not. You'll still have to put the 
> /do/ in your links though (and not in your form defintion). I'm still 
> a bit confused though why would your mapping to what calls the Struts 
> ActionServlet need to change? If you really think it will change that 
> much I guess you could create your own tag to create links that would 
> append or prepend the appropriate mapping to the link. I've just never 
> really run into a case where someone has really wanted to change the 
> mapping prefix/suffix.
>

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


Re: Portability & extension vs path mapping

Posted by Rick Reumann <st...@reumann.net>.
Erik Weber wrote:

> I have a feeling I am missing something here. I tried fiddling with the 
> action attribute to html:link, rather than the page attribute, but that 
> didn't seem to do it. . . . . Or am I thinking about extension mapping 
> the wrong way?

Why not just always use the mapping /do/* then it won't matter if you 
decide later to use an extension or not. You'll still have to put the 
/do/ in your links though (and not in your form defintion). I'm still a 
bit confused though why would your mapping to what calls the Struts 
ActionServlet need to change? If you really think it will change that 
much I guess you could create your own tag to create links that would 
append or prepend the appropriate mapping to the link. I've just never 
really run into a case where someone has really wanted to change the 
mapping prefix/suffix.

-- 
Rick

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