LoginSignup
1
2

More than 3 years have passed since last update.

Apexでcookieを扱う

Posted at

ちょっと普通のcookieと違う

apexでcookieを扱う際にはちょっとした注意が必要になります。

スクリーンショット 2019-09-13 19.39.56.png

スクリーンショット 2019-09-13 19.40.41.png

こんな感じでapex__がつきます。

保存の仕方としてはapexで保存する方法と、Javascriptを使う方法があります。

今回はjavascriptで保存し、apex側で呼び出してセットしてみました。

sample.js
function hoge(){
            actfun();
            //入力内容を取得
            var pname = $("[id*=pname]").val();
            var pfamily = $("[id*=pfamily] option:selected").val();
            var pcode = $("[id*=pcode]").val();
            //パスの指定
            var path = "path=/";
            document.cookie = 'apex__conditions.Name='+pname;
            document.cookie = 'apex__conditions.Family=' + pfamily;
            document.cookie = 'apex__conditions.ProductCode=' + pcode;
        }
sample.apex
    public String getNameval() {
        //'apex__'を外したcookie名を指定して取得する
        Cookie Name = ApexPages.currentPage().getCookies().get('conditions.Name');
        return Name == null ? '' : Name.getValue();
    }

こんな感じで取得します。

それ以外は他のcookieとほとんど変わらない挙動かと思います。

注意点はapex__こいつってことですね。

1
2
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
1
2