2

I've the following xhtml page, that is wrapped in the major part of the other pages in my project:

<ui:composition  xmlns="http://www.w3.org/1999/xhtml"
             xmlns:f="http://java.sun.com/jsf/core"
             xmlns:h="http://xmlns.jcp.org/jsf/html"
             xmlns:ui="http://java.sun.com/jsf/facelets"
             xmlns:p="http://primefaces.org/ui">
<h:head>
    <title></title>
</h:head>
<h:form>  
    <p:menubar>
        <p:menuitem value="Home" url="/protected/personal/HomeCalendar.xhtml" icon="ui-icon-home"/>
        <p:menuitem value="#{topbarBean.username}" url="#" style="text-decoration: underline" />
        <f:facet name="options">
            <p:inputText style="margin-right:20px" placeholder="Search"  value="#{searchBean.searched}"/>
            <p:commandButton action="#{searchBean.search()}" type="submit" icon="ui-icon-search" />
        </f:facet>
       </p:menubar>
</h:form>
</ui:composition>

This is the navigation rule that I've wrote:

<navigation-rule>
    <from-view-id>/Components/TopBar.xhtml</from-view-id>
    <navigation-case>
        <from-action>#{searchBean.search()}</from-action>
        <from-outcome>searchingResults</from-outcome>   
        <to-view-id>/protected/SearchResults.xhtml</to-view-id>
    </navigation-case>
</navigation-rule>

and this the referred Bean:

@RequestScoped
@ManagedBean
public class SearchBean implements Serializable {

private String searched;
private final String resultsOutcome = "searchingResults";
private List<User> users;
private List<Event> events;

@EJB
UserFacade uf;

@EJB
UserManager um;

@EJB
EventFacade ev;

@PostConstruct
public void init(){
    try {
        setEvents(um.getEventsVisibilityMasked(um.getLoggedUser().getId()));
    }
    catch (NotFoundException ex) { 
        Logger.getLogger(SearchBean.class.getName()).log(Level.SEVERE, null, ex);
    }
}

public void setSearched(String searched) {
    this.searched = searched;
}

public String getSearched() {
    return searched;
}


public void search() {
    FacesContext fc = FacesContext.getCurrentInstance();
    fc.getApplication().getNavigationHandler().handleNavigation(fc, null, resultsOutcome);
}

public List<User> getUsers(){
    return users;
}
public void setUsers(List<User> users){
    for(User user:users)
    this.users.add(user);
}

public List<Event> getEvents(){
    return events;
}
public void setEvents(List<Event> events){
    for(Event event:events)
    this.events.add(event);
}    
}

The error is the following one: JSF1064: Unable to find or serve resource, /protected/personal/searchingResults.xhtml.

This path is not specified anywhere, if it could be helpful I've the following structure :

-Index,xhtml
-Web Pages { components , protected}
-components{TopBar.xhtml}
-protected {event,persona,user,SearchResults.xhtml}
-event{eventCreate,eventPage,eventEdit}
-personal{HomeCalendar,ManageSettings,ManageInvitations}

I don't understand if the problem regards the navigation-rule or the next xhtml page.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
LNRD.CLL
  • 385
  • 1
  • 5
  • 19

1 Answers1

1

That can happen if JSF can't find the matching navigation rule. It'll then switch to implicit navigation. I.e. the outcome will be used as the actual view ID, relative to the current context.

Apparently the current view ID is sitting somewhere in /protected/personal. An outcome of searchingResults which doesn't match any navigation rule will then trigger an implicit navigation to /protected/personal/searchingResults.xhtml.

You've 2 options:

  1. Fix the current view ID. The <from-view-id>/Components/TopBar.xhtml</from-view-id> is apparently wrong. You can find out the right one as follows:

    System.out.println(FacesContext.getCurrentInstance().getViewRoot().getViewId());
    

    It's usually the one matching the context-relative URI in browser's address bar as long as you don't use POST for page-to-page navigation. Use this value in <from-view-id>.

  2. Get rid of navigation cases altogether and rely on implicit navigation. Remove the <navigation-case> altogether from faces-config.xml and change the outcome value and action method as below:

    private final String resultsOutcome = "/protected/SearchResults.xhtml";
    
    public String search() {
        return resultsOutcome;
    }
    

    The NavigationHandler approach was also quite clumsy. Even with navigation cases, just return the outcome outright instead of fiddling with NavigationHandler.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • ok I notice that there is something wrong, in my navigation rules I state from Index to Index according to registrationBean withOut:Index from Index to Error according to registrationBean withOut:Error from Index to HomeCalendar according to loginBean withOut:Success from Index to Error according to loginBean withOut:Error and the ones that i've posted before.The problem is that in the case of a Login even if the outcome is Success it doesn't load the HomeCalendar but in the URI on the browser there is still the Index path. – LNRD.CLL Jan 22 '15 at 17:43
  • My doubts about the previous problem is: which is the viewId for a ui:component? because it included in all the pages under /protected/* but I don't know if I've to put the URI for the specific component or for all the pages in which the component is wrapped. (the component in my project is the file TopBar.xhtml) I'm really grateful for your support!! – LNRD.CLL Jan 22 '15 at 17:44
  • You're mixing several concepts and terms. Navigation cases has got nothing to do with components (nor with includes/compositions). Perhaps the current page was being opened via a POST navigation (which is really really a bad practice). Print then the view ID as shown in the answer to get the right one. I suggest to take a pause and carefully read the "See also" links in bottom of the answer and also the "See also" ones in the linked answers. Last but not least I also suggest to go through a sane JSF book and practice some more before working on a new/existing JSF application. – BalusC Jan 22 '15 at 17:47
  • Hey, I solved the problem by using: FacesContext fc = FacesContext.getCurrentInstance(); fc.getApplication().getNavigationHandler().handleNavigation(fc, null, myCalendarOutcome); only in filters and I make navigation rules for these filters, moreover I've used implicit navigation all the time it's possible. Thanks for your help. – LNRD.CLL Jan 23 '15 at 13:33