You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Dan Harmer <Ha...@ldschurch.org> on 2005/11/22 15:24:48 UTC

Anchors, navigation cases, and commandLinks/outputLinks

Greetings :) 
I'm trying to accomplish the following scenario and could use some assistance
from someone who's accomplished this seemingly simple task:
 
1) Click on a commandLink on a page
2) Execute code from method binding on commandLink that was just clicked
3) Navigate to a page (possibly the same page) AND SCROLL to an anchor listed
on the page
 
I've tried to accomplish this by having my method binding return a string value
which represents a unique navigation case that has a <to-view-id> of a URL with
an anchor appended on it such as this:
 
     <navigation-rule> 
        <navigation-case> 
            <from-outcome>anAction</from-outcome> 
          <to-view-id>/somePage.jsp#someAnchor</to-view-id> 
          <redirect/> 
        </navigation-case> 
    </navigation-rule> 
 
With an anchor on the page like this:
<f:verbatim><a name="</f:verbatim><h:outputText value="someAnchor"
/><f:verbatim>" /></f:verbatim>
 
This results in the application appending a .jsp extension to the end of the
<to-view-id> URL value (ex: /somePage.jsp#someAnchor.jsp) instead of just
/somePage.jsp#someAnchor
 
I've also tried wrapping a commandLink with an outputLink--hoping to somehow
fire both the navigation to the outputLink value along with the bean.methodName
code:
 
       <h:outputLink value="module.faces##someAnchor"><h:outputText value="Test
Link" />
           <h:commandLink action="#{bean.methodName}">
            <h:outputText value="Bean Backed Test Link"/>
       </h:outputLink>
 
The outputLink works just fine by itself; however, I need a bean method to fire
as well before the navigation takes place.  This seems like a simple task that
would be very common.  I would greatly appreciate some guidance from anyone who
has done this or accomplished the same desired outcome via different means or
techniques.  If this isn't possible, perhaps I should log it as a wish list item
in JIRA?  Thanks,
 
Dan



------------------------------------------------------------------------------
This message may contain confidential information, and is
intended only for the use of the individual(s) to whom it
is addressed.
------------------------------------------------------------------------------

Re: Anchors, navigation cases, and commandLinks/outputLinks

Posted by Mike Kienenberger <mk...@gmail.com>.
Don,

I don't know the answer to your question, which is why I haven't said
anything previously.

One possibility is to write your own renderer for commandLink.   Or
maybe it can be done by subclassing the NavigationManager.

Another possibility is that MyFaces has an "autoscroll" javascript tag option.
You can use it to scroll to the location of an existing submit button
(and maybe command link).  I've been unable to determine how to make
it scroll to an arbitrary component on the page, but my javascript is
very weak.   But perhaps you can specify the value of the autoscroll
parameter to force it to go to your anchor location.

You could also stick a parameter in the session or request as a flag,
and create a filter that rewrote the URL to append an anchor onto it
to run as a post-processor.   Kinda like the MyFaces extension filter
does to add javascript.

There's a few ideas, but I haven't investigated any of them.

On 11/22/05, Dan Harmer <Ha...@ldschurch.org> wrote:
>  Greetings :)
>
>
> I'm trying to accomplish the following scenario and could use some
> assistance from someone who's accomplished this seemingly simple task:
>
> 1) Click on a commandLink on a page
> 2) Execute code from method binding on commandLink that was just clicked
> 3) Navigate to a page (possibly the same page) AND SCROLL to an anchor
> listed on the page
>
> I've tried to accomplish this by having my method binding return a string
> value which represents a unique navigation case that has a <to-view-id> of a
> URL with an anchor appended on it such as this:
>
>      <navigation-rule>
>         <navigation-case>
>             <from-outcome>anAction</from-outcome>
>           <to-view-id>/somePage.jsp#someAnchor</to-view-id>
>           <redirect/>
>         </navigation-case>
>     </navigation-rule>
>
> With an anchor on the page like this:
> <f:verbatim><a name="</f:verbatim><h:outputText
> value="someAnchor" /><f:verbatim>" /></f:verbatim>
>
> This results in the application appending a .jsp extension to the end of the
> <to-view-id> URL value (ex: /somePage.jsp#someAnchor.jsp) instead of just
> /somePage.jsp#someAnchor
>
> I've also tried wrapping a commandLink with an outputLink--hoping to somehow
> fire both the navigation to the outputLink value along with the
> bean.methodName code:
>
>        <h:outputLink value="module.faces##someAnchor"><h:outputText
> value="Test Link" />
>            <h:commandLink action="#{bean.methodName}">
>             <h:outputText value="Bean Backed Test Link"/>
>        </h:outputLink>
>
> The outputLink works just fine by itself; however, I need a bean method to
> fire as well before the navigation takes place.  This seems like a simple
> task that would be very common.  I would greatly appreciate some guidance
> from anyone who has done this or accomplished the same desired outcome via
> different means or techniques.  If this isn't possible, perhaps I should log
> it as a wish list item in JIRA?  Thanks,
>
> Dan
>
>
> ------------------------------------------------------------------------------
>  This message may contain confidential information, and is
>  intended only for the use of the individual(s) to whom it
>  is addressed.
> ------------------------------------------------------------------------------
>