Quantcast
Channel: SmartClient Forums
Viewing all articles
Browse latest Browse all 4756

Sending HTML text from server.

$
0
0
Smartgwt version 3.1.

We are using HTMLPane to display HTML content. The HTML content is sent by the server. As of now we are making a servlet call to send the HTML content to the client. But I feel we can achieve this using data source fetch operation. Below is the client code(java):

DataSource ds = DataSource.get("sampleDS"):
DSRequest dsRequest = new DSRequest();
dsRequest.setOperationId("download");
dsRequest.setWillHandleError(true);
Criteria criteria = new Criteria();
criteria.addCriteria("PrimaryKeyID", "34567");
ds.fetchData(criteria, new DSCallback() {

@Override
public void execute(DSResponse response, Object rawData, DSRequest request)
{
if(rawData instanceof String)
{
String data = response.getDataAsString();
GWT.log(data);
}
String data = response.getDataAsString();
GWT.log(data);
String resp = response.getHttpResponseText();
panel.setContents(resp);

}
}, dsRequest);


Server side code:
public void downloadData(DSRequest dsRequest, RPCManager rpc)
{
DSResponse dsResponse = new DSResponse();
try
{
rpc.doCustomResponse();
Map criteria = dsRequest.getCriteria();
String pkID = (String)criteria.remove("PrimaryKeyID");
HttpServletResponse response = rpc.getContext().response;
response.setHeader("Expires", "Sat, 6 May 1995 12:00:00 GMT");
response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
response.addHeader("Cache-Control", "post-check=0, pre-check=0");
response.setHeader("Pragma", "no-cache");
response.setContentType("text/html");
ServletOutputStream out = response.getOutputStream();
String sampleData = "this is sample data\r\n\r\n";
out.write(sampleData.getBytes());
out.flush();
out.close();
dsResponse.setStatus(DSResponse.STATUS_SUCCESS);
rpc.send(dsRequest, dsResponse);
}
catch (Exception e) {
try {
rpc.sendFailure(dsRequest, e.getMessage());
} catch(Exception er) {}
}
}

But with the above code I am unable to display HTML content. Is there a way to read the HTML content from server(smartgwt server) and display the same as aprt of HTMLPane.

Viewing all articles
Browse latest Browse all 4756

Trending Articles