* Fixed and simplified example

git-svn-id: trunk@15817 -
This commit is contained in:
michael 2010-08-15 14:56:37 +00:00
parent a9adb698cb
commit 1e0228d72b

View File

@ -24,6 +24,7 @@ type
AResponse: TResponse; var Handled: Boolean); AResponse: TResponse; var Handled: Boolean);
private private
{ private declarations } { private declarations }
procedure GetAdaptorAndFormatter(P : TFPWebDataProvider; Var F :TExtJSDataFormatter; ARequest : TRequest; AResponse : TResponse);
public public
{ public declarations } { public declarations }
end; end;
@ -55,6 +56,26 @@ begin
end; end;
end; end;
procedure TFPWebModule1.GetAdaptorAndFormatter(P : TFPWebDataProvider; Var F :TExtJSDataFormatter; ARequest : TRequest; AResponse : TResponse);
begin
If Request.QueryFields.values['format']='xml' then
begin
F:=TExtJSXMLDataFormatter.Create(Self);
TExtJSXMLDataFormatter(F).TotalProperty:='total';
AResponse.ContentType:='text/xml';
P.Adaptor:=TExtJSXMLWebdataInputAdaptor.Create(Nil);
end
else
begin
P.Adaptor:=TExtJSJSonWebdataInputAdaptor.Create(Nil);
F:=TExtJSJSONDataFormatter.Create(Self);
end;
P.Adaptor.Request:=ARequest;
F.Adaptor:=P.Adaptor;
F.Provider:=P;
end;
procedure TFPWebModule1.TFPWebActions0Request(Sender: TObject; procedure TFPWebModule1.TFPWebActions0Request(Sender: TObject;
ARequest: TRequest; AResponse: TResponse; var Handled: Boolean); ARequest: TRequest; AResponse: TResponse; var Handled: Boolean);
@ -69,19 +90,9 @@ Var
begin begin
// Providername; // Providername;
PN:=ARequest.GetNextPathInfo; PN:=ARequest.GetNextPathInfo;
// P:=GetWebDataProvider(PN);
P:=TFPWebDataProvider.Create(Self); P:=TFPWebDataProvider.Create(Self);
try try
P.Adaptor:=TWebDataInputAdaptor.Create(Self); GetAdaptorAndFormatter(P,F,ARequest,AResponse);
P.Adaptor.Request:=ARequest;
If Request.QueryFields.values['format']='xml' then
begin
F:=TExtJSXMLDataFormatter.Create(Self);
TExtJSXMLDataFormatter(F).TotalProperty:='total';
AResponse.ContentType:='text/xml';
end
else
F:=TExtJSJSONDataFormatter.Create(Self);
{$ifdef wmdebug} SendDebug(className+' '+F.ClassName);{$endif} {$ifdef wmdebug} SendDebug(className+' '+F.ClassName);{$endif}
try try
DS:=TDatasource.Create(Self); DS:=TDatasource.Create(Self);
@ -90,11 +101,9 @@ begin
DS.Dataset:=DBf1; DS.Dataset:=DBf1;
DBF1.Open; DBF1.Open;
try try
F.ADaptor:=P.Adaptor;
P.Datasource:=DS; P.Datasource:=DS;
P.Adaptor.Action:=wdaRead; P.Adaptor.Action:=wdaRead;
P.ApplyParams; P.ApplyParams;
F.Provider:=P;
M:=TMemoryStream.Create; M:=TMemoryStream.Create;
try try
F.GetContent(ARequest,M,Handled); F.GetContent(ARequest,M,Handled);
@ -137,18 +146,7 @@ begin
P:=TFPWebDataProvider.Create(Self); P:=TFPWebDataProvider.Create(Self);
try try
P.IDFieldName:='ID'; P.IDFieldName:='ID';
If Request.QueryFields.values['format']='xml' then GetAdaptorAndFormatter(P,F,ARequest,AResponse);
begin
F:=TExtJSXMLDataFormatter.Create(Self);
AResponse.ContentType:='text/xml';
P.Adaptor:=TWebDataInputAdaptor.Create(Self);
end
else
begin
F:=TExtJSJSONDataFormatter.Create(Self);
P.Adaptor:=TExtJSJSonWebdataInputAdaptor.Create(Self);
end;
P.Adaptor.Request:=ARequest;
{$ifdef wmdebug} SendDebug(className+' '+F.ClassName);{$endif} {$ifdef wmdebug} SendDebug(className+' '+F.ClassName);{$endif}
try try
DS:=TDatasource.Create(Self); DS:=TDatasource.Create(Self);
@ -157,11 +155,9 @@ begin
DS.Dataset:=DBf1; DS.Dataset:=DBf1;
DBF1.Open; DBF1.Open;
try try
F.ADaptor:=P.Adaptor;
P.Datasource:=DS; P.Datasource:=DS;
P.Adaptor.Action:=wdaInsert; P.Adaptor.Action:=wdaInsert;
P.ApplyParams; P.ApplyParams;
F.Provider:=P;
M:=TMemoryStream.Create; M:=TMemoryStream.Create;
try try
F.GetContent(ARequest,M,Handled); F.GetContent(ARequest,M,Handled);
@ -205,19 +201,7 @@ begin
P:=TFPWebDataProvider.Create(Self); P:=TFPWebDataProvider.Create(Self);
try try
P.IDFieldName:='ID'; P.IDFieldName:='ID';
If Request.QueryFields.values['format']='xml' then GetAdaptorAndFormatter(P,F,ARequest,AResponse);
begin
{$ifdef wmdebug} SendDebug('Update request received in XML');{$endif}
F:=TExtJSXMLDataFormatter.Create(Self);
AResponse.ContentType:='text/xml';
P.Adaptor:=TWebDataInputAdaptor.Create(Self);
end
else
begin
F:=TExtJSJSONDataFormatter.Create(Self);
P.Adaptor:=TExtJSJSonWebdataInputAdaptor.Create(Self);
end;
P.Adaptor.Request:=ARequest;
{$ifdef wmdebug} SendDebug(className+' '+F.ClassName);{$endif} {$ifdef wmdebug} SendDebug(className+' '+F.ClassName);{$endif}
try try
DS:=TDatasource.Create(Self); DS:=TDatasource.Create(Self);
@ -226,11 +210,9 @@ begin
DS.Dataset:=DBf1; DS.Dataset:=DBf1;
DBF1.Open; DBF1.Open;
try try
F.ADaptor:=P.Adaptor;
P.Datasource:=DS; P.Datasource:=DS;
P.Adaptor.Action:=wdaUpdate; P.Adaptor.Action:=wdaUpdate;
P.ApplyParams; P.ApplyParams;
F.Provider:=P;
M:=TMemoryStream.Create; M:=TMemoryStream.Create;
try try
F.GetContent(ARequest,M,Handled); F.GetContent(ARequest,M,Handled);
@ -274,18 +256,7 @@ begin
P:=TFPWebDataProvider.Create(Self); P:=TFPWebDataProvider.Create(Self);
try try
P.IDFieldName:='ID'; P.IDFieldName:='ID';
If Request.QueryFields.values['format']='xml' then GetAdaptorAndFormatter(P,F,ARequest,AResponse);
begin
F:=TExtJSXMLDataFormatter.Create(Self);
AResponse.ContentType:='text/xml';
P.Adaptor:=TWebDataInputAdaptor.Create(Self);
end
else
begin
F:=TExtJSJSONDataFormatter.Create(Self);
P.Adaptor:=TExtJSJSonWebdataInputAdaptor.Create(Self);
end;
P.Adaptor.Request:=ARequest;
{$ifdef wmdebug} SendDebug('className '+F.ClassName);{$endif} {$ifdef wmdebug} SendDebug('className '+F.ClassName);{$endif}
try try
DS:=TDatasource.Create(Self); DS:=TDatasource.Create(Self);
@ -294,11 +265,9 @@ begin
DS.Dataset:=DBf1; DS.Dataset:=DBf1;
DBF1.Open; DBF1.Open;
try try
F.ADaptor:=P.Adaptor;
P.Datasource:=DS; P.Datasource:=DS;
P.Adaptor.Action:=wdaDelete; P.Adaptor.Action:=wdaDelete;
P.ApplyParams; P.ApplyParams;
F.Provider:=P;
M:=TMemoryStream.Create; M:=TMemoryStream.Create;
try try
F.GetContent(ARequest,M,Handled); F.GetContent(ARequest,M,Handled);