Unexpected result of virtual forms?
i am trying to write an example testing virtual forms
there are five components and one virtual form in my page.
A input Text Field 1
A input Text Field 2(with required)
A Submit button
A reset button (join the virtual form with submit "yes")
A static text
And InputTextFiled1 and Static Text field's text is property binding to
same property in the session scope bean
so there is only one button reset join the virtual form
when i click the reset button, it will works like this:
public String resetAction(){
form1.discardSubmittedValue(inputTextField1);
inputTextField1.setText("");
}
if i just input text(ex:hello) in inputTextField1, and inputTextField2 with blank
then submit the submit button, there will be a error like "required error message for inputTextField2".
after error message shows, i click the reset button,
the static text will show the text which i type before(ex:hello),
and inputTextField1 will be blank.
it means property in the session scope bean is updated?
but i didnt let the inputTextField1 join the virtual form..
why static text shows that words?
and if i dont push submit button at first,
i just input something in inputTextField1, let inputTextField2 blank, then just push the reset button.
the static text wont be update as my predict.
is something wrong in my mind?
[1575 byte] By [
kojilin] at [2007-11-26 8:15:46]

# 4
First, I want to thank you both for finding this issue.
I do see unexpected results. However, when I click the "clear" button, I am not seeing textField1 repopulated with any text.
Let's restate the scenario.
Valid use case with unexpected results:
1. Drag textField1, textField2, button1, button2, staticText1, messageGroup1.
2. Set textField2 required.
3. Configure button2 as a "clear textField1" button that submits a virtual form with no participants.
4. Action method for the "clear textField1" button.
public String button2_action() {
form1.discardSubmittedValue(textField1);
textField1.setSubmittedValue(""); //use setSubmittedValue("") and not an equivalent
return null;
}
5. Bind both the textField1 and the staticText1 to a session bean property.
6. Run.
7. Enter "hello" into textField1.
8. Click button1. Validation fails because textField2 is required. "hello" is still in textField1.
9. Click button2. "hello" is cleared from textField1, but shows up in staticText1. It could be said that this should not happen, since a virtual form was submitted with no participants, and yet "hello" was copied to the binding target in the session bean.
Workaround:
public void preprocess() {
//use as a temporary workaround:
//for pages with validation, clear the local value of any
//virtual form non-participants that are also bound
textField1.setValue(null);
textField1.setLocalValueSet(false);
}
mbohm at 2007-7-6 21:14:01 >
