Demo "music" does not work for me

Hi.

I would like to use your Grid.Plugins (from xdatamusic demo) in my test application for crud operations.
I cannot use the entities for build a list of my records (because of a very complex query) and I retrieve data with rawinvoke via XDataWebClient and loaded  the XDataWebDataSet with SetJSONData and it works but  don't know how to make this working with Grid.Plugins... I got the error  "XDataWebDataset : Operation cannot be performed on an active dataset" 
all data from the entity are loaded instead. Is it possible to use Grid.Plugins the way I'm trying?


I don't know exactly how you are using it, since you didn't provide any source code, but that error message simply indicate you should close the dataset before performing the operation you are trying to perform. If you are using SetJSONData, try to close the dataset before calling it.

ok.


this is the code I'm using... what I'm trying to do is to use TGridPlugin with a  TXDataWebDataset I need (I would like) to load with SetJSONData...  data are in FARRAY for further use... 

The question is:  is it possible to use TGridPlugin  with a  TXDataWebDataset not to be loaded with SetJSOData?

thankyou

procedure TFViewLowResourcesList.WebFormCreate(Sender: TObject);
begin

  DoGetLowResourcesByUserId(2);

  FGridPlugin := TGridPlugin.Create(
    WebDBTableControl1,
    XDataWebDataset,
    lcPaginator,
    lbPaginationInfo
  );
  FGridPlugin.SetPageSize(StrToInt(cbPageSize.Text));
  FGridPlugin.SetFilterText(edSearch.Text);
  FGridPlugin.Load;
end;


procedure TFViewLowResourcesList.DoGetLowResourcesByUserId(auid: integer);
  procedure GetBIDSuccess(adata: string);
  var
    js: TJSON;
    jsobj: TJSONObject;
    I: integer;
    json: string;
  begin
    FADATA := adata;
    js := TJSON.Create;
    try
      FJSARRAY := TJSONArray(js.Parse(FADATA));
    finally
      js.Free;
    end;
    XDataWebDataset.SetJSONData(FJSARRAY);
    XDataWebDataset.Open;
  end;

  procedure GetBIDError(AMsg: string);
  begin
  ///
  end;

begin
  ApiService.GetLowResourcesByUSERID(auid , @GetBIDSuccess, @GetBIDError);
end;

more tests... it seems none of the DB aware control can show the data also not using TGridPlugin...


RecordCount for the Xdatawebdataset is 1 when in my JSON array the count is 2232 and if I use webresponsivegrid I can get values from the array... 

I must be confused somewhere...

Can you please provide a sample project reproducing the issue? It's more straightforward so we can check what's going on and provide the solution.

It's also not clear what your server is returning. You must be sure you are providing a JSON array to the dataset. Are you sure of that? I would suggest you log FADATA value to console to see what's there. Maybe your response is an array wrapped in the "value" property of a JSON object. That happens in some XData responses. In this case (hypothetical) you should do it this way:




    FJSARRAY := TJSONArray(TJSONObject(js.Parse(FADATA))['value']));
    XDataWebDataset.SetJSONData(FJSARRAY);


this a sample of FADATA 

