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-15]
# 1

Please try change the following in your action mappings:

1. <form-bean name="OptionEntryForm", change the name to "optionEntryForm" ("O" to lowercase)

2. name="optionEntryForm" ("O" to lowercase)

3. input="/myJSPpage.jsp", add the path like, input = "/WEB-INF/jsp/myJSPpage.jsp">

4. where is forward page? <forward name="success" path="/WEB-INF/jsp/viewConfirm.jsp"/>

5. scope="request" />, here remove "/", only forward will have close "/"

skp71a at 2007-7-29 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 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 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 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 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 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 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 5

This should work, so did you solve the issue?

Why do you have "styleId" in the hidden? Just property is enough.

<html:hidden styleId="optionTypeId" property="optionType" />

skp71a at 2007-7-29 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 6

skp71,

Yes, the hidden-input workaround seems to work. I'm very curious why <html:radio /> does not seem to return a property value to the form in this case, while <html:text /> does.

the JSP:

<html:hidden styleId="optionTypeId" property="optionType" />

displays in HTML as:

<input type="hidden" name="optionType" id="optionTypeId" />

'optionTypeId' lets the javascript know how to set the value which will be passed through the form as 'optionType'

Thanks for your help and consideration

ip_VTa at 2007-7-29 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 7

If we have group of radio buttons or check boxes, I used to work out thro' javascript. I haven't tried anything else. Thanks for the duke stars.

skp71a at 2007-7-29 > top of java,Enterprise & Remote Computing,Web Tier APIs...