2
votes

when i am putting autowiring interceptor(interceptor-ref name="autowiring") in the action tag in spring.xml then struts tag in index.jsp does not able to map with the setter of that action class. and when i am removing that autowiring tag from the action tag then in that case struts tag of jsp does able to map with the setter of the action class.

Any help from your side will be more than welcome. if you need any sort of example then let me know.

<s:textfield name="name" label="Name" />
<s:textfield name="salary" label="Salary" />
<s:submit value="Add Record" />

then this struts tag with name 'name' and 'salary' does not set the value in action class represented with the same name of setter/getter.

public void setName(String name) {
    this.name = name;
}

public void setSalary(String salary) {
    this.salary = salary;
}
1
can you provide your xml code?Umesh Awasthi
<action name="submitEmp" class="myaction.AddEmployeeSubmitAction"> <interceptor-ref name="autowiring" /> <result name="success">/addRecord.jsp</result> </action>ankit
i am not sure why you doing this??? you can do this simply in your codeUmesh Awasthi
but the thing is why would i am not able to do this way? why jsp is not mapping to action when i am using autowiring interceptor.ankit
my question is why you are using this interceptor, if you are using spring-s2 plugin it will do the autowiring for you.Any reason to use this approach?Umesh Awasthi

1 Answers

2
votes

If you define an interceptor On an action you must define all interceptors on an action. If your parameters aren't being set then whatever the "autowiring" interceptor reference doesn't include the "parameters" stack, the interceptor responsible for transferring form properties to actions.

And Umesh is correct, if you're using Spring, the plugin handles injection for you, and you do not need to manually define the "autowiring" plugin on your action. If you just remove that interceptor definition, your parameters should be set as normal, and the action should still be wired up.

That said–using a session factory manually inside an action would not be considered a best practice. Any session factory logic should be wrapped up inside your DAOs/services/etc. Actions should rarely (read: never) be aware of the persistence layer.