This week's book giveaway is in the Agile forum.
We're giving away four copies of Fixing your Scrum and have Ryan Ripley & Todd Miller on-line!
See this thread for details.
Win a copy of Fixing your Scrum this week in the Agile forum!
  • 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:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

Javascript reset() method and JSF h:form

 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I created a JSP with a JSF h:form with login elements such as text input field and a password field. I included some javascript in the JSP header such that each time the html body loads or unloads, the h:form is reset. The results are not consistent. I tested using tomcat's internal web browser, safari and IE on Mac.
When I first start tomcat and load the jsp page, the reset works fine. Going back and forth between pages resets the fields. When the I reload the page within the same server connection, the text field remains populated and is not reset. This is true even when I click the reset button. The reset button redundancy is just for practice.

In the javascript function, I used the h:form's ID value since it doesn't have a name attribute.


Here is my JSP code:



What am I missing?

Thanks.
 
Sheriff
Posts: 67579
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please be sure to ask JSF questions in the JSF forum. I have moved this post there for you.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not sure why Bear moved it since it is a JavaScript problem

document.forms.loginfo.reset() is not valid

It is either

document.formName.reset();
or
document.forms["formName"].reset();
or
document.getElementById("formId").reset();

Eric
 
Gina vernon
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Eric Pascarello wrote:I am not sure why Bear moved it since it is a JavaScript problem



Thats what I thought.


Anyway, I gave all your recommendations a try, the problem persists. One other thing I have noticed is that the second time I load the page within the same server connection, the reset button doesn't work either. It looks like the value from the previous page load is considered the default.
Is there any server cache setting I can change to fix it?

Thanks.
Gina
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can create a function and set the values with anything you want, but that would require you to reference each element of the form.

Eric
 
Saloon Keeper
Posts: 24161
165
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It think the problem is in understanding what Reset does.

Reset reverts all form values to whatever they were when the page was loaded. In JSF, however, if you move off the page using a commandbutton or commandlink, the normal mode of operation is to update the backing bean from the form. Then if you go back to that form, the page is reloaded with those updated values. Reset cannot revert to the older original values since they're not what was in the form when it was loaded.

A more powerful type of reset that CAN handle things like that can be done by adding a commandbutton labelled "Reset" that has 'immediate="true"' set and attaches to an action method on the backing bean that resets the bean's fields to their original values. Since the command action also redisplays the page (assuming you haven't set up to navigate somewhere else, instead), the page will be reloaded with those updated backing bean values. And the HTML/JavaScript reset runction would then revert to those values.

And, yes this does mean that you could totally confuse the user by placing two different reset buttons on the page; one that talks to the server and resets from the backend and the other being a traditional HTML form reset that only resets the current inputs.
 
Create symphonies in seed and soil. For this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic