I don't know what you mean by "always start in new browser window".
As far as I know, you need to designate an existing page as the start page using the 'Set as start page'
in the projects panel (right click on the page you want to set as the start page).
As to closing a window, tie the javascript "window.close()" function to one of the actions of your button for example,
onClick="window.close()".
This will bring up an "Are you sure?" promt and close the window if the user says 'Yes".
I guess I should clarify my question.
I have a five page web application that aceeses a database. I log the user in as part of the init of the session bean. I would like to log the user out, close the database connection and return the user to wherever the started from in their browser.
I figure the easiest way to do that is to always open a new browser window when the session bean starts up. This would allow me to close the session and the browser window, forcing a new session to be started the next time the user selects the application form the main web pages.
What you appear to be saying is that the control of starting the deployed project in a new window would be done from the logic of the main page using javascript, php,html or whatever the main web pages are written in.
You suggest that my close be controlled through a javascript call. I was hoping to do it within my creator code which is written in java and jsp. Is there a java call to close the browser window?
You don't need some client side javascript tricks, which can fail, to do this. You have to invalidate the session programmatically, if this doesn't happen automatically after time out. Give the user a logout button and in the action method call HttpSession.invalidate() and clean up the ressources. During the next request with the old JSESSIONID the user gets a new session from the server.
You can't close the browser window using Java because this is the client side. You can't rely on the client side behavior at all, because it depends on the user's settings.
Message was edited by:
Ingmar
I tried this with the following code:
public String button1_action() {
// TODO: Process the button click action. Return value is a navigation
// case name where null will return to the same page.
HttpSession.invalidate();
return null;
}
but Creator gave me an error stating
non-static method invalidate() cannot be called from a static reference.
I thought maybe I could try using the destroy method on my session bean to end the session, but that does not seem to have the desired effect.
Yes,
HttpSession.invalidate()
isn't a static method. First you must retrieve the current session from the ExternalContext:
HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession();
session.invalidate();
The call of the destroy() method in the session bean is the effect not the cause, I think.