0

My client side code is as follows where I am sending some data to the server to just print out the output. But when it returns from the server I get a empty listgrid record. what is the cause for this.

Here is the screen shot of the issue

enter image description here

if (fieldName.equals("Approve"))
{
IButton button = new IButton();
button.setHeight(18);
button.setWidth(65);
button.setTitle("Approve");
button.addClickHandler(new ClickHandler()
{
    public void onClick(ClickEvent event)
    {
        DebugTools.print("SOID " + record.getAttribute("supplierOrderID") + " SODID" + record.getAttribute("sodID")+" sordID "+record.getAttribute("sordID"));
        approveProduct(record.getAttribute("supplierOrderID"), record.getAttribute("sodID"),record.getAttribute("sordID"));
    }

private void approveProduct(String supplierOrderID, String sodID, String sordID)
{
    Record record = new Record();
                                record.setAttribute("supplierOrderID", supplierOrderID);
                                record.setAttribute("sodID", sodID);
                                record.setAttribute("sordID",sordID);
                                historyGrid.addData(record, callback);

}

          DSCallback callback = new DSCallback()
{
    @Override
    public void execute(DSResponse response, Object rawData, DSRequest request)
    {
        Record[] records = response.getData();

        if (records != null && records.length > 0)
        {
                             Record record = records[0];
                             JavaScriptObject js = record.getJsObj();                            JSONObject json = new JSONObject(js);                          System.out.println("  records.length    " + records.length);                    for (int i = 0; i < records.length; i++)    {                       Record recordd = records[i];
                                            JavaScriptObject jss = recordd.getJsObj();
                                            JSONObject jsonn = new JSONObject(jss);
                                            System.out.println(jsonn.toString());
                                        }
                                    }
                                }
                            };

and on the server side my add method is very simple for now where I am just printing the data I received from the client

public DSResponse add(DSRequest dsRequest) throws Exception
{
    DSResponse dsResponse = new DSResponse();
    Long user_idlong = SessionUtills.getSessionUser(dsRequest.getHttpServletRequest());

    System.out.println("sodID       " + dsRequest.getFieldValue("sodID").toString());
    System.out.println("PRODUCT APPROVED !!!!!!!!!!!!!" + " SUPPLIER ORDER ID " + dsRequest.getFieldValue("supplierOrderID").toString());
    return dsResponse;

}

I have also attached the shot of the issue

ZAJ
  • 793
  • 3
  • 23
  • 50

1 Answers1

0

The problem is at server side from where you are sending an empty DSResponse back to client hence at client side you are getting zero length records array.

Return a valid DSResponse that contains all the information of the newly added record.


Please have a look at

Must read The basic flow of logic for handling DataSource requests

Braj
  • 46,415
  • 5
  • 60
  • 76
  • thanks for your comments.it was helpful.. Now taking my code as it is and just want to avoid that empty record,what I need to do. I will appreciate your help. – ZAJ Apr 27 '14 at 03:33
  • Why not? Please can you tell me how are your calling `add()` method from client side. – Braj Apr 29 '14 at 06:31
  • Is data added in database? Are you using `ds.xml` file? – Braj Apr 29 '14 at 06:34
  • cheers!!...I have this button which when clicked will fire this method approveProduct(..). In this method I have this addData method which sends the request to the server..historyGrid.addData(record, callback); – ZAJ Apr 29 '14 at 07:04
  • regarding your second comment. yes I am adding the data to the db.but for now I just want to print in the console that the data has been updated but without that issue arising which i have shown in the screenshot – ZAJ Apr 29 '14 at 07:06
  • Braj still waiting for your help – ZAJ Apr 30 '14 at 05:04