How to set default home while developing jsf applications - jsf

I am developing a jsf application, and my application is already on the production environment. But there is something i want to know: if my domain name is: "mydomain.com" and in my application the home page is: "home.jsf", i would like my application to display the home page directly when i visit: www.mydomain.com
But what is happening now is to get my home page to display, i must write: www.mydomain.com/home.jsf . This seems to me very tedious.
Does anyone know a way to do this?

Just mention the welcome file in your web.xml as follows:
<welcome-file-list>
<welcome-file>home.jsf</welcome-file>
</welcome-file-list>

As far as JSF is concern, adding a simple welcome file wont produce good result. In addition to home.xhtml file, create an empty home.jsf file.. the server will not run the empty file (home.jsf) , wherelse it will proceed with home.xhtml. Then declare the welcome file in web.xml. for more have a look at this answer https://stackoverflow.com/a/4618142/839393

Related

XPages Resource Servlet

my xPages app (with oneUI theme set) works perfect when I use e.g. this URL:
https://testserver.xxxx.xxxx.com/app_folder/Home.xsp
and then our Domino admin mapped it to a new URL
https://myApp.xxxx.xxxx.com
that by default opens Home.xsp page
but now I see several UI issues - some icons/images are not shown, some controls displayed incorrectly.
What could cause this problem? It's the same Domino server but just two different ways to log in. Is it something related to "XPages Resource Servlet" configuration? Where can I check it?
For example. I have an image on xPage that has following resource:
"../../oneuiv2/images/sortDescending.png"
then when I log in through https://myApp.xxxx.xxxx.com - it doesn't show the image...
OK, then I replaced it with:
"/.ibmxspres/domino/oneuiv2/images/sortDescending.png"
same result.
but this works:
"/.ibmxspres/global/theme/oneui/images/sortDescending.gif"
I can replace all images/icons with new resource URLs but anyway other standard controls are not shown correctly..
Based on our short discussion your problem is in wrong URLs.
So why one URL works and the other one doesn't? Concatenation, in my opinion. Browser, JS frameworks (DOJO) and JS programmers in general tend to use either relative URLs or cut/concatenate URL string. This my result into URL that is not understandable by server.
In your case check URL mapping made by your admin - does it apply to all URL formats used by XPages? Are those transformed URLs accessible on server (enter them in URL bar of browser)? That is the key to get your XPage working.
OK.. it's fixed. The problem was in Virtual Server Mapping document.
Names.nsf -> Web -> Web Configuration -> Virtual Server -> Mapping tab...
we had to set
HTML directory: domino\html
which was
HTML directory: /myappdbname.nsf
instead

Java ee session/conversation/view timeout redirection

My environment is: NetBeans7.2.1, GlassFish3.1, JSF2 and Weld 1.1.0.
I'm trying to redirect to an error page in one of these cases ( session/conversation/view timeout ).
From what I read there are number of options:
Using <error-page> inside web.xml (but for some reason when I use location with error.xhtml page it's not working, only with a servlet - asked this question about this issue).
Using <exception-handler-factory> inside faces-config.xml which will use a CustomExceptionHandler like in this example.
Using a #WebFilter like in this example.
My main problem is that after I'm redirecting to error.xhtml page I want to disable going back to previous pages. so even if the user clickes on the back button he will still be redirected to the error page.
I was able to redirect to an error page when an exception accourd , but was not able to clear the cache so when the user goes back he still can see the previous page content.
I don't fully understand what are the diffrances between the 3 options above, and exactly what is the role of each option.
Can someone please explain ?
what is the diffrence between
NavigationHandler nav = fc.getApplication().getNavigationHandler();
nav.handleNavigation(fc, null, "/error");
facesContext.renderResponse();
and
((HttpServletResponse)response).sendRedirect("yourCustomJSF.jsf"); ?
How can I handle these exceptions by redirecting and clearing the cache so that the user will not be able to see previous page ?
Thank's In Advance.
You can use this for handle expired session/view:
<error-page>
<exception-type>javax.faces.application.ViewExpiredException</exception-type>
<location>/index.jsf</location>
</error-page>
My main problem is that after I'm redirecting to error.xhtml page I want to disable going back to previous pages. so even if the user clickes on the back button he will still be redirected to the error page
to do this use a filter to not cache the page and send the request to the server instead
see this to get the code of filter
https://stackoverflow.com/a/19034603/2422368

Changing welcome file location results in deployment failure

I am getting below error.
FAIL - Application at context path /sampleJSF could not be started
I want to change my welcome file location. I have a index.jsp page at WEB-INF/pages/index.jsp. How can I modify servlet mapping and welcome file list to achive this?
Here is my servlet-mapping and welcome-file-list from web.xml.
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>WEB-INF/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>WEB-INF/pages/index.jsp</welcome-file>
</welcome-file-list>
It look like that you misunderstood the purpose of both the welcome file setting and the /WEB-INF folder.
The welcome file must represent the name of the file which the server should serve from the current folder when a folder is been requested instead of a file in URL. E.g. /, /foo/, /bar/, etc. So, when you set it to index.jsp, then it will serve /index.jsp when / is requested, and /foo/index.jsp when /foo/ is requested, etc.
The /WEB-INF folder is for files which shouldn't be independently publicly accessible. For example, include files, template files, error files, tag files, configuration files, etcetera. Mapping the Faces Servlet on /WEB-INF makes no utter sense as the servlet container already restricts direct (public) access to /WEB-INF folder when the enduser purposefully enters the /WEB-INF folder in the URL.
Undo all those changes you made on the sample web application. They make simply no sense. Whatever functional requirement you had in mind for which you incorrectly thought that this is the right solution must be solved differently.
Unrelated to the concrete problem, it look like that you're just getting started with JSF, but do you know that JSP is deprecated since JSF 2.0 in 2009? Are you absolutely positive that you're learning JSF based on the right and up to date resources? I strongly recommend to do so, or you will end up having confusion headache and code disaster. Start at our JSF wiki page.

glassfish: redirect all url to index

I'm working on the java ee application using glassfish 3 server and jsf.
I want all of requests to urls starting from my context root to be redirected to my index.xhtml.
For example, if a user types:
my-host/my-app-context-root/lgsfdjglksjdflgjldskfjg-anything
I want this request to be redirected to:
my-host/my-app-context-root/index.xhtml
So I want to know how can I implement this rule. If it's possible, I would like to do it somehow using Java/jsf or web.xml or some other files which belongs to my application only. I want to avoid to do any "general" server configurations, such as setting properties "redirect_n" as it is suggested there.
Thanks in advance and sorry for my English.
You could create a servlet filter with mapping "/*". Then use HttpServletRequest#getRequestURI() to check whether this is a request for js/css files or any other request and you can accordingly redirect to index.xhtml.
One solution would be to use a servlet with / in web.xml. This servlet would Act as the Default servlet for your application and could output the content of index.xhtml.

how to create a link to a JSF page from outside the application

I am working with a JSF application that posts on every mouse click, so if you get 5 pages deep, your url stays the same.
now i need to link to one of these pages from outside of jsf. what can i do?
(i am new to jsf)
Navigation rules use forward by default, that's why the URL does not change.
Use http://site.com/ctx/page.jsf to access a given page. *.jsf is the mapping of your faces servlet to in web.xml (it can have different value in your configuration, but normally it is *.jsf or /faces/*
i dont know if ive got it right but as much as i understood it you need to use GET instead of POST this time, right?
in my current project we still use JSF 1.2 and that is achieved by PrettyFaces (http://ocpsoft.com/prettyfaces/) by us. do you mean that?

Resources