问题描述
我有以下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:
@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
.
您有2个选择:
-
修复当前视图ID.
<from-view-id>/Components/TopBar.xhtml</from-view-id>
显然是错误的.您可以找到正确的一个,如下所示:
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
中完全删除<navigation-case>
,并更改结果值和操作方法,如下所示:
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
.
另请参见:
- JSF 2中的通信-隐式导航
- 重定向和导航/转发和何时使用什么有什么区别?
- action和actionListener之间的差异
- Communication in JSF 2 - Implicit Navigation
- What is the difference between redirect and navigation/forward and when to use what?
- Differences between action and actionListener
See also:
这篇关于导航规则导致JSF1064:无法找到或提供资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!