LoginSignup
0
0

More than 3 years have passed since last update.

Firefox上apex:actionFuncionを呼出時の注意事項

Posted at

業務上に実現したいことは以下となります。


一覧にファイルリストがあって、行毎にダウンロードボタンがあります。
そのボタンをボタンを押下したら、あるオブジェクトの更新を行い、更新完了したら、ファイルをダウンロードする
上記の処理は非同期で行うことです。

以下の実装だと、chrome上に問題なく処理されます。

①オブジェクトが正しく更新されます。
②サーバ側の処理が処理完了したら、画面の非同期更新エリアがリフレッシュされます。
③ファイルが正しくダウンロードされます。
Firefox上③のみ有効、①②が効かない。

ファイルダウンロード1.v
<a onclick="fileDownload(id)" />
<apex:actionFunction name="testAction" action="testAction" reRender="testArea">
    <apex:param name="testId" assignTo="{!testId}" />
</apex:actionFunction>

<script>
function fileDownload(id) {
    // 他の業務処理を行う
    testAction(id);
    loaction.href="ファイルパス" + id;
}
</script>

以下のように変更すると、Firefox上に①②も効かないが、ボタンを連続的に押下する場合、①が効きます。

ファイルダウンロード2.v
<a onclick="fileDownload(id)" />
<apex:actionFunction name="testAction" action="testAction" reRender="testArea">
    <apex:param name="testId" assignTo="{!testId}" />
</apex:actionFunction>

<script>
function fileDownload(id) {
    // 他の業務処理を行う
    Function('return this')()['testAction'](id);
    loaction.href="ファイルパス" + id;
}
</script>

以下のように変更すると、ChromeもFirefoxも①②③正しく処理されます。

ファイルダウンロード3.v
<a onclick="fileDownload(id)" />
<apex:actionFunction name="testAction" action="testAction" oncomplete="doDownload()" reRender="testArea">
    <apex:param name="testId" assignTo="{!testId}" />
</apex:actionFunction>

<script>
var testId = null;
function fileDownload(id) {
    // 他の業務処理を行う
    Function('return this')()['testAction'](id);
    testId = id;
}
function doDownload() {
    loaction.href="ファイルパス" + testId;
}
</script>

まとめ(原因分析)

1、Salesforce非同期処理(apex:actionFunction)のName属性は通常意味のJSの関数だと理解していますので、
JSから直接呼出して問題がないかと思います。おそらくChrome上もその通りに解析されるから、問題なく処理される。
だがFirefox上にJS関数を経由し、Salesforce非同期処理(apex:actionFunction)を直接呼出すのは効かない。
原因がわからないが、Functionを利用してラッピングしたら、問題なく利用されます。
2、Firefox上に「loaction.href」を利用すると、「redirect」が変わってしまうから、非同期処理完了後の画面リフレッシュが効かなくなるかと思います。なので、ダウロード処理はoncompleteに移動すれば解決します。
※上記の分析は自分の考えだけですが、全部正しいわけではないが、上記のようにやっておけば、問題が解決できます!
もし本当の原因がわかる方はいらっしゃいましたら、是非教えて頂きたいです。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0