导航规则导致 JSF1064:无法找到或提供资源 [英] navigation rule causes JSF1064: Unable to find or serve resource

查看:19
本文介绍了导航规则导致 JSF1064:无法找到或提供资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下 xhtml 页面,它包含在我项目中其他页面的主要部分中:

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>

这是我写的导航规则:

<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>

这就是提到的 Bean:

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);
}    
}

错误如下:JSF1064:无法找到或提供资源,/protected/personal/searchingResults.xhtml.

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}

我不明白问题是关于导航规则还是下一个 xhtml 页面.

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

推荐答案

如果 JSF 找不到匹配的导航规则,就会发生这种情况.然后它将切换到隐式导航.IE.结果将用作相对于当前上下文的实际视图 ID.

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.

显然当前视图 ID 位于 /protected/personal 中的某个位置.searchingResults 的结果与任何导航规则都不匹配,然后将触发到 /protected/personal/searchingResults.xhtml 的隐式导航.

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.

你有两个选择:

  1. 修复当前视图 ID.<from-view-id>/Components/TopBar.xhtml</from-view-id> 显然是错误的.您可以通过以下方式找到正确的:

  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());

只要您不使用 POST 进行页面到页面导航,它通常与浏览器地址栏中的上下文相关 URI 匹配.在 <from-view-id> 中使用此值.

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>.

完全摆脱导航案例并依赖隐式导航.从 faces-config.xml 中完全删除 并更改结果值和操作方法,如下所示:

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;
}

NavigationHandler 方法也相当笨拙.即使使用导航案例,也只需直接返回结果,而不是摆弄 NavigationHandler.

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

另见:

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