This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Hi, I want to display a list of rows to the user, once they successfully log into my web application. Once the user successfully logs in, some of their data, like username etc is being stored in the session. The page a user sees after a successful login is list of rows about their activity. I want this to happen dynamically, without user having to press submit button. Which is the best way to go about it? Right now the flow is as follows: login.jsp -> home.jsp -> userLog.jsp LoginAction -> on success sends user to ActionForward mapped to home.jsp. home.jsp redirects to userLog.jsp -> UserLog Action has functionality to display rows about the user. Display of data happens on userLog.jsp. I've set up UserLogForm (ActionForm) to have initial value for the action field, ie, action="showlogs", but how can I populate their username in the UserLogForm without submit button being pressed ? Any insight into this will be greatly appreciated.
In your action class, when you know what jsp you are going to forward to, create an instance of the form that you will be going to, populate it and put in into the request as an attribute.
In other words, say you're in loginAction.execute and you've just made the determination that you are going to go to the home.jsp page next. Create an instance of the ActionForm for the home page, populate any fields you want to transfer and then call HttpServletRequest.setAttribute with the parameters class name (the name of the ActionForm class) and the actionForm itself.
Mallika R Kumar
Joined: Jan 21, 2004
Hi Tim, Thanks for your response. Instantiating the ActionForm worked, the user is being properly directed to the userLog.jsp page after a successful login, with values set for the ActionForm. But their activity is not being displayed when they land on this page. How can I trigger the execute() method, that gets rows for that user's activity, without putting a submit button ? I want this to happen dynamically, without user intervention. How can I do that ?
Mallika R Kumar
Joined: Jan 21, 2004
Hi, I'm trying to display a user's activity as soon as they land on a jsp page, without the user hitting submit button, or clicking on a href. Is this a good test case to be designed in Struts, or should MVC-I be used here? Using scriplets and javabeans, I can send the user's data to an intermediate class that will send control to the Model class, without having a Struts action class. This is not in conformance with Struts Controller Servlet, but I'm trying to come up with ways of doing this. Am I missing something ? Does Struts have inbuilt actions that will allow me to perform this functionality ? Any response will be helpful.
What we're trying to get across here is that the Struts way of doing things is to have the action class do the database access and store the information it retrieves in a javaBean. The Action class then forwards to the jsp, which then uses the javaBean to display the information.
If you want the userLog.jsp to display log information, have the action class populate the actionForm with that log information BEFORE the page is displayed. Then, when the jsp is displayed, it can access the information in the ActionForm put there by the action class.
I think what you're looking for is to maintain a list of activities in the form that you can modify as the user walks through the pages that you can display on the pages.
I had a question about dynamically adding a table to a jsp which you can read in this thread that gives adivce similar to what you'd want to do to put this info on your pages. Though you'd want to keep track of the activities in LinkedList data members that you'd pass between the forms rather than in a seperate bean. And you'd generate the data in your action classes rather than pulling it out of a database.
What I see headed your way is some interesting (complex) coding to handle what to do when someone presses the "Back" browser button in regards to how to remove items from your list correctly.
Hope that's not too abstract for you.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com