File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes How can we use <jsp:scriptlet /> tag in jspx file that uses faclets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "How can we use <jsp:scriptlet /> tag in jspx file that uses faclets" Watch "How can we use <jsp:scriptlet /> tag in jspx file that uses faclets" New topic
Author

How can we use <jsp:scriptlet /> tag in jspx file that uses faclets

suresh dasari
Ranch Hand

Joined: Oct 05, 2009
Posts: 121

Hi,

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.

Any help is appreciated.


Sun Certified Java Programmer with 93 percent
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15641
    
  15


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.


Customer surveys are for companies who didn't pay proper attention to begin with.
suresh dasari
Ranch Hand

Joined: Oct 05, 2009
Posts: 121

Tim,

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.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15641
    
  15

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.
suresh dasari
Ranch Hand

Joined: Oct 05, 2009
Posts: 121

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:

<body onload="closewindow();">
</body>

and closewindow() script method will close the page.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15641
    
  15

If all you were doing was closewindow, it wouldn't create a session. JavaScript closewindow() doesn't even send anything to the server. And the server isn't going to create anything at all if a client doesn't make a request to it.
suresh dasari
Ranch Hand

Joined: Oct 05, 2009
Posts: 121

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.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15641
    
  15

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.
suresh dasari
Ranch Hand

Joined: Oct 05, 2009
Posts: 121

Tim,

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How can we use <jsp:scriptlet /> tag in jspx file that uses faclets
 
Similar Threads
Query regarding using jsp, .tag, .tld altogether in application
Does someone know Facelest?
Tag Files : why TLD requires
Can't render custom facelet component in IceFaces
Need help in xhtml files