You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Mirko <id...@googlemail.com> on 2009/06/24 15:09:57 UTC
Struts2/Javascript: Action class cannot get property from jsp
Hi all,
I'm new to Struts and struggling with Struts2/Javascript.
I have a jsp website with a search form (textfield and submit button).
Submitting the button calls the Struts action "SearchAction".
"SearchAction" gets the property "searchInput" from the jsp website
and does something with it. This works.
But now: I have some (Dojo-)Javascript on my jsp website from which I
want to call the request. The Javascript (instead of the submit
button) sends a HttpRequest to "SearchAction". I assumed that, like
above, "SearchAction" could get the property "searchInput". But this
does not work. "SearchAction is called, but the "searchInput" property
is null. How would I manage that?
Thanks, Mirko
Search form on the jsp website:
<form id="searchForm" action="none" method="post">
<input type="text" id="searchInput" name="searchInput"></input>
<div dojoType="dijit.form.Button" type="submit">Search</div>
</form>
Request in the Dojo JavaScript:
this._xhr = dojo.xhrPost({
url: "./searchAction"
load: function(data){
// DO THINGS
}
},
error: function(error){
// ERROR
}
});
SearchAction class:
public class SearchAction extends ActionSupport {
public String execute() throws Exception {
System.out.println(searchInput); //NULL
return SUCCESS;
}
/* Properties */
private String searchInput = null;
public String getSearchInput() {
return searchInput;
}
public void setSearchInput(String value) {
searchInput = value;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts2/Javascript: Action class cannot get property from jsp
Posted by Mirko <id...@googlemail.com>.
Thanks Dave,
ok I did that and got it working. Although it's not clear to me why my
first attempt doesn't work.
I read about the built-in ajax features. Not sure if they are
approriate for my needs. Have to go into that more thoroughly, later.
Regards, Mirko
Am 24.06.2009 um 15:44 schrieb Dave Newton:
> Mirko wrote:
>> Hi all,
>> I'm new to Struts and struggling with Struts2/Javascript.
>> I have a jsp website with a search form (textfield and submit
>> button). Submitting the button calls the Struts action
>> "SearchAction". "SearchAction" gets the property "searchInput" from
>> the jsp website and does something with it. This works.
>> But now: I have some (Dojo-)Javascript on my jsp website from which
>> I want to call the request. The Javascript (instead of the submit
>> button) sends a HttpRequest to "SearchAction". I assumed that, like
>> above, "SearchAction" could get the property "searchInput". But
>> this does not work. "SearchAction is called, but the "searchInput"
>> property is null. How would I manage that?
>
> I'd assume that the dojo.xhrPost has some means of sending form
> data: you need to serialize the form so the action gets the form
> parameters.
>
> That said, depending on your actual needs, there's built-in support
> for submitting a form via Ajax and updating a div with the action's
> response.
>
> Dave
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts2/Javascript: Action class cannot get property from jsp
Posted by Dave Newton <ne...@yahoo.com>.
Mirko wrote:
> Hi all,
> I'm new to Struts and struggling with Struts2/Javascript.
>
> I have a jsp website with a search form (textfield and submit button).
> Submitting the button calls the Struts action "SearchAction".
> "SearchAction" gets the property "searchInput" from the jsp website and
> does something with it. This works.
>
> But now: I have some (Dojo-)Javascript on my jsp website from which I
> want to call the request. The Javascript (instead of the submit button)
> sends a HttpRequest to "SearchAction". I assumed that, like above,
> "SearchAction" could get the property "searchInput". But this does not
> work. "SearchAction is called, but the "searchInput" property is null.
> How would I manage that?
I'd assume that the dojo.xhrPost has some means of sending form data:
you need to serialize the form so the action gets the form parameters.
That said, depending on your actual needs, there's built-in support for
submitting a form via Ajax and updating a div with the action's response.
Dave
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org