Quantcast

[Tools] Possible to check StrutsLinkTool for an existing "forward"

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[Tools] Possible to check StrutsLinkTool for an existing "forward"

Christopher Schultz-2
All,

I've been using StrutsLinkTool with Struts 1.x for a very long time, and
I'm surprised this is the first time this has come up.

I'd like to check for the existence of a forward definition and, if it
exists, use it. Otherwise, I'd like to fall-back to a default.
Basically, I'm taking a Velocity template that is used in a bunch of
places to do one thing, and make it so that I can post a form to a
different (new) action in certain cases.

Normally, I'd do something like this:

#if($link.forward('maybe-exists'))
  <form action="$link.forward('maybe-exists')">
#else
  <form action="$link.forward('same-old-action')">
#end

Unfortunately, the $link.forward('maybe-exists'} will throw an error in
the cases that "maybe-exists" doesn't actually exist. Hence, my desire
to check for the existence of the forward declaration.

Is anything like that possible with the current 2.0 tools build? Can
anyone suggest an alternative without tossing something into the
Velocity context to act as a flag?

Thanks,
-chris


signature.asc (924 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Tools] Possible to check StrutsLinkTool for an existing "forward"

Mike Kienenberger
I'd do it by subclassing StrutsLinkTool and adding a custom method
that calls setForward() and returns true or false based on whether
there was an exception thrown.

You could also create a unique tool if you didn't want to subclass
StrutsLinkTool, but subclassing StrutsLinkTool is how I handled custom
struts link tool behavior.  Just redefine "link" to point to your
subclass in the toolbox.xml file.




On Mon, Jan 30, 2017 at 7:38 PM, Christopher Schultz
<[hidden email]> wrote:

> All,
>
> I've been using StrutsLinkTool with Struts 1.x for a very long time, and
> I'm surprised this is the first time this has come up.
>
> I'd like to check for the existence of a forward definition and, if it
> exists, use it. Otherwise, I'd like to fall-back to a default.
> Basically, I'm taking a Velocity template that is used in a bunch of
> places to do one thing, and make it so that I can post a form to a
> different (new) action in certain cases.
>
> Normally, I'd do something like this:
>
> #if($link.forward('maybe-exists'))
>   <form action="$link.forward('maybe-exists')">
> #else
>   <form action="$link.forward('same-old-action')">
> #end
>
> Unfortunately, the $link.forward('maybe-exists'} will throw an error in
> the cases that "maybe-exists" doesn't actually exist. Hence, my desire
> to check for the existence of the forward declaration.
>
> Is anything like that possible with the current 2.0 tools build? Can
> anyone suggest an alternative without tossing something into the
> Velocity context to act as a flag?
>
> Thanks,
> -chris
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Loading...