1

I have a JSF 1.2 based Servlet. Am doing session invalidation if a user stays idle for some time. I have to show a Jquery dialog box to user 1 minute before session invalidation happens and ask if the user wants to continue or logout.

I have the code for Jquery dialog box in a xhtml page (session.xhtml). I have nearly 15-20 pages in my web application. A user can remain idle in any of those 15-20 pages. So, I need to include session.xhtml page in all of my xhtml pages. Am doing this by using below piece of code in all of my pages.

<ui:insert>
<ui:include src="/session.xhtml" />
</ui:insert>

I have 2 problems here.

a) As the number of page grows in my web application, I need to keep on adding above code to each page

b) Code maintainability : Down the line, if some one else has to develop some pages in my web application, he may not remember to include the above code

So, the question is, is there any way in which I can put this page (say some where in web.xml or some xml files) by which by default this session.xhtml will be available to all pages in my web application?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Vikas V
  • 3,176
  • 2
  • 37
  • 60
  • What exactly is a "JSF 1.2 based servlet"? This phrase in the beginning of your question makes no utter sense. JSF has only one [servlet](http://stackoverflow.com/tags/servlets/info), the `FacesServlet`, which is the front controller. You as developer should usually be writing views (JSP/XHTML files) and models (backing bean classes) only. – BalusC Oct 17 '12 at 20:17
  • Related: http://stackoverflow.com/questions/4792862/how-to-include-another-xhtml-in-xhtml-using-jsf-2-0-facelets – BalusC Oct 17 '12 at 20:17
  • @BalusC What I meant by "JSF 1.2 based servlet" is, my application is a Servlet and not a Portlet. Now if my application is a Portlet I would have solved it using Portal features. For eg., lets take Liferay Portal. Instead of including my xhtml page in all of my other xhtml pages, I can include this in the Theme of Liferay. $theme.runtime("SessionWar"). Since Theme gets applied to all wars(and all pages inside war) I dont have to bother about including my Session Idle monitor code in each individual xhtml page. I just wanted to be specific about my question because I had this answer in my mind – Vikas V Oct 18 '12 at 03:56
  • @BalusC And the link which you have suggested, I have indeed used . Kindly again go through the 2 problems I have mentioned in my question. And kindly also refer to the solution I have put in my comment above which talks about using Portal features. Now, I cannot definitely use that solution for a Servlet as there is no Portal Theme there. So, am looking for a way through JSF. Hope am clear now with my question and "JSF 1.2 based servlet" phrase :) – Vikas V Oct 18 '12 at 04:04
  • @BalusC Your comments on this..? – Vikas V Oct 24 '12 at 03:32
  • Sorry, portlets is beyond me, so I'm not sure what you're talking about. – BalusC Oct 24 '12 at 10:13

1 Answers1

1

The view file may have a template (which is a good practice):

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:a="http://richfaces.org/a4j"
                ...
                template="../layout/maintemplate.xhtml">

you may put common logic into maintemplate.xhtml. hope this helps.

nigi
  • 136
  • 5
  • Your solution is better than what I have mentioned in my post. Instead of writing 3 lines of code your solution requires 1 line of code. But, problem still exists. That 1 line of code has to be put in all xhtml pages. I was looking for a way of putting that page in some faces-config.xml or web.xml (Am not sure) which will get applied to all xhtml pages. Let me know if a solution can be found out in that direction. – Vikas V Oct 11 '12 at 03:53