You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Chris Pratt <th...@gmail.com> on 2009/01/07 01:56:18 UTC

Getting an URL for an Action

I'm trying to turn an action name into an URL from within another action.
I've tried:

UrlHelper.buildUrl("action-name",request,response,null)

Which seems to just return "action-name".  And I've tried:

UrlHelper.buildUrl("/action-name",request,response,null)

Which returns "/context/action-name", which is a little closer, but still
isn't the full, working URL.

What am I missing?
  (*Chris*)

Re: Getting an URL for an Action

Posted by Musachy Barroso <mu...@gmail.com>.
I totally misunderstood your last statement :)

musachy

On Wed, Jan 7, 2009 at 1:14 PM, Musachy Barroso <mu...@gmail.com> wrote:
> It is not a sin, we are suggesting alternatives, based on the fact
> that there is not built in way of doing what you are asking.
>
> musahcy
>
> On Wed, Jan 7, 2009 at 1:05 PM, Chris Pratt <th...@gmail.com> wrote:
>> In this case it has to do with the fact that we're using Tiles to ensure
>> that we get a consistent look for all our emails.  Basically I've created a
>> Tiles Layout that constructs the emails using tiles to include the
>> text/plain and text/html versions of the content and using action properties
>> to control to, from, cc, bcc, subject and the attachments.  I guess I'm
>> confused as to why it's a sin to ask the system for information it obviously
>> has to have?
>>  (*Chris*)
>>
>> On Wed, Jan 7, 2009 at 9:58 AM, Musachy Barroso <mu...@gmail.com> wrote:
>>
>>> If the MIME Emails are generated by tags, why don't you build the URL
>>> in the jsps?
>>>
>>> musachy
>>>
>>> On Wed, Jan 7, 2009 at 12:45 PM, Chris Pratt <th...@gmail.com>
>>> wrote:
>>> > Basically, I have some tried and true tag libraries for generating
>>> pretty,
>>> > MIME Emails that work great with Struts.  They support all manner of
>>> > attachments and have worked great for years.  Occasionally I need to
>>> attach
>>> > something (in this case a PDF) that is generated by another action.  So
>>> the
>>> > main action needs to have a property that returns a list of things to be
>>> > attached, which in this case is a URL to the Action that generates the
>>> > dynamic PDF.
>>> >
>>> > I'm sure there's a way to refactor all this into some unrecognizable
>>> form,
>>> > but this is tried and true, supports JSP and Tiles including properly
>>> > formatted, pretty HTML and plain text MIME emails, and really I can't see
>>> > any reason that this should be precluded from working with any system
>>> that
>>> > supports JSP Tag Libraries.
>>> >
>>> > Can you see a better way to get the generated attachment into the email?
>>> >  (*Chris*)
>>> >
>>> > On Wed, Jan 7, 2009 at 9:23 AM, Dave Newton <ne...@yahoo.com>
>>> wrote:
>>> >
>>> >> Chris Pratt wrote:
>>> >>
>>> >>> Strange?  I would have thought this was a fairly commonly needed
>>> feature
>>> >>>
>>> >>
>>> >> I've never needed to generate a URL from an action name within another
>>> >> action across a half-dozen S2 apps--it can't be *that* common... I think
>>> the
>>> >> most hackish thing I've done like that is to use an action name as a
>>> dynamic
>>> >> result parameter for a "redirectAction" result type.
>>> >>
>>> >> IMO actions should "never" generate a URL since they're supposed to be
>>> >> decoupled from the underlying action access mechanism. What's your use
>>> case
>>> >> that this solves?
>>> >>
>>> >> Dave
>>> >>
>>> >>
>>> >>
>>> >> ---------------------------------------------------------------------
>>> >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> >> For additional commands, e-mail: user-help@struts.apache.org
>>> >>
>>> >>
>>> >
>>>
>>>
>>>
>>> --
>>> "Hey you! Would you help me to carry the stone?" Pink Floyd
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>>>
>>
>
>
>
> --
> "Hey you! Would you help me to carry the stone?" Pink Floyd
>



-- 
"Hey you! Would you help me to carry the stone?" Pink Floyd

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


Re: Getting an URL for an Action

