Do wee need to implement NavigationHandler?

Isn't it easyer to implement navigate(String viewId) method and call it near 
the end of an action method:

public String anActionMethod() {
   ....
   MyFacesUtil.navigate("/foo.jsp");
   return null;
}

This is my try:

    public static void navigate(String viewId) {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        ViewHandler viewHandler = 
facesContext.getApplication().getViewHandler();
        UIViewRoot viewRoot = viewHandler.createView(facesContext, viewId);
        facesContext.setViewRoot(viewRoot);
        facesContext.renderResponse();
    }

    public static void navigateRedirect(String viewId, String queryString) {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        ExternalContext externalContext = facesContext.getExternalContext();
        ViewHandler viewHandler = 
facesContext.getApplication().getViewHandler();
        String redirectPath = viewHandler.getActionURL(facesContext,viewId);
        if (queryString != null) {
            redirectPath = redirectPath + '?' + queryString;
        }        
        try {
            
externalContext.redirect(externalContext.encodeActionURL(redirectPath));
        } catch (IOException e) {
            throw new FacesException(e);
        }
        facesContext.responseComplete();
    }


----- Original Message ----- 
From: "Mike Kienenberger" <[EMAIL PROTECTED]>
To: "MyFaces Discussion" <[email protected]>; "hicham abassi" <[EMAIL 
PROTECTED]>
Sent: Tuesday, September 27, 2005 5:16 PM
Subject: Re: Question about dynamic navigation actions


This is the default way to do it.

However, you can write your own
javax.faces.application.NavigationHandler to handle things differently
if you don't like the default navigation (for example, you could
return the name of the page to load directly).

On 9/27/05, hicham abassi <[EMAIL PROTECTED]> wrote:
> Hi,
>
> How do you handle your navigation when you webapp can have many many views ?
> Is there a another way to avoid declaring views into faces-config.xml ?
> What's you dynamic way fot that purpose ?
>
> Thanks.
>
>
>
>
> --
>
> hicham ABASSI
> [EMAIL PROTECTED]
>

Reply via email to