Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Smart GWT combo box and List grid

    Be sure your post includes:

    I need to display a grid(using ListGrid which is databound)
    On click of one of the field , it should be edited to a combo box and based on the values in other columns of the same row, set of values needs to be populated in the combo box which also retrieves data from backend.

    Following is my code snippet:
    For Grid
    final DataSource dataSource = new DataSource();
    dataSource.setDataFormat(DSDataFormat.JSON);
    String url = GWT.getModuleBaseURL() + "getBonds?fetch=Bonds";
    System.out.println("url here is" + url);
    dataSource.setDataURL(url);


    For combo box

    final DataSource curveListDS = ComboBoxOptionDS.getInstance("Curves");

    OperationBinding fetchCurves = new OperationBinding();
    fetchCurves.setOperationType(DSOperationType.FETCH);
    fetchCurves.setDataProtocol(DSProtocol.GETPARAMS);
    fetchCurves.setDataURL(curveurl);

    curveListDS.setOperationBindings(fetchCurves);


    final SelectItem curveItem = new SelectItem();
    //curveItem.setPickListWidth(210);
    curveItem.setAllowEmptyValue(true);
    curveItem.setOptionDataSource(curveListDS);
    curveItem.setAutoFetchData(true);
    curveItem.setDisplayField("curveName");
    curveItem.setValueField("curveId");
    curveItem.setName("curveName");


    Adding combo box to grid

    final DataSourceTextField CURVE_NAME = new DataSourceTextField(
    "curvveName", "Curve Name");
    CURVE_NAME.setCanEdit(true);
    CURVE_NAME.setEditorType(curveItem);


    grid.addCellClickHandler(new CellClickHandler() {
    Integer colnum = null;

    public void onCellClick(CellClickEvent event) {
    ListGridRecord record = event.getRecord();
    colnum = event.getColNum();
    System.out.println("colnum" + colnum);
    if (colnum.toString().matches("3")) {
    ccy = record.getAttribute("ccy");
    spn = record.getAttribute("spn");
    System.out.println("calling fetchData");
    curveListDS.fetchData();
    System.out.println("exiting fetchdata");
    // curveListDS.updateData(record, callback, requestProperties)
    }

    }
    });

    To create dynamic url on click of each combo box

    protected Object transformRequest(DSRequest dsRequest) {
    System.out.println("inside transformRequest");
    //DSOperationType operationType = request.getOperationType();
    //System.out.println("operationType here"+operationType);
    dsRequest.setPrompt("Hi there " + dsRequest.getDataSource());
    String operationType = dsRequest.getOperationType().toString();
    System.out.println("operationType >>>>"+operationType);
    if (operationType.equals("FETCH")) {
    System.out.println("before" + xmlSerialize(dsRequest.getData()) + "before");
    //JSOHelper.setAttribute(dsRequest.getData(), "spn", spn);
    //String[] values = new String[]{spn,ccy};
    //JSOHelper.setAttribute(dsRequest.getData(), "criteria", values);
    //System.out.println("after " + xmlSerialize(dsRequest.getData()) + "after");
    dsRequest.setActionURL(GWT.getModuleBaseURL()+ "getCurves?fetch=curves&spn="+spn+"&ccy="+ccy);
    }
    super.transformRequest(dsRequest);
    return dsRequest.getData();

    }

    Now , the issue is that eventhoigh I can see that the db is hit , but the combo box is not getting populated with the values from backend.


    The backend data is in json format.
    And the display value should be curvename and its hidden value should be curveId.

    #2
    There's a sample of the suggested pattern for doing this here.

    However, it's not clear whether one of your DataSources is just malfunctioning independently of your attempt to create dependent selects - try troubleshooting that in isolation first, and use the RPC tab of the Developer Console to see requests and responses.

    Comment


      #3
      I have a grid with one of the fields editable which is databound(json format returned from backend).
      This editable field on click should pop up as a combobox and retreive data from backend which is in json format.

      Please find my code as attachment .
      Somehow , I am not able to populate the combobox eventhough I can see the response as

      [{"curveId":"2991","curveName":"ABC"},{"curveId":"1164","curveName":"XYZ"}]

      When I tried to do this independently , it works.

      Or could anyone please provide me a working sample code for the above case?
      Attached Files
      Last edited by renisha; 7 Oct 2010, 06:18.

      Comment


        #4
        The expected format for returned data is here.

        Consider also RestDataSource, which is recommended if you have control over what the server returns.

        If you have no control over what the server returns, you can access the server response via the "data" param, and form a DSResponse from that.

        Comment

        Working...
        X