PDA

View Full Version : How to get changed data from client(extjs grid) uses struts2.0 + extjs3.0 edit grid



pclovec
23 Dec 2009, 10:07 AM
hi, all

i uses java +struts2.0 + extjs grid3.0 + mysql , now i can get json data from server side
(struts2 can auto serialize java class)

now i want to save the data when i changed the grid data. , but i can get error. please refer to below info

1. i create a new action call SavePriceData
2. add new method savepricedata in LoadPriceData class
3. map the action and function:
<action name="LoadPriceData" method="loadpricedata" class="qa.LoadPriceData">
<result type="json"/>
</action>
<action name="SavePriceData" method="savepricedata" class="qa.LoadPriceData">
<result type="json"/>
</action>

4. add new function to handler save function
....
text : 'Save',
tooltip : 'save data',
iconCls : 'save',
handler: function() {
var modified = store.modified;
alert(modified[0]);
updateData(modified);
}

function updateData(modified) {
var json = [];
Ext.each(modified, function(item) {
json.push(item.data);
});

if (json.length > 0) {
Ext.Ajax.request({
url: "SavePriceData",
params: { limit:10,start:0,prices: Ext.util.JSON.encode(json) },
success: function(response) {
Ext.Msg.alert("info", "ok?", function() { store.reload(); });
},
failure: function(response) {
Ext.Msg.alert("info", "faild?");
}
});
}
else {
Ext.Msg.alert("Warning", "There's no data changed?");
}
}


5. i refer to post info
header:
X-Requested-With XMLHttpRequest
Content-Type application/x-www-form-urlencoded; charset=UTF-8

post info:

limit 10
prices [{"close":33.4092955037,"high":34.1482484239,"low":33.2071280333,"open":1,"procdate":"2009-12-15T00:00:00"}]
start 0

6:java class
private List prices = new ArrayList<Price>();
..setfunctin....
..getfunction...

public String savepricedata() throws Exception {
try{
/// how to do:

}
catch(Exception e){
System.out.println(e);
return ERROR;
}
return SUCCESS;
}

public String loadpricedata() throws Exception {
it works .
}


7:give me error info

ec 23, 2009 12:00:48 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger error
SEVERE: Could not find action or result
No result defined for action qa.SavePriceData and result input
at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:364)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:266)
at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:252)
at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:179)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:235)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:89)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:130)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:126)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:138)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:165)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:179)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)
at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:488)
at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:395)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
at java.lang.Thread.run(Thread.java:619)

pclovec
23 Dec 2009, 3:32 PM
if i have removed the prices data point from params list . then it works..

so i think action can receive the limit or start value but cann't get the json list data.

limit18prices[{"close":33.4092955037,"high":34.1482484239,"low":33.2071280333,"open":31,"procdate":"2009-12-15"}]start1

so how to put the prices data into server. have any idea or adivce

thanks


/params: { limit:15,start:1,prices:Ext.util.JSON.encode(json)},
params: { limit:18,start:1,prices:jsonData},

still give me error
SEVERE: Could not find action or result
No result defined for action qa.LoadPriceData and result input
om.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:364)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:266)
.....