I am having trouble clearing a form using "Reset", and would most appreciate some help.
Bassically I have the index page, and options 1, 2 and 3. I will have the beans MyOption1Bean, MyOption2Bean and MyOption3bean for the three option pages, respectively, that will contain only getters and setters specific to those options. In addtion, I will have the bean, MyOptionBean (no number) that will have getters and setters for the index page, getters and setters that are common to more than one of the option pages, and actions and file I/O etc.
The page option1.xhtml has a reset button as follows:
which is supposed to reset the form, and is where I'm having the trouble.
It is linked to an action in MyOptionBean at the end of the listing here:
where I'm accessing the values in MyOption1Bean, and eventually the other two.
The contents of MyOption1Bean are just getters and setters, such as here:
The problem I have is when the form in option1.xhtml is first filled in, if the reset button is clicked without submitting the values, the form is cleared, as it should be, regardless of whether I have it is linked to any actions. However, if I enter values in the form, submit them, then return back to the same form using the
JSF navigation, not using the browser buttons, the contents of the form are still displayed. That in itself is not necessarily a problem as one may want to change a couple of the values and resubmit the form. The problem is that the reset does not work, using either of the two methods in the action in the listing above, one of which is commented out, or trying something very simple, such as:
where I have just called up the methods in myOption1Bean to set the values back to empty.
None of these work. To summarize, values are cleared in the form when the "Reset" button is clicked, but only if the values have not been submitted, otherwise they will not clear. I suspect that on clicking "Reset" the values are cleared in the bean, but the bean then picks up the values still held in the option1.xhtml page.
The only way I can solve this is by using JavaScript to clear the fields of the HTML form. Is there a way of directly crearing the values in the bean? I would very much appreciate some help on this.
Incidentally, although createValueBinding() is depricated, I still tried it out. If this problem can be solved, I would obviously not want to use depricated methods.