Posted by Musachy Barroso <mu...@gmail.com>.
It is not a sin, we are suggesting alternatives, based on the fact
that there is not built in way of doing what you are asking.

musahcy

On Wed, Jan 7, 2009 at 1:05 PM, Chris Pratt <th...@gmail.com> wrote:
> In this case it has to do with the fact that we're using Tiles to ensure
> that we get a consistent look for all our emails.  Basically I've created a
> Tiles Layout that constructs the emails using tiles to include the
> text/plain and text/html versions of the content and using action properties
> to control to, from, cc, bcc, subject and the attachments.  I guess I'm
> confused as to why it's a sin to ask the system for information it obviously
> has to have?
>  (*Chris*)
>
> On Wed, Jan 7, 2009 at 9:58 AM, Musachy Barroso <mu...@gmail.com> wrote:
>
>> If the MIME Emails are generated by tags, why don't you build the URL
>> in the jsps?
>>
>> musachy
>>
>> On Wed, Jan 7, 2009 at 12:45 PM, Chris Pratt <th...@gmail.com>
>> wrote:
>> > Basically, I have some tried and true tag libraries for generating
>> pretty,
>> > MIME Emails that work great with Struts.  They support all manner of
>> > attachments and have worked great for years.  Occasionally I need to
>> attach
>> > something (in this case a PDF) that is generated by another action.  So
>> the
>> > main action needs to have a property that returns a list of things to be
>> > attached, which in this case is a URL to the Action that generates the
>> > dynamic PDF.
>> >
>> > I'm sure there's a way to refactor all this into some unrecognizable
>> form,
>> > but this is tried and true, supports JSP and Tiles including properly
>> > formatted, pretty HTML and plain text MIME emails, and really I can't see
>> > any reason that this should be precluded from working with any system
>> that
>> > supports JSP Tag Libraries.
>> >
>> > Can you see a better way to get the generated attachment into the email?
>> >  (*Chris*)
>> >
>> > On Wed, Jan 7, 2009 at 9:23 AM, Dave Newton <ne...@yahoo.com>
>> wrote:
>> >
>> >> Chris Pratt wrote:
>> >>
>> >>> Strange?  I would have thought this was a fairly commonly needed
>> feature
>> >>>
>> >>
>> >> I've never needed to generate a URL from an action name within another
>> >> action across a half-dozen S2 apps--it can't be *that* common... I think
>> the
>> >> most hackish thing I've done like that is to use an action name as a
>> dynamic
>> >> result parameter for a "redirectAction" result type.
>> >>
>> >> IMO actions should "never" generate a URL since they're supposed to be
>> >> decoupled from the underlying action access mechanism. What's your use
>> case
>> >> that this solves?
>> >>
>> >> Dave
>> >>
>> >>
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> >> For additional commands, e-mail: user-help@struts.apache.org
>> >>
>> >>
>> >
>>
>>
>>
>> --
>> "Hey you! Would you help me to carry the stone?" Pink Floyd
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>



-- 
"Hey you! Would you help me to carry the stone?" Pink Floyd

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


Re: Getting an URL for an Action

Posted by Chris Pratt <th...@gmail.com>.
In this case it has to do with the fact that we're using Tiles to ensure
that we get a consistent look for all our emails.  Basically I've created a
Tiles Layout that constructs the emails using tiles to include the
text/plain and text/html versions of the content and using action properties
to control to, from, cc, bcc, subject and the attachments.  I guess I'm
confused as to why it's a sin to ask the system for information it obviously
has to have?
  (*Chris*)

On Wed, Jan 7, 2009 at 9:58 AM, Musachy Barroso <mu...@gmail.com> wrote:

