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 Using window.location.href Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Using window.location.href" Watch "Using window.location.href" New topic
Author

Using window.location.href

Christopher Sharp
Ranch Hand

Joined: Dec 12, 2007
Posts: 155
I'm continuing with the JSF project mentioned in previous postings. When I first started on this I had to develop the client-side code first before I was in a position to decide which server technology to use, and by the time I opted for JSF, I already had a lot of JavaScript code written. Consequently I want as much as possible to avoid rewriting a lot of code.

The spoecific problem I'm having is with the document.location.href redirection. In my index.jsp file I have the following JavaScript function in the head:



Then in the body of the page I have the following form:



where the user can choose between two buttons. Near the bottom of the page I have the following:



which is associated with class LoginBean, and includes the following methods:



Together with several other methods.

When the user first visits this page isLoggedin() returns false so the user is directed to the login page "login.jsp". As the home page contains some data that is later used, I append it to the href in the JavaScript function. This works OK. If as a test I ensure that isLoggedin() returns true to simulate the situation where the user is already logged on and returns to the index page, he is directed to pages "option1.jsp" or "option2.jsp" together with some data, according to which of the buttons he clicked on. This also works, and the associated data is picked up in the "option1.jsp" or "option2.jsp" pages as required and stored in hidden fields.

When the person visits the login page, as should be the case on starting a new session, if he successfully logs in, "loggedin" is set to true and the getter returns that. However, I'm having a lot of trouble going from the login page to one of the option pages and passing the parameters along with it. I can indeed store the parameters in the string "urldata" in my login page with using:



but I can't find an easy way of directing JSF to option1.jsp or option2.jsp as required.

I can go to an intermediate page called "success.jsp", and have a button that when clicked is supposed to take you to one of the options using href, but this doesn't work. Why does href only work with the index page?

I would be most grateful for some help with this. I've had to use "onklick" here as your server objects to the correct spelling.

Christopher Sharp
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using window.location.href