Skip to main content

JSF - Change views directory

2 replies [Last post]
jmail22
Offline
Joined: 2010-05-17
Points: 0

Hi everyone!

I am new to Java Server Faces. I would like to ask about something what is very anoing for me.

Let's take a look at my project dirs (I am developing app with NetBeans 6.8 JSF 2.0 Hibernate)

Source Packages
|
Libraries
|
WebPages
__WEB-INF
__|
__resources
__|
__template.xhtml
__index.html

Nothing more is needed.

I've go the managedbean

settingsController

in which I've go the method index. this method should return String with template (index) name. And if it returns "index" everything is ok, but... I would like to change location for views. After my operation my project tree should looks like:

Source Packages
|
Libraries
|
WebPages
__WEB-INF
__|
__resources
__|
__templates
____|
____settings
______|
______index.html
______template.xhtml
template.xhtml
index.html

I am trying to put the views in seperate directory for each controller. I have tried to return template with directory like this:

public String index(){
return "templates/settings/index";
}

but this returns me an error

Unable to find matching navigation case with from-view-id '/index.xhtml' for action '#{settingsController.index}' with outcome 'settings/index'

Can anyone explain me how to make this working? Just for example for two cases: settings/index and user/changePass

I'll be very grateful.

Best regards

jmail

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
mpscholz
Offline
Joined: 2003-06-12
Points: 0

With your index() method, the navigation handler of JSF will first add the same extension to the string as the current page has and look for the resulting resource.
I strongly suspect that the current page has an ".[b]x[/b]html" extension, so the resulting relative address for implicit navigation will be "templates/settings/index.[b]x[/b]html" in your case (mind the [b]x[/b]!).
As your listing suggests, no index.[b]x[/b]html file exists, though (only a index.html file).
Hence, next the handler will try to find a navigation case that maps to the outcome "templates/settings/index", which most likely (and correctly) will not exist.

Either use a logical outcome string and create a navigation case in your faces-config.xml or keep on using implicit navigation and rename index.html to index.[b]x[/b]html.

jmail22
Offline
Joined: 2010-05-17
Points: 0

That's my man!!!!

Thank you thank you thank you.

The days of creeping have just finished :D

once again thank you thank you :D

very best regards

jmail