Hi, I'm trying to set a value in a hidden multivalue form field, without much luck. I'm trying to create some test scripts for an internal "legacy" intranet site.
I started off with with setParameter(String, String[]) but as the field is hidden this throws an error.
After reading the some of the site I tried the getScriptableObject().setParameterValue(String,String) but as this is a multivalue field this does not work.
I think I've found a way by using the form.getRequest(SubmitButton) after setting setParameterValuesValidated to false, this allows me to get a WebRequest object which I can then alter via the setParameter(String,String[]).
What I can't figure out is how to submit the webRequst. I've tried getResource(WebRequest) but this doesnt seem to work, I've noticed that there is a completeRequest but I've no idea how to get the urlConnection or if this is the right way of going about it. Any ideas?
String[] currentValues = form.getParameterValues( name );
Vector values = new Vector();
if (arrayIndex != -1){
// change all values to the one passed in
}
else{
//change only the 1 value identified by the arrayIndex to the value passed in
currentValues[arrayIndex] = value;
for (int x = 0; x < currentValues.length; x++){
values.add (currentValues[x]);
}
}
//save value back to form
form.setParameter( name, (String[])values.toArray( new String[0] ) );
return form;
}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2004-05-24
See my other post regarding a feature in the getRequest method.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi, I'm trying to set a value in a hidden multivalue form field, without much luck. I'm trying to create some test scripts for an internal "legacy" intranet site.
I started off with with setParameter(String, String[]) but as the field is hidden this throws an error.
After reading the some of the site I tried the getScriptableObject().setParameterValue(String,String) but as this is a multivalue field this does not work.
I think I've found a way by using the form.getRequest(SubmitButton) after setting setParameterValuesValidated to false, this allows me to get a WebRequest object which I can then alter via the setParameter(String,String[]).
What I can't figure out is how to submit the webRequst. I've tried getResource(WebRequest) but this doesnt seem to work, I've noticed that there is a completeRequest but I've no idea how to get the urlConnection or if this is the right way of going about it. Any ideas?
Code:
HttpUnitOptions.setParameterValuesValidated( false );
WebRequest Wrq = form.getRequest(form.getSubmitButton("cmdNewQuote"));
Wrq = modifyParameterArray(Wrq,"txtRowDirty","Y",0);
Wrq.setParameter("txtName1","Graham");
Wrq.setParameter("varField1c5","33");
Wrq.setParameter("txtVersionName","Perf-Test");
Wrq.setParameter("txtDirty", "Y");
modifyParameterArray method is based on the one in the patches directory but changes so that it would work with hidden fields.
protected WebRequest modifyParameterArray(WebRequest form,String name, String value,int arrayIndex){
String[] currentValues = form.getParameterValues( name );
Vector values = new Vector();
if (arrayIndex != -1){
// change all values to the one passed in
}
else{
//change only the 1 value identified by the arrayIndex to the value passed in
currentValues[arrayIndex] = value;
for (int x = 0; x < currentValues.length; x++){
values.add (currentValues[x]);
}
}
//save value back to form
form.setParameter( name, (String[])values.toArray( new String[0] ) );
return form;
}
See my other post regarding a feature in the getRequest method.