Cannot propagate data from struts form to an Action Class
Cannot propagate data from struts form to an Action Class
(OP)
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>
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>
ActionForm class:
public class FormClass extends ActionForm {
private String _strValue;
public String getStrValue(){return _strAvalue;}
public void setStrValue(String string){_strValue=string;}
Action class:
FormClass aFormClass = (FormClass) form;
session.setAttribute("myForm", aFormClass);
String val = Utils.trim(aFormClass.getStrValue());
............
val is not getting a value.
If anyone knows the answer to that, it would be greate.
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>
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>
ActionForm class:
public class FormClass extends ActionForm {
private String _strValue;
public String getStrValue(){return _strAvalue;}
public void setStrValue(String string){_strValue=string;}
Action class:
FormClass aFormClass = (FormClass) form;
session.setAttribute("myForm", aFormClass);
String val = Utils.trim(aFormClass.getStrValue());
............
val is not getting a value.
If anyone knows the answer to that, it would be greate.
RE: Cannot propagate data from struts form to an Action Class
Please :
- copy & paste your code instead of typing
- post your code between [code] and [/code] tags
- specify some proper file names not just their type
By the way, are you sure that val should have a value ?Feherke.
http://rootshell.be/~feherke/
RE: Cannot propagate data from struts form to an Action Class
That's an idea, so that value defines the feature logic flow.
Thank you for your reply.
Eugene
RE: Cannot propagate data from struts form to an Action Class
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 form field, then are you sure there has to be "operation" ?
CODE
Then there is that "A" in the getter :
CODE
Feherke.
http://rootshell.be/~feherke/
RE: Cannot propagate data from struts form to an Action Class
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.