This is a migrated thread and some comments may be shown as answers.

Binding to remote data by pure jsp to implement?

6 Answers 174 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jong Woo
Top achievements
Rank 1
Jong Woo asked on 02 Jan 2014, 08:57 AM
(core)jsp without using spring only being implemented Binding to remote data.

test.jsp and test_data.jsp search, sorting, paging, try to implement.

############# /test.jsp ########################
<kendo:grid name='grid' pageable='true' sortable='true' filterable='true' columnMenu='true'>
<kendo:grid-columns>
    <kendo:grid-column title='Order ID' field='orderId' />
  <kendo:grid-column title='Ship Country' field='shipCountry' />
  <kendo:grid-column title='Ship Name' field='shipName' />  
  <kendo:grid-column title='Ship Address' field='shipAddress' />        
</kendo:grid-columns>
<kendo:dataSource pageSize='10' serverPaging='true' serverSorting='true' serverFiltering='true'>
    <kendo:dataSource-transport>             
 <kendo:dataSource-transport-read url='/test_data.jsp' type='POST'  contentType='application/json'/>
 <kendo:dataSource-transport-parameterMap>
  <script>
   function parameterMap(options) {     
    return JSON.stringify(options);                   
   }
  </script>
 </kendo:dataSource-transport-parameterMap>               
    </kendo:dataSource-transport>
    <kendo:dataSource-schema data='data' total='total'>
     <kendo:dataSource-schema-model>
  <kendo:dataSource-schema-model-fields>
      <kendo:dataSource-schema-model-field name='orderId' type='number' />
      <kendo:dataSource-schema-model-field name='shipCountry' type='string' />
      <kendo:dataSource-schema-model-field name='shipName' type='string' />
      <kendo:dataSource-schema-model-field name='shipAddress' type='string' />
  </kendo:dataSource-schema-model-fields>
     </kendo:dataSource-schema-model>
 </kendo:dataSource-schema>
</kendo:dataSource>
<kendo:grid-pageable />
</kendo:grid>

############# /test_data.jsp ########################
<%@ page contentType='text/html; charset=utf-8' %>
<%
 response.setContentType('application/json');
%>
{'orderId':'26','shipCountry':'acanet','shipName':'wdkang','shipAddress':'wdkang'},{'orderId':'27','shipCountry':'acanet1','shipName':'wdkang1','shipAddress':'wdkang1'}

test_data.jsp written as above, but of course "No items to display" coming out.

1. How should receive the parameters test_data.jsp?

2. How would you describe the json data test_data.jsp should I do?


In other words,

header('Content-Type: application/json');$request = json_decode(file_get_contents('php://input'));$result = new DataSourceResult('sqlite:../../sample.db');echo json_encode($result->read('Orders', array('ShipName', 'Freight' => array('type' => 'number') , 'OrderDate', 'OrderID', 'ShipCity'), $request));

Pure jsp, php code above if you want to implement, what should I do?

6 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 02 Jan 2014, 09:08 AM
Hello,

Try making this an array and replace the single quotes with double quotes:

<%@ page contentType='application/json' %>
<% 
 response.setContentType('application/json'); 
%>
[
   {"orderId":"26","shipCountry":"acanet","shipName":"wdkang","shipAddress":"wdkang"}, 
   {"orderId":"27","shipCountry":"acanet1","shipName":"wdkang1","shipAddress":"wdkang1"}
]

Here is a similar question in stackoverflow: http://stackoverflow.com/questions/9124960/how-to-simply-return-json-from-a-jsp


Regards,
Atanas Korchev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Jong Woo
Top achievements
Rank 1
answered on 02 Jan 2014, 10:43 AM
Thank you for the answer.

Revised proposal. Still "No items to display" it comes out.

Do you attach a file created by test_data.jsp test.jsp and ask.

1 question, 1. How should receive the parameters test_data.jsp?
I ask for an answer.
0
Atanas Korchev
Telerik team
answered on 02 Jan 2014, 04:22 PM
Hello,

There are a couple of more issues:

  1. The path to test_data.jsp may not be correct. Try using "test_data.jsp" instead of "/test_data.jsp"
  2. The schema of your data source is configured to expect a different JSON result. You need to change the result like this:
{
"data": [
    {"orderId":"26","shipCountry":"acanet","shipName":"wdkang","shipAddress":"wdkang"}, 
    {"orderId":"27","shipCountry":"acanet1","shipName":"wdkang1","shipAddress":"wdkang1"}
],
"total": 2
}

If you remove the parameterMap setting you will get the data source parameters as POST data which you can retrieve using request.getParameter. Otherwise the data source state is posted as a JSON string.

int p = Integer.parseInt(request.getParameter("page"));

I have attached a working project exported as a war file.

Regards,
Atanas Korchev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Jong Woo
Top achievements
Rank 1
answered on 03 Jan 2014, 12:00 AM
Thank you very much.

There are two kinds of additional questions.

1. page, pageSize, take, skip parameter is the request.getParameter ("page") to accept must be makin How do I sort and filter parameters?

2. <input type="hidden" name="testParam" value="test"> user-defined parameters, such as How should I do?
0
Atanas Korchev
Telerik team
answered on 03 Jan 2014, 07:50 AM
Hello Jong,

The easiest way would be to use a parameterMap and serialize the data source parameters as JSON.

            <kendo:dataSource-transport-parameterMap>
                <script>
                function parameterMap(data, type) {
                     if (type == "read") {
                           return {
                                 testParam: $("[name=testParam]").val(),
                                 grid: JSON.stringify(data)
                           };
                      }
                }
                </script>
               </kendo:dataSource-transport-parameterMap>

Find attached updated files that log the current grid state and user specified data to System.out.
Regards,
Atanas Korchev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Jong Woo
Top achievements
Rank 1
answered on 03 Jan 2014, 09:47 AM
thank you so much.^^

happy new year~!!

Tags
Grid
Asked by
Jong Woo
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Jong Woo
Top achievements
Rank 1
Share this question
or