基本的にCMSシステムへのビューであるVFページがあります。汎用 ID でログインし、Web サービスを使用してファイルのリストを取得および表示できます。ここで、ファイルをクリックして新しいウィンドウで開くことができるようにしたいと考えています。ファイルのバイト ストリームを返す CMS Web サービスがあります。そのストリームをブラウザに返すように Apex リモートアクションを設定するにはどうすればよいですか? さらに、これを新しいタブで開くにはどうすればよいですか?
次のような削除アクションが必要です。
public static HttpResponse sendRequest(String endpoint, String method)
{
HttpRequest req = new HttpRequest();
req.setMethod(method);
req.setEndpoint(endpoint);
HttpResponse resp;
if (Test.isRunningTest())
{
resp = new HttpResponse();
resp.setBody('');
}
else
{
Http http = new Http();
resp = http.send(req);
}
return resp;
}
@RemoteAction
public static HttpResponse open(docid)
{
return sendRequest(API_DOMAIN + '/ws/open/' + docid + '/', 'GET');
}
次に、UI 側で:
MainBehavior.Open= function(docid) {
Visualforce.remoting.Manager.invokeAction(
'{!$RemoteAction.ResourceCenterController.open}',
docid,
function(result, event)
{
if (event.status)
{
return result;
}
else if (event.type === 'exception')
{
alert('Not able to open!\n\n' + event.message);
}
else
{
alert('Not able to open!');
}
}
);
そして後でクリックイベントで:
window.open(MainBehavior.Open(docid), '_blank');
このコードがそのままでは機能しないことはわかっていますが、これが私の目標です。これをどうするかについての提案はありますか?