• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Triggering execute() without form submit

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

Thanks,
Mallika.
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ?

Thanks,
Mallika.
 
Mallika R Kumar
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

Thanks,
Mallika.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Tim Manchester
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

I will not go into detail on this as it's going to take some thought and a fair bit of effort to make this work the way you want it to. Though I would suggest that you put a hidden text element in your jsps and forms that list the action that the user selects (you can set it in javascript when the user presses a button, do some reading on how to accomplish that). That way in your action form you can figure out what data to add/remove to/from your "actions" LinkedList.

Hope that's not too abstract for you.

Regards,

- DM_Tim
 
reply
    Bookmark Topic Watch Topic
  • New Topic