0

I am implementing a simple ExtJS form that submits to a Struts 2 ActionSupport class. The code for the various components is as follows:

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>

When the submit button is pressed, my action executes properly, and in addition to standard debugging data prints out:

null null

The JSON result is sent back correctly, but of course is also 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}

Now, it's my understanding that the values entered in the form should be inserted into the instance variables for my action class. Am I wrong in this? If not, what could be going wrong? If so, what can I do to ensure that the form data is sent to my action handler?

Thanks.

Catie
  • 75
  • 1
  • 2
  • 6
  • could you please help me out with this: [Error on running the application "No action mapped for namespace / and action name login][1] [1]: http://stackoverflow.com/questions/6966890/getting-error-there-is-no-action-mapped-for-namespace-and-action-name-loginact – rahul Aug 07 '11 at 04:15

2 Answers2

0

Any parameters sent will be placed into the similarly named setters. Why don't you first check that the form parameters are getting sent correctly with LiveHttpHeaders Firefox plugin.

rado
  • 4,040
  • 3
  • 32
  • 26
  • You were right, form data isn't being sent correctly. Any idea what could be cause that? I've been looking around and haven't found anything on the subject. Any thoughts would be greatly appreciated. – Catie Dec 13 '10 at 16:49
0

Once we realized the form data was not being correctly passed into the http request, my coworker developed a form data interceptor, which we use to load the data in manually. For more information, look into the <interceptor>, <interceptor-stack>, and <interceptor-ref> tags.

Catie
  • 75
  • 1
  • 2
  • 6