> If the MIME Emails are generated by tags, why don't you build the URL
> in the jsps?
>
> musachy
>
> On Wed, Jan 7, 2009 at 12:45 PM, Chris Pratt <th...@gmail.com>
> wrote:
> > Basically, I have some tried and true tag libraries for generating
> pretty,
> > MIME Emails that work great with Struts.  They support all manner of
> > attachments and have worked great for years.  Occasionally I need to
> attach
> > something (in this case a PDF) that is generated by another action.  So
> the
> > main action needs to have a property that returns a list of things to be
> > attached, which in this case is a URL to the Action that generates the
> > dynamic PDF.
> >
> > I'm sure there's a way to refactor all this into some unrecognizable
> form,
> > but this is tried and true, supports JSP and Tiles including properly
> > formatted, pretty HTML and plain text MIME emails, and really I can't see
> > any reason that this should be precluded from working with any system
> that
> > supports JSP Tag Libraries.
> >
> > Can you see a better way to get the generated attachment into the email?
> >  (*Chris*)
> >
> > On Wed, Jan 7, 2009 at 9:23 AM, Dave Newton <ne...@yahoo.com>
> wrote:
> >
> >> Chris Pratt wrote:
> >>
> >>> Strange?  I would have thought this was a fairly commonly needed
> feature
> >>>
> >>
> >> I've never needed to generate a URL from an action name within another
> >> action across a half-dozen S2 apps--it can't be *that* common... I think
> the
> >> most hackish thing I've done like that is to use an action name as a
> dynamic
> >> result parameter for a "redirectAction" result type.
> >>
> >> IMO actions should "never" generate a URL since they're supposed to be
> >> decoupled from the underlying action access mechanism. What's your use
> case
> >> that this solves?
> >>
> >> Dave
> >>
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >> For additional commands, e-mail: user-help@struts.apache.org
> >>
> >>
> >
>
>
>
> --
> "Hey you! Would you help me to carry the stone?" Pink Floyd
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: Getting an URL for an Action

Posted by Musachy Barroso <mu...@gmail.com>.
If the MIME Emails are generated by tags, why don't you build the URL
in the jsps?

musachy

On Wed, Jan 7, 2009 at 12:45 PM, Chris Pratt <th...@gmail.com> wrote:
> Basically, I have some tried and true tag libraries for generating pretty,
> MIME Emails that work great with Struts.  They support all manner of
> attachments and have worked great for years.  Occasionally I need to attach
> something (in this case a PDF) that is generated by another action.  So the
> main action needs to have a property that returns a list of things to be
> attached, which in this case is a URL to the Action that generates the
> dynamic PDF.
>
> I'm sure there's a way to refactor all this into some unrecognizable form,
> but this is tried and true, supports JSP and Tiles including properly
> formatted, pretty HTML and plain text MIME emails, and really I can't see
> any reason that this should be precluded from working with any system that
> supports JSP Tag Libraries.
>
> Can you see a better way to get the generated attachment into the email?
>  (*Chris*)
>
> On Wed, Jan 7, 2009 at 9:23 AM, Dave Newton <ne...@yahoo.com> wrote:
>
>> Chris Pratt wrote:
>>
>>> Strange?  I would have thought this was a fairly commonly needed feature
>>>
>>
>> I've never needed to generate a URL from an action name within another
>> action across a half-dozen S2 apps--it can't be *that* common... I think the
>> most hackish thing I've done like that is to use an action name as a dynamic
>> result parameter for a "redirectAction" result type.
>>
>> IMO actions should "never" generate a URL since they're supposed to be
>> decoupled from the underlying action access mechanism. What's your use case
>> that this solves?
>>
>> Dave
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>



-- 
"Hey you! Would you help me to carry the stone?" Pink Floyd

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


Re: Getting an URL for an Action

Posted by Greg Lindholm <gl...@yahoo.com>.
I have a similar use case which I think would be very common:
It's the "forgot password" case.
When a user has forgotten there password and wants it reset 
we send them an email with a URL link to the reset action that includes 
the security parameters.
We have to construct (i.e. hack together) the URL in an action.

It would be nice it there was a helper utility to do this.


