JSF 2.0 implicit navigation, different views

浪子不回头ぞ 提交于 2020-01-13 10:58:23

问题


I'm looking for a good explanation to JSF 2.0 implicit navigation and how it works with views. To be more precise, I understand that from an action method I can return a string which is the outcome of the action. If there's a JSF view whose file name matches the outcome, then this is implicit navigation.

Now... my question, what if the action is invoked from a view that's inside a folder but the view that I want to navigate to next is in a different folder? I.e., from /manager/edit.xhtml an action is invoked. What String should that action return so that navigation can safely go to /user/list.xhtml or to /index.xhtml or to /manager/index.xhtml?


回答1:


As far as my knowledge goes, JSF looks for a matching view only within the current context. You probably have to define a navigation rule in your faces-config.xml to handle an outcome in a special way. Here is an example:

<navigation-rule>
        <from-view-id>/profiles/viewkeypages.xhtml</from-view-id>
        <navigation-case>
            <from-outcome>editkeypage</from-outcome>
            <to-view-id>/users/editkeypage.xhtml</to-view-id>
            <redirect />
        </navigation-case>      
</navigation-rule>

-Praveen.




回答2:


You can use implicit navigation to get to views in other folders.

Just do something like this in a view:

<h:link value="Move" outcome="#{request.contextPath}/users/editkeypage.xhtml?faces-redirect=true" />

or

<h:link value="Move" outcome="/users/editkeypage.xhtml?faces-redirect=true" />


来源:https://stackoverflow.com/questions/5545557/jsf-2-0-implicit-navigation-different-views

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!