[Httpunit-commit] CVS: httpunit/src/com/meterware/httpunit FormControl.java,1.19,1.20 WebForm.java,1
Brought to you by:
russgold
From: Russell G. <rus...@us...> - 2002-08-21 03:45:04
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory usw-pr-cvs1:/tmp/cvs-serv2259/src/com/meterware/httpunit Modified Files: FormControl.java WebForm.java Log Message: Added JavaScript support for Radio buttons Index: FormControl.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/FormControl.java,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- FormControl.java 20 Aug 2002 19:39:20 -0000 1.19 +++ FormControl.java 21 Aug 2002 03:45:01 -0000 1.20 @@ -100,6 +100,11 @@ abstract String[] getValues(); + Object getDelegate() { + return getScriptableObject(); + } + + /** * Returns a scriptable object which can act as a proxy for this control. */ @@ -325,10 +330,17 @@ private final boolean _isCheckedDefault; + protected FormControl.Scriptable newScriptable() { + return new Scriptable(); + } + + class Scriptable extends FormControl.Scriptable { public Object get( String propertyName ) { - if (propertyName.equalsIgnoreCase( "checked" )) { + if (propertyName.equalsIgnoreCase( "value" )) { + return getQueryValue(); + } else if (propertyName.equalsIgnoreCase( "checked" )) { return isChecked() ? Boolean.TRUE : Boolean.FALSE; } else if (propertyName.equalsIgnoreCase( "defaultchecked" )) { return _isCheckedDefault ? Boolean.TRUE : Boolean.FALSE; @@ -445,6 +457,7 @@ public RadioGroupFormControl() { } + void addRadioButton( RadioButtonFormControl control ) { _buttonList.add( control ); _buttons = null; @@ -473,6 +486,15 @@ } + Object getDelegate() { + ScriptableDelegate[] delegates = new ScriptableDelegate[ getButtons().length ]; + for (int i = 0; i < delegates.length; i++) { + delegates[i] = getButtons()[i].getScriptableObject(); + } + return delegates; + } + + void addValues( ParameterProcessor processor, String characterSet ) throws IOException { for (int i = 0; i < getButtons().length; i++) getButtons()[i].addValues( processor, characterSet ); } @@ -495,10 +517,12 @@ } if (matchingButtonIndex <0) throw new IllegalParameterValueException( getButtons()[0].getName(), (String) values.get(0), getAllowedValues() ); + boolean wasChecked = getButtons()[ matchingButtonIndex ].isChecked(); for (int i = 0; i < getButtons().length; i++) { if (!getButtons()[i].isReadOnly()) getButtons()[i].setChecked( i == matchingButtonIndex ); } values.remove( getButtons()[ matchingButtonIndex ].getQueryValue() ); + if (!wasChecked) getButtons()[ matchingButtonIndex ].sendOnClickEvent(); } @@ -539,32 +563,6 @@ setChecked( values.contains( getQueryValue() ) ); if (isChecked()) values.remove( getQueryValue() ); if (isChecked() != wasChecked) sendOnClickEvent(); - } - - - protected FormControl.Scriptable newScriptable() { - return new Scriptable(); - } - - - class Scriptable extends BooleanFormControl.Scriptable { - - public Object get( String propertyName ) { - if (propertyName.equalsIgnoreCase( "value" )) { - return getQueryValue(); - } else { - return super.get( propertyName ); - } - } - - - public void set( String propertyName, Object value ) { - if (propertyName.equalsIgnoreCase( "checked" )) { - setChecked( value instanceof Boolean && ((Boolean) value).booleanValue() ); - } else { - super.set( propertyName, value ); - } - } } Index: WebForm.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebForm.java,v retrieving revision 1.58 retrieving revision 1.59 diff -u -r1.58 -r1.59 --- WebForm.java 19 Aug 2002 18:52:26 -0000 1.58 +++ WebForm.java 21 Aug 2002 03:45:01 -0000 1.59 @@ -319,7 +319,7 @@ * Resets all parameters to their initial values. */ public void reset() { - FormControl controls[] = getFormControls(); + FormControl[] controls = getFormControls(); for (int i = 0; i < controls.length; i++) { controls[i].reset(); } @@ -471,11 +471,16 @@ public void setParameterValue( String name, String value ) { - getParameter( name ).getScriptableObject().set( "value", value ); + final Object scriptableObject = getParameter( name ).getScriptableObject(); + if (scriptableObject instanceof ScriptableDelegate) { + ((ScriptableDelegate) scriptableObject).set( "value", value ); + } else if (scriptableObject instanceof ScriptableDelegate[]) { + ((ScriptableDelegate[]) scriptableObject)[0].set( "value", value ); + } } - public ScriptableDelegate[] getControls() { + public ScriptableDelegate[] getElementDelegates() { FormControl[] controls = getFormControls(); ScriptableDelegate[] result = new ScriptableDelegate[ controls.length ]; for (int i = 0; i < result.length; i++) { @@ -649,8 +654,19 @@ } - ScriptableDelegate getScriptableObject() { - return getControls()[0].getScriptableObject(); + Object getScriptableObject() { + if (getControls().length == 1) { + return getControls()[0].getDelegate(); + } else { + ArrayList list = new ArrayList(); + for (int i = 0; i < _controls.length; i++) { + FormControl control = _controls[i]; + if (control instanceof CheckboxFormControl) { + list.add( control.getScriptableObject() ); + } + } + return list.toArray( new ScriptableDelegate[ list.size() ] ); + } } |