struts form info dropped before action
hi all, is there someone knowledgeable who could help with the following:
problem summary: when info submitted from JSP to Struts action, Struts form info dropped before struts action can process info
seeking solution: info submitted from JSP to Struts action would remain in Struts form for action to process info
code:
> JSP (/myJSPpage.jsp)
<html:form target="_self" action="/myStrutsAction.do">
Option 1<html:radio property="optionType" value="option_1" />
Option 2<html:radio property="optionType" value="option_2" />
Option 3<html:radio property="optionType" value="option_3" />
Title:<html:text property="titleString"/>
<html:submit value="submit" property="optionSubmit" />
<input type="hidden" name="action" value="processOptions" />
</html:form>
> struts-config.xml:
<form-beans>
<form-bean name="OptionEntryForm" type="com.forms.OptionEntryForm"/>
</form-beans>
<action-mappings>
<action path="/myStrutsAction" name="OptionEntryForm" type="com.actions.OptionAuthAction" validate="false" input="/myJSPpage.jsp" scope="request" />
</action-mappings>
> OptionEntryForm.java:
publicfinalclass OptionEntryFormextends BaseForm{
private String optionType ="";
private String titleString ="";
publicvoid setOptionType(String optionType){
this.optionType = optionType ;
}
public String getOptionType(){
return optionType;
}
publicvoid setTitleString(String titleString){
this.titleString = titleString ;
}
public String getTitleString(){
return titleString;
}
}
> within OptionAuthAction:
log("- OptionAuthAction: form is OptionEntryForm?" + (forminstanceof OptionEntryForm));
if (forminstanceof OptionEntryForm)
{
inForm = (OptionEntryForm) form;
log("- OptionEntry form is found");
log("- OptionAuthAction: action=" + action);
if (action.equals("processOptions"))
{
log("- OptionAuthAction: processOptions form type=" + inForm.getOptionType());
log("- OptionAuthAction: processOptions form title=" + inForm.getTitleString()) ;
}
}
user input:
selects 'option_1' from JSP, fills out title text field, presses 'submit' button
log output:
- OptionAuthAction: form is OptionEntryForm?true
- OptionEntry form is found
- OptionAuthAction: action=processOptions
- OptionAuthAction: processOptions form type=
- OptionAuthAction: processOptions form title=
Thanks for your consideration!
[4408 byte] By [
ip_VTa] at [2007-11-27 11:59:48]

# 2
Some success! I am seeing two text fields passed to the action.
skp71:
1. changed this
2. changed this
3. the path is set up, I left it out for simplicity of posting to forum
4. I added this in.. is the forward essential to process a form?
5. I am working on someone else's code where the other (four or five dozen) action tags have '/>' I don't quite understand this..
The radio inputs are still not being passed to the action. Is there some special handling that radio inputs need in order to pass through from the form to the action?
log output:
- OptionAuthAction: form is OptionEntryForm?true
- OptionEntry form is found
- OptionAuthAction: action=processOptions
- OptionAuthAction: processOptions form type=
- OptionAuthAction: processOptions form title=this is another test
- OptionAuthAction: processOptions form desc=testing 1 2 3 4
thanks for your consideration
ip_VTa at 2007-7-29 19:27:45 >

# 3
radio buttons values, you have to get it something like this using javascript:
finally assign to a hidden, and get it using form bean getter/setter
function subForm()
{
var j = 0;
var check_values = new Array();
var the_form = window.document.forms[0];
var commaVal;
for(var i=0; i<the_form.length; i++)
{
var temp = the_form.elements[i].type;
if((temp == "radio") && (the_form.elements[i].checked)) {
check_values[j] = the_form.elements[i].value;
j++;
}
}
for(var k=0; k><check_values.length; k++)
{
commaVal = commaVal + check_values[k] + ","; //get as comman delimited string
}
document.getElementById("hiddenfield").value = commaVal; //assign to hidden
}
>
skp71a at 2007-7-29 19:27:45 >

# 4
yikes.. struts doesn't support passing html:radio values through a form to an action? I've got that wrong, right?
skp71, I'm planning to go with a simplified version of the solution you suggest, which looks like this:
> JSP (/myJSPpage.jsp)
<script>
function loadHiddenVal(optionVal)
{
document.getElementById("optionTypeId").value = optionVal ;
}
</script>
<html:form target="_self" action="/myStrutsAction.do">
Option 1<input type="radio" name="optionRadio" value="option_1" onclick="loadHiddenVal('option_1')" />
Option 2<input type="radio" name="optionRadio" value="option_2" onclick="loadHiddenVal('option_2')" />
Option 3<input type="radio" name="optionRadio" value="option_3" onclick="loadHiddenVal('option_3')" />
Title:<html:text property="titleString"/>
<html:submit value="submit" property="optionSubmit" />
<input type="hidden" name="action" value="processOptions" />
<html:hidden styleId="optionTypeId" property="optionType" />
</html:form>
The rest of the code is the same as before.
Thanks for your help and consideration.
ip_VTa at 2007-7-29 19:27:45 >
