Ich implementiere ein einfaches ExtJS-Formular, das an eine Struts 2 ActionSupport-Klasse übergeben wird. Der Code für die verschiedenen Komponenten ist wie folgt:Struts 2 überträgt keine Parameter vom ExtJS-Formular in die ActionSupport-Klasse
MyAction.java:
//packaging and imports
public class MyAction extends ActionSupport {
private String aField;
private String anotherField;
public String execute() throws Exception {
System.out.println(afield + " " + anotherField); //just checking values, atm
return ActionSupport.SUCCESS;
}
public String getAField() {
return this.aField;
}
public void setAField(String aField) {
this.aField = aField;
}
public String getAnotherField() {
return this.anotherField;
}
public void setAnotherField(String anotherField) {
this.anotherField = anotherField;
}
}
myForm.js:
Ext.onReady(function() {
Ext.QuickTips.init();
// turn on validation errors beside the field globally
Ext.form.Field.prototype.msgTarget = 'side';
var myForm = new Ext.form.FormPanel({
id: 'myFormId',
url: 'submitMyForm.action',
defaults: {
xtype: 'textfield'
},
items: [
{
fieldLabel: 'A Field',
id: 'aField',
name: 'aField',
allowBlank: false
},
{
fieldLabel: 'Another Field',
id: 'anotherField',
name: 'anotherField',
allowBlank: false
}
],
renderTo: 'contentMain'
});
var submitButton = new Ext.Button({
text: 'SUBMIT',
handler: function(button, event) {
myForm.getForm().submit({
url: 'submitMyForm.action',
failure: function() {
Ext.Msg.alert('Error', 'Can not save data.');
}
});
}
});
});
struts.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="myPackage" namespace="/" extends="json-default">
<action name="submitMyForm" class="mycodepackage.MyAction">
<result name="*" type="json">
<param name="includeProperties">aField</param>
</result>
</action>
</package>
</struts>
Wenn das Eintragen Die Schaltfläche wird gedrückt, meine Aktion wird ordnungsgemäß ausgeführt und gibt zusätzlich zu den Standard-Debugging-Daten Folgendes aus:
null null
Das JSON Ergebnis wieder korrekt gesendet wird, aber natürlich ist auch null:
14:22:17,046DEBUG JSONResult:68 - Adding include property expression: aField
14:22:17,052DEBUG JSONWriter:68 - Ignoring property because of include rule: anotherField
14:22:17,053DEBUG JSONUtil:68 - [JSON]{"aField":null}
Jetzt ist es mein Verständnis, dass die in Form eingegebenen Werte sollten in die Instanzvariablen eingefügt werden meine Aktionsklasse. Liege ich damit falsch? Wenn nicht, was könnte schief gehen? Wenn ja, wie kann ich sicherstellen, dass die Formulardaten an meinen Aktionshandler gesendet werden?
Danke.
könnten Sie mir bitte dabei helfen out: [Fehler beim Ausführen der Anwendung „Keine Aktion zugeordnet für Namespace/und Aktionsnamen einloggen] [1] [1]: http://stackoverflow.com/questions/6966890/getting-error-there-is-no-action-mapped-for-namespace-und-action-name-loginact – rahul