File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes SetFocus on re-displayed page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "SetFocus on re-displayed page" Watch "SetFocus on re-displayed page" New topic

SetFocus on re-displayed page

Michelle Cox

Joined: Feb 24, 2004
Posts: 4
I have a jsp page that has many calculate buttons. Hitting any of these would submit the form, do some calculations, repopulate the page with the new values and redisplay it. But my OnLoad sets focus to the first element.
How can I keep track of which button was hit, and setfocus to that button.
Somebody pls help. Thx.
[ February 24, 2004: Message edited by: Michelle Cox ]
Eric Pascarello

Joined: Nov 08, 2001
Posts: 15385
Since it could be many buttons that would do the submission, you need to send a value to the jsp and back to the document when it is being reloaded.
That value should be the button name.
How can you keep track of that button name that was clicked you may ask?
The easiest way would be to add the value to a hidden form element when it is clicked.
now when the form gets submitted you have the ability to keep track of what was submitted. now when the page gets reloaded, you need to pass that button value back to the page somehow. It can be anything from query string to filling in a hidden field.
With that information you need to call the focus()
That is a lot of work to focus a button. Another route would be with cookies. Storing the value into a cookie and reading the cookie when the page is loaded.
Hope you can follow my gibberish
Michelle Cox

Joined: Feb 24, 2004
Posts: 4
Thanks for your detailed reply. I am able to follow what you are saying.
But one thing that I didn't mention bcz I don't know if it is important or not is: I am using struts/dynabeans/tiles/...
So, right now my html:form is like this.
<html:form action="/PersonalInfoSubmit" focus="firstName">
Can the focus property be somehow used to handle this scenario, or should I start modifying my <body OnLoad.. > (which is located in my tiles-layout)
To the moderators of this forum: Should we maybe move this thread to the Struts forum? I am sorry if I posted it in the wrong place, bcz I didn't quite understand if this would be a Javascript solution or not.
Thanks again.
anu ramk

Joined: Feb 26, 2004
Posts: 3
I also have a similar requirement. Were you able to get a solution for your problem?
And for me, 'focus' wont really work, because not only do I need set focus to that field/button, I also have to scroll the page down, so that, that section is visible to the user. But 'focus' doesnt do that.
A friend suggested the use of anchor tags to scroll the page, and using them somehow to roll the page down to the desired section. Please let me know your findings.
A Ramk.
I agree. Here's the link:
subject: SetFocus on re-displayed page
It's not a secret anymore!