Chris Pratt wrote:
> 
> Basically, I have some tried and true tag libraries for generating pretty,
> MIME Emails that work great with Struts.  They support all manner of
> attachments and have worked great for years.  Occasionally I need to
> attach
> something (in this case a PDF) that is generated by another action.  So
> the
> main action needs to have a property that returns a list of things to be
> attached, which in this case is a URL to the Action that generates the
> dynamic PDF.
> 
> I'm sure there's a way to refactor all this into some unrecognizable form,
> but this is tried and true, supports JSP and Tiles including properly
> formatted, pretty HTML and plain text MIME emails, and really I can't see
> any reason that this should be precluded from working with any system that
> supports JSP Tag Libraries.
> 
> Can you see a better way to get the generated attachment into the email?
>   (*Chris*)
> 
> On Wed, Jan 7, 2009 at 9:23 AM, Dave Newton <ne...@yahoo.com> wrote:
> 
>> Chris Pratt wrote:
>>
>>> Strange?  I would have thought this was a fairly commonly needed feature
>>>
>>
>> I've never needed to generate a URL from an action name within another
>> action across a half-dozen S2 apps--it can't be *that* common... I think
>> the
>> most hackish thing I've done like that is to use an action name as a
>> dynamic
>> result parameter for a "redirectAction" result type.
>>
>> IMO actions should "never" generate a URL since they're supposed to be
>> decoupled from the underlying action access mechanism. What's your use
>> case
>> that this solves?
>>
>> Dave
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/Getting-an-URL-for-an-Action-tp21322853p21355940.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: Getting an URL for an Action

Posted by Chris Pratt <th...@gmail.com>.
Basically, I have some tried and true tag libraries for generating pretty,
MIME Emails that work great with Struts.  They support all manner of
attachments and have worked great for years.  Occasionally I need to attach
something (in this case a PDF) that is generated by another action.  So the
main action needs to have a property that returns a list of things to be
attached, which in this case is a URL to the Action that generates the
dynamic PDF.

I'm sure there's a way to refactor all this into some unrecognizable form,
but this is tried and true, supports JSP and Tiles including properly
formatted, pretty HTML and plain text MIME emails, and really I can't see
any reason that this should be precluded from working with any system that
supports JSP Tag Libraries.

Can you see a better way to get the generated attachment into the email?
  (*Chris*)

On Wed, Jan 7, 2009 at 9:23 AM, Dave Newton <ne...@yahoo.com> wrote:

> Chris Pratt wrote:
>
>> Strange?  I would have thought this was a fairly commonly needed feature
>>
>
> I've never needed to generate a URL from an action name within another
> action across a half-dozen S2 apps--it can't be *that* common... I think the
> most hackish thing I've done like that is to use an action name as a dynamic
> result parameter for a "redirectAction" result type.
>
> IMO actions should "never" generate a URL since they're supposed to be
> decoupled from the underlying action access mechanism. What's your use case
> that this solves?
>
> Dave
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: Getting an URL for an Action

Posted by Dave Newton <ne...@yahoo.com>.
Chris Pratt wrote:
> Strange?  I would have thought this was a fairly commonly needed feature

I've never needed to generate a URL from an action name within another 
action across a half-dozen S2 apps--it can't be *that* common... I think 
the most hackish thing I've done like that is to use an action name as a 
dynamic result parameter for a "redirectAction" result type.

IMO actions should "never" generate a URL since they're supposed to be 
decoupled from the underlying action access mechanism. What's your use 
case that this solves?

Dave


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


Re: Getting an URL for an Action

Posted by Chris Pratt <th...@gmail.com>.
Strange?  I would have thought this was a fairly commonly needed feature and
the code in ServletUrlRenderer has a lot of hoops to jump through to make
something seemingly simple work.  Thanks for your help, I guess I'll just
have to hard code it for now.
  (*Chris*)

On Wed, Jan 7, 2009 at 5:46 AM, Musachy Barroso <mu...@gmail.com> wrote:

> hum, there is no right way after all. If you end up using UrlHelper,
> take a look at how it is used in ServletUrlRenderer:renderFormUrl,
> different methods are used depending on whether an action mapping was
> found or not.
>
> musachy
>
> On Wed, Jan 7, 2009 at 12:00 AM, Chris Pratt <th...@gmail.com>
> wrote:
> > Is there a right way to do it?
> >  (*Chris*)
> >
> > On Tue, Jan 6, 2009 at 5:24 PM, Musachy Barroso <mu...@gmail.com>
> wrote:
> >
> >> I wouldn't advise you to use UrlHelper, given that Struts 2 doesn't
> >> have an API, that class can change without warning (it does from time
> >> to time)
> >>
> >> musachy
> >>
> >> On Tue, Jan 6, 2009 at 7:56 PM, Chris Pratt <th...@gmail.com>
> >> wrote:
> >> > I'm trying to turn an action name into an URL from within another
> action.
> >> > I've tried:
> >> >
> >> > UrlHelper.buildUrl("action-name",request,response,null)
> >> >
> >> > Which seems to just return "action-name".  And I've tried:
> >> >
> >> > UrlHelper.buildUrl("/action-name",request,response,null)
> >> >
> >> > Which returns "/context/action-name", which is a little closer, but
> still
> >> > isn't the full, working URL.
> >> >
> >> > What am I missing?
> >> >  (*Chris*)
> >> >
> >>
> >>
> >>
> >> --
> >> "Hey you! Would you help me to carry the stone?" Pink Floyd
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >> For additional commands, e-mail: user-help@struts.apache.org
> >>
> >>
> >
>
>
>
> --
> "Hey you! Would you help me to carry the stone?" Pink Floyd
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: Getting an URL for an Action

Posted by Musachy Barroso <mu...@gmail.com>.
hum, there is no right way after all. If you end up using UrlHelper,
take a look at how it is used in ServletUrlRenderer:renderFormUrl,
different methods are used depending on whether an action mapping was
found or not.

musachy

On Wed, Jan 7, 2009 at 12:00 AM, Chris Pratt <th...@gmail.com> wrote:
> Is there a right way to do it?
>  (*Chris*)
>
> On Tue, Jan 6, 2009 at 5:24 PM, Musachy Barroso <mu...@gmail.com> wrote:
>
>> I wouldn't advise you to use UrlHelper, given that Struts 2 doesn't
>> have an API, that class can change without warning (it does from time
>> to time)
>>
>> musachy
>>
>> On Tue, Jan 6, 2009 at 7:56 PM, Chris Pratt <th...@gmail.com>
>> wrote:
>> > I'm trying to turn an action name into an URL from within another action.
>> > I've tried:
>> >
>> > UrlHelper.buildUrl("action-name",request,response,null)
>> >
>> > Which seems to just return "action-name".  And I've tried:
>> >
>> > UrlHelper.buildUrl("/action-name",request,response,null)
>> >
>> > Which returns "/context/action-name", which is a little closer, but still
>> > isn't the full, working URL.
>> >
>> > What am I missing?
>> >  (*Chris*)
>> >
>>
>>
>>
>> --
>> "Hey you! Would you help me to carry the stone?" Pink Floyd
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>



-- 
"Hey you! Would you help me to carry the stone?" Pink Floyd

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


Re: Getting an URL for an Action

Posted by Chris Pratt <th...@gmail.com>.
Is there a right way to do it?
  (*Chris*)

On Tue, Jan 6, 2009 at 5:24 PM, Musachy Barroso <mu...@gmail.com> wrote:

> I wouldn't advise you to use UrlHelper, given that Struts 2 doesn't
> have an API, that class can change without warning (it does from time
> to time)
>
> musachy
>
> On Tue, Jan 6, 2009 at 7:56 PM, Chris Pratt <th...@gmail.com>
> wrote:
> > I'm trying to turn an action name into an URL from within another action.
> > I've tried:
> >
> > UrlHelper.buildUrl("action-name",request,response,null)
> >
> > Which seems to just return "action-name".  And I've tried:
> >
> > UrlHelper.buildUrl("/action-name",request,response,null)
> >
> > Which returns "/context/action-name", which is a little closer, but still
> > isn't the full, working URL.
> >
> > What am I missing?
> >  (*Chris*)
> >
>
>
>
> --
> "Hey you! Would you help me to carry the stone?" Pink Floyd
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: Getting an URL for an Action

Posted by Musachy Barroso <mu...@gmail.com>.
I wouldn't advise you to use UrlHelper, given that Struts 2 doesn't
have an API, that class can change without warning (it does from time
to time)

musachy

On Tue, Jan 6, 2009 at 7:56 PM, Chris Pratt <th...@gmail.com> wrote:
> I'm trying to turn an action name into an URL from within another action.
> I've tried:
>
> UrlHelper.buildUrl("action-name",request,response,null)
>
> Which seems to just return "action-name".  And I've tried:
>
> UrlHelper.buildUrl("/action-name",request,response,null)
>
> Which returns "/context/action-name", which is a little closer, but still
> isn't the full, working URL.
>
> What am I missing?
>  (*Chris*)
>



-- 
"Hey you! Would you help me to carry the stone?" Pink Floyd

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