I use Struts 2 and Ajax. I am not able to get parameter in Action class. I have a form like this:
<s:form id="form" onSubmit="sendAjaxRequest();">
<s:textfield name="libelle" label="Libelle" />
<s:textfield name="id" label="id" />
<s:submit value="Valider" />
<s:reset value="Effacer" />
</s:form>
When I examine the request which is sent in HTTP Reader :
Content-length contains libelle=Test&id=13
My request is good !
In my action class :
public class MyAction extends ActionSupport {
private String libelle;
private Integer id;
public String getLibelle() {
return auteur;
}
public void setLibelle(String libelle) {
this.libelle = libelle;
}
public String getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String execute() {
System.out.println("Libelle " + libelle);
System.out.println("Libelle " + this.libelle);
}
}
In my Action libelle and this. libelle are null. I don't know if I am making mistakes. If someone could give me help. Thanks.
I found my problem but not a solution. I inspect the html code generated and i see the following one :
<form id="form" name="form" action="/path/MyOtherAction.action" method="post" onSubmit="sendAjaxRequest();">
<table class="wwFormTable">
<tr>
<td class="tdLabel"><label for="form_libelle" class="label">Libelle:</label></td>
<td><input type="text" name="libelle" value="" id="form_libelle"/></td>
</tr>
<tr>
<td class="tdLabel"><label for="form_id" class="label">id:</label></td>
<td><input type="text" name="ide" value="" id="form_id"/></td>
</tr>
...
<td colspan="2"><div align="right"><input type="submit" id="form_0" value="Valider"/>
..
<td colspan="2"><div align="right"><input type="reset" value="Effacer"/>
..
</table>
</form>
So MyOtherAction is executed first before my sendAjaxRequest. How to remove action MyOtherAction in my form ? Thanks for reading.