Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cannot propagate data from struts form to an Action Class

Status
Not open for further replies.

piterskiy

Technical User
Aug 24, 2007
8
US
I have a jsp page, Action and ActionForm classes.
When sending parameters from JSP to Action, parameters are not being propagated to Action class.

Here is what I have:

struts-config file:

<form-beans>
<form-bean name="myForm" type="path_to_form.FormClass">
</form-bean>
</form-beans>

<action-mappings>
<action path="/myAction" type="somePath.myAction" name="myForm" scope="request" input="/My.jsp">
</action>
</action-mappings>
[/color blue]

JSP file:

function doSearch(val)
{
//frm = document.forms['wbasPropsForm'];
frm = document.wbasPropsForm;
frm.operation.value = "search";

if (checkForm(val))
{
frm.submit();
}
}

<html:form action="myAction.do">
html:text property="strValue" styleClass="searchField"/>
</html:form>
[/color blue]
ActionForm class:

public class FormClass extends ActionForm {
private String _strValue;

public String getStrValue(){return _strAvalue;}
public void setStrValue(String string){_strValue=string;}
[/color blue]
Action class:

FormClass aFormClass = (FormClass) form;
session.setAttribute("myForm", aFormClass);

String val = Utils.trim(aFormClass.getStrValue());
[/color blue]
............

val[/color red] is not getting a value.

If anyone knows the answer to that, it would be greate.

 
Hi

Please :
[ul]
[li]copy & paste your code instead of typing[/li]
[li]post your code between [tt][ignore]
Code:
[/ignore][/tt] and [tt][ignore]
[/ignore][/tt] tags[/li]
[li]specify some proper file names not just their type[/li]
[/ul]
By the way, are you sure that val should have a value ?

Feherke.
 
Yes, absolutelly.
That's an idea, so that value defines the feature logic flow.

Thank you for your reply.

Eugene
 
Hi

Because you posted a JavaScript function. Which in normal case case would have nothing to do in all this. And now I am wondering what is the reason you posted it. If that should be the one which populates the [tt]form[/tt] field, then are you sure there has to be "operation" ?
Code:
 frm.[red]operation[/red].value = "search";
Searching for a logic flow, I have a feeling there should be "strValue".

Then there is that "A" in the getter :
Code:
public String getStrValue(){return _str[red]A[/red]value;}
Again searching for a logic flow, I would expect to have "_strValue" there...

Feherke.
 
I just misspelled the variable.
In fact that is an _strValue.
The reason for me to have a javascript function on click event of the button is, that I have multiple buttons on my form that submit different parameters to the form.

The code that I sent it is just a fragment of the whole picture.

The entire code has one form with three buttons that are doing different actions for the form.
Each action is specified by the operation value.
"operation" is a hidden field on a form.

So, depending on that value, program will have different workflow.

By the way, when I retrieve operation in my Action class, it's value is being successfully retrieved.

Getter and Setter methods for "operation" attribute I specify in a parent class of my FormClass.
And then my FormClass extends that Parent class.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top