This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
how can we use <jsp:scriptlet /> tag in jspx file.
when I am using scriplet in my jspx file I am getting "The content of elements must consist of well-formed character data or markup. " error.
the reason behind this is: In my project I am using facelets so it doesnt understand what jsp:scriptlet tag means.
like I cant even use hx tags too. if I want to use hx tags in jspx file with facelets, I need to define it in taglib.xml file. I succesfully did that and working fine. In the same way to use jsp tags in my jspx file I need to define it in xml file for that I need the jsp tags tld file, which I am unable to find, could any one help me solving this problem. where can I get that tld file or the jar file in which this tld file is defined.
how can we use <jsp:scriptlet /> tag in jspx file.
Actually, I recommend that you don't.
There are 2 reasons, one technical, one ideological.
The technical reason is that scriptlets often don't have sufficient awareness of what JSF is doing on the page (and vice versa), and the results are often unfortunate.
The ideological reason is that JSF is a Model/View/Controller framework, and when you use scriptlets, you're usually adding non-view attributes to a View, which muddies the design of the program and makes it harder to understand and maintain.
JSF comes with iterative (datatable) and conditional ('rendered=') constructs that are sufficient to manage most conditional display requirements. What they can't do is usually something that should be controlled by back-end logic. That's true whether you're using Facelets or not.
An IDE is no substitute for an Intelligent Developer.
Thanks for your response.
the reason why I am asking this questions is, I want to invalidate session in the jsp file and close it.
I mean when I click exit button in any page it will come to close.jspx page where I should invalidate session and close the jspx file.
I invalidated session in the previous page and called close.jspx file, If I do this way when close.jspx file is loaded session is created automatically.
to avoid this I want to invalidate session in the closing page itself.
so please explain me how can I solve this problem.
Well, if what you're talking about is the usual "Log Out" button, what I normally do is attach the command button to a bean with an action method that invokes session.invalidate().
Then I return a navigation string that routes me to a page that has a "You have been logged out" message on it.
If that page doesn't reference any JSF managed beans in session scope, there will not be a session at that point and no session will be created as long as the user doesn't bring up a page with session-scope bean references.
yeah, I did the same way
I invalidate the session in the current page and routed my page to a new jspx file only to close it with empty body.
but still a new session is created. I dont know atually whats happening there.
my close.jspx file is:
and closewindow() script method will close the page.
yes your right. butwhat happening here is I am invalidating the session in one page(backing bean) and routing to another page. so here when a new request is initiated a new session is created.(to be more clear when ever a new request is initiated my authentication filter will be invoked and checks for the availability of session. creates one if not there).
so I tried all the available solutions. what I can do is only to invalidate session in jspx file itself and close the window.
but somehow I couldnt do it.
I think you're fighting it too hard. Just to begin with, it's generally considered rude to go closing web browser primary windows, since a browser app session is something that runs within a browser that may be used before, after, or even in parallel with sessions to other web apps on other servers and even in other countries. About the only case where that would be considered proper is if you're setting up a kiosk-style system where the browser isn't supposed to be working outside of the selected application.
Closing pop-up windows is somewhat more forgivable, except that a lot of people thing pop-ups are pretty rude themselves. I have my browser set to open them as new tabs, instead, so things occasionally get confusing when pop-ups are involved.
JSF has a clearly-defined lifecycle, and that includes when the FacesServlet will instantiate beans (and thereby possible create HttpSessions). As far as I can determine, there is no time after the execute Action phase that's going to construct session objects. In fact, JSF itself would have done any construction before the action processor is invoked, so the only way to construct a session object from that point onwards would be if your action processor did a getSession(true). If you did a session.invalidate, the session would be gone.
When you start talking servlet filters, that's another matter, but none of the standard JSF infrastructure interacts with servlet filters in ways that invalidate what I just described. What your servlet filter does depends on what you set it up to do.
the window what I am closing is a popup window. but one thing I found from your response is getting the session using getSession(true), but I getting the session using getSession(false).
and one more thing is it was the requirement that I should open my JSF project using a link from other project and that to it should open in a new tab.
that why when ever they want to close the jsf project user will click exit button and the tab should be closed automatically after invalidating the session and control will be focused to the previous tab where user can again click the JSF project. as session is invalidated a new request is initiated so the data before clicking the exit button will be flushed away.