[
{"id":6118,"name":"L2.001 - U_47660065 - 10.144.129.2","detail":"Via Savona 12","typeid":6,"visibledetails":""},
{"id":6119,"name":"L2.001 BK - U_47660066 - 10.144.129.3","detail":"Via Savona 12","typeid":6,"visibledetails":""},
{"id":6120,"name":"L2.002 - A_8997203 - 10.144.119.2","detail":"Via del Tempio di Giove 21","typeid":6,"visibledetails":""},
{"id":6121,"name":"L2.002 BK - A_8997213 - 10.144.119.3","detail":"Via del Tempio di Giove 21","typeid":6,"visibledetails":""},
{"id":6122,"name":"L2.003 - A_8997774 - 10.144.31.2","detail":"Circonvallazione Ostiense 191","typeid":6,"visibledetails":""},
{"id":6123,"name":"L2.003 BK - A_8997775 - 10.144.31.3","detail":"Circonvallazione Ostiense 191","typeid":6,"visibledetails":""},
{"id":6124,"name":"L2.004 - U_47687175 - 10.144.157.2","detail":"Piazza Cinecittà 11","typeid":6,"visibledetails":""},
{"id":6125,"name":"L2.004 BK - U_47687176 - 10.144.157.3","detail":"Piazza Cinecittà 11","typeid":6,"visibledetails":""},
{"id":6126,"name":"L2.005 - U_47660069 - 10.144.216.2","detail":"Via Acqua Acetosa Ostiense 5","typeid":6,"visibledetails":""},
{"id":6127,"name":"L2.005 BK - U_47660070 - 10.144.216.3","detail":"Via Acqua Acetosa Ostiense 5","typeid":6,"visibledetails":""}
]

it looks like a JSONArray... and it is correctly parsed into a TJSONArray, I can consume it by code , what I'm loading it in a TXDataWebDataset with .SetJSONData(jsonarray) then .Open but no records are in... 

 

Have you closed the dataset before calling SetJsonData? Have you created the persistent fields in the dataset representing the object properties like id, name, detail, typeid, etc..?

If none of this helps, please send us the project reproducing the issue, if you can reproduce it without using GridPlugin I believe the project would be a simple one, correct?

made the most simple project...  a webmemo with the array:

[
{"id":6118,"name":"L2.001 - U_47660065 - 10.144.129.2","detail":"Via Savona 12","typeid":6,"visibledetails":""},
{"id":6119,"name":"L2.001 BK - U_47660066 - 10.144.129.3","detail":"Via Savona 12","typeid":6,"visibledetails":""},
{"id":6120,"name":"L2.002 - A_8997203 - 10.144.119.2","detail":"Via del Tempio di Giove 21","typeid":6,"visibledetails":""}
]


... xdatawebdataset, webdatasource, webdbtablecontrol  and a webbutton, persistent fields created... 

the unit looks like this:


uses
  System.SysUtils, System.Classes, JS, Web, WEBLib.Graphics, WEBLib.Controls,
  WEBLib.Forms, WEBLib.Dialogs, WebLib.JSON, Vcl.Controls, WEBLib.Grids,
  WEBLib.DBCtrls, Vcl.StdCtrls, WEBLib.StdCtrls, Data.DB, XData.Web.JsonDataset,
  XData.Web.Dataset, WEBLib.DB, WEBLib.CDS;

type
  TForm1 = class(TWebForm)
    WebButton1: TWebButton;
    WebMemo1: TWebMemo;
    WebDBTableControl1: TWebDBTableControl;
    WebDataSource: TWebDataSource;
    XDataWebDataset: TXDataWebDataSet;
    XDataWebDatasetid: TXDataWebEntityField;
    XDataWebDatasetname: TXDataWebEntityField;
    XDataWebDatasetdetail: TXDataWebEntityField;
    XDataWebDatasetvisibledetails: TXDataWebEntityField;
    XDataWebDatasettypeid: TXDataWebEntityField;
    procedure WebButton1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.WebButton1Click(Sender: TObject);
var
    FADATA: string;
    FJSARRAY: TJSONArray;
    js: TJSON;
begin


    FADATA := WebMemo1.Lines.Text;
    js := TJSON.Create;
    try
      FJSARRAY :=  TJSONArray(TJSONObject(js.Parse(FADATA)));
    finally
      js.Free;
    end;

    XDataWebDataset.Close;
    XDataWebDataset.SetJSONData(FJSARRAY);
    XDataWebDataset.Open;


end;

end.

some tests.... if the fields are defined as  XdatawebEntityField  no values are displayed but "null"
if defined as integer or string only the headers are displayed....

if I remember well EntitySetName and Connection were required but they are not  with 1.2.5.4?

maybe you could  provide a working simple project? 




I realize now that the problem in your code is that you are using TJSONArray and other Json classes from WebLib.JSON, which are there for Delphi compatibility, but you cannot cast "real" JavaScript arrays and objects to it. You should use TJS* classes from JS unit. Here is the correct code. Also, you should define the persistent fields in the dataset representing the JSON properties:




procedure TForm4.WebButton1Click(Sender: TObject);
var
  FADATA: string;
  FJSARRAY: TJSArray;
begin
  FADATA := WebMemo1.Lines.Text;
  FJSARRAY := TJSArray(TJSJson.Parse(FADATA));


  xdatawebdataset1.Close;
  xdatawebdataset1.SetJsonData(FJSARRAY);
  xdatawebdataset1.Open;
end;


GOOD! This is working!

thankyou

GOOD! This is working!

thankyou
[/QUOTE]

ok. now 2 more thing to ask (not the last I guess)...

TJS* classes in JS unit are OK for loading a XDataWebDataSet with SetJSONData but I've a field in my table that is a JSON Object created with standard Delphi  JSON routines: 

{"fields":
[
{"caption":"Codice NIS","name":"NIS","dataType":1,"value":"U_47687206","valueList":"","visible":"S"},
{"caption":"CPE","name":"CPE","dataType":1,"value":"rm-cpe-co256-1813","valueList":"","visible":"S"},
{"caption":"INDIRIZZO","name":"INDIRIZZO","dataType":1,"value":"Via Caprilli 11","valueList":"","visible":"S"}
]
}

I parsed it in a JSArray and iterating trough its Elements, with the debugger, I can see it is ok. 
I can access name and value for each Pair?  

Saw a Foreach method in TJSArray class but I don't know how to define the callback procedure, where I can find documentation about JS unit's classes?

The JS classes are direct wrappers for Javascript objects, like Array and Object. It has the same properties and methods: 


https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object

Your code should be parsed as TJSObject and you get the fields value. For example:


arr := TJSArray(TJSObject(TJSJson.Parse(data))['fields']);
for I := 0 to arr.length - 1 do
  // access arr directly

Hi i now updated my TMSWebCoreSetupWrapper to last version and i have same error !!!!!

I'm having the same issue. Delphi 11 - Web Core 2.0.4.0 - XDATA 5.8.0.0
Tried with all the solutions shown in this post but without results.
Any suggestions?

[2022-10-03 16:10:48.414] [INFO] Auth server module listening at "http://+:2001/tms/xdata/music/auth"
[2022-10-03 16:10:48.708] [INFO] Api server module listening at "http://+:2001/tms/xdata/music/api"
[2022-10-03 16:10:48.708] [INFO] Servers started. Press ENTER to stop.
[2022-10-03 16:11:01.630] [INFO] GET /tms/xdata/music/auth/$model HTTP/1.1
[2022-10-03 16:11:05.832] [INFO] OPTIONS /tms/xdata/music/auth/LoginService/Login/ HTTP/1.1
[2022-10-03 16:11:05.834] [INFO] POST /tms/xdata/music/auth/LoginService/Login/ HTTP/1.1
[2022-10-03 16:11:05.841] [INFO] OPTIONS /tms/xdata/music/api/$model HTTP/1.1
[2022-10-03 16:11:05.847] [INFO] GET /tms/xdata/music/api/$model HTTP/1.1
[2022-10-03 16:11:05.847] [INFO] 401 Unauthorized on GET /tms/xdata/music/api/$model HTTP/1.1

Since version 5.7, XData requires the JWT secret to have a minimum size.
To quickly fix this in the demo, just open unit Common.Config and set the JwtTokenSecret to a longer size:

constructor TServerConfig.Create;
begin
  AdminPassword := 'admin';
  JwtTokenSecret := 'this_should_be_just_a_random_secret';
  Urls := [DefaultServerUrl];
end;

Demo will be updated in the next release.

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.