Announcement

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

    ListGrid select row show record details issue

    Stack : SmartGWT v2.4, GWT sdk 2.1 Mozilla 3.6

    I am fairly new to Smart GWT, but have so far got the ListGrid component working. Our requirement is to show additional details of the record selected in the ListGrid.

    Scenario: ListGrid -->select record --> send request to server to fetch details of the record --> show details of this fetched record as readonly

    Question:
    1. What is the best approach to send HTTP GET request and rendering the JSON response.
    2. We considered using DetailsViewer and Dynamic form. Though DetailsViewer.setData(...) works when we pass the current selected ListGrid record, we want to get more details that is not held in the ListGrid row.

    Tried setting a RestDatasource for detailsViewer, it doesnt show the fetched record in detailsViewer, although we can verify from firebug that the request from datasource.fetchData() is hitting the server(running a java spring MVC application and returns JSON).

    Can you please help what is the best possible approach to retreive JSON data for a record detail from server and show it in a form as read only?

    Thanks
    Sandeep

    PS:
    We are evaluating SmartGWT and will adopt pro version if it fits these common requirements.

    #2
    Thanks to the buggy DetailViewer widget and the tightly coupled datasource, one way i solved is by using core GWT class RequestBuilder.


    Code:
    import com.google.gwt.core.client.JavaScriptObject;
    import com.google.gwt.http.client.Request;
    import com.google.gwt.http.client.RequestBuilder;
    import com.google.gwt.http.client.RequestCallback;
    import com.google.gwt.http.client.RequestException;
    .......
    
    //code to set DetailsViewer from selected record.
            Record selectedRecord  = itemListGrid.getSelectedRecord();  
    	        String eventIdStr =selectedRecord.getAttribute("eventId");
    		String url = "/test/event/"+eventIdStr;
    						
    	        
    	        RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
    	        builder.setHeader("Content-Type", "application/json"); 
    	        builder.setHeader("Accept", "application/json");
    	        
    	        try {
    	          Request response = builder.sendRequest(null, new RequestCallback() {
    				
    				@Override
    				public void onResponseReceived(Request request, Response response) {
    					   String jsonData = response.getText(); 
    					   JSONValue jsonResponse = JSONParser.parseStrict(jsonData);
    					   Record record = new Record();
    					   JavaScriptObject javaScriptObject = jsonResponse.isObject().getJavaScriptObject();
    					   SC.say(javaScriptObject.toString());
    					   
    					   record.setJsObj(javaScriptObject);
    					   eventDetailsViewer.setData(new Record[]{record});
    				}
    				
    				@Override
    				public void onError(Request request, Throwable exception) {
    					
    				}
    			});
    	        } catch (RequestException e) {
    	        	e.printStackTrace();
    	        }
    I hate to answer myself.

    I hope there is a better solution for this trivial problem..
    Last edited by sandeepm; 28 Feb 2011, 08:40.

    Comment

    Working...
    X