11 Replies Latest reply on Aug 21, 2013 5:05 PM by benleg1

    Cookies usage with jDev




      Anyone could point me to a tutorial or code sample on the best usage of cookies with jDev (12c)


      Thanks in advance



        • 1. Re: Cookies usage with jDev
          Timo Hahn

          Cookies are no special Jdev thing. They are handled add in every other application running on the web. Do you can just Google for 'java cookie' and get plenty of results.


          If you have a specific question, please tell it's the use case.



          • 2. Re: Cookies usage with jDev

            I think i'm ok with the manipulation of the cookie themselves (addCookie / getCookies)... the problem is how do i make the link between the my .jsf and the cookieClass...

            (i have some old jsp sample that i was using 12 years ago... but i'm pretty sure that similar syntax is not optimal anymore)

            • 3. Re: Cookies usage with jDev
              Timo Hahn

              If you can share your use case I'm sure we can help you.

              I would say you can get our set your cookies from a bean method out a listener depending on the use case.



              • 4. Re: Cookies usage with jDev
                Frank Nimphius-Oracle



                the link between your JSF and cookies are in one of the following


                1. a PhaseListener (JSF or PagePhaseListener)

                2. Managed bean accessing the FacesContext --> ExternalContext --> Http Request Object

                3. EL on a page #{cookie.CookieName.value}. Or, if the cookie name has dots "." in it #{cookie['CookieName'].value}

                And finally, as a combination of 2 + 3


                4. #{manageBeanname.cookieValue} and the managed bean exposing a property


                String cookieValue = "";


                public void setCookieValue(String v){}

                public String getCookieValue(){

                    FacesContext --> ExternalContext --> Http Request Object --> get and return cookie value





                Ps.: Timo is correct saying that all of this can be found Googling for "cookie" and "JSF" as this is not knowledge specific to ADF. However, at least now you have a nice summary

                • 5. Re: Cookies usage with jDev

                  Thanks, that help a lot!


                  Now with my cookie results, i want to do query my DB. I already create a View Object Class (with parameters)... but I'm not too sure how to access it from my "listener"


                  Thanks again for your help

                  • 6. Re: Cookies usage with jDev
                    Timo Hahn

                    add a methodAction in the pagedef and select the vo and in the vo the method you have created (you have to expose the method to the client interface of the vo).

                    Then you get the method inside your bean and set the parameter and call the method.

                            // GET A METHOD FROM PAGEDEF AND EXECUTE IT

                            // get the binding container

                            BindingContainer bindings = BindingContext.getCurrent().getCurrentBindingsEntry();

                            // get an Action or MethodAction

                            OperationBinding method = bindings.getOperationBinding("YourMethodAction");

                            if (method == null) {

                                // handle method not found error...




                            // if there are parameters to set...

                            Map paramsMap = method.getParamsMap();

                            paramsMap.put("param", "value");

                            // execute the method


                            List errors = method.getErrors();

                            if (!errors.isEmpty()) {

                                // handle errors here errors is a list of exceptions!




                    • 7. Re: Cookies usage with jDev

                      Thanks for the code Timo


                      I'm getting the following error:


                      <Automatically initializing a DefaultContext for getCurrent.

                      Caller should ensure that a DefaultContext is proper for this use.

                      Memory leaks and/or unexpected behaviour may occur if the automatic initialization is performed improperly.

                      This message may be avoided by performing initADFContext before using getCurrent().

                      For more information please enable logging for oracle.adf.share.ADFContext at FINEST level.>


                      I can't really reference to similar problem... could it be that my code is not in the right place:

                      public void sessionCreated(HttpSessionEvent event) {

                      • 8. Re: Cookies usage with jDev
                        Timo Hahn

                        Huh? where do you try to get to the db?

                        From the "public void sessionCreated(HttpSessionEvent event) {" method, which is called where in the lifecylce?

                        If this is the method where the client session is created, then you the ADF Binding layer isn't initialized yet, as the error message tells you. The code was meant to run as a part of an action or actionListener.



                        • 9. Re: Cookies usage with jDev

                          Thanks Timo


                          My goal is to run a query base on information found in the cookie.


                          So I think I need to:

                          1 -  Get info from  cookie in a “Servlet Listener”

                          2-  Use an invokeMethod (page Def) to run my query as the page load.


                          I’m just not sure I’m suppose to connect the 2 (can’t find reference to my listener when i look in expression builder for value that i could pass to my invoked function)

                          I think my inexperience is showing here...

                          • 10. Re: Cookies usage with jDev
                            Timo Hahn

                            Why do you need to call the db from a servletListener?

                            Why no do it e.g. when a task flow is loaded?


                            As I don't understand the use case I can't advice. A servletListener is outside the adf lifecycle so you have to do some hacks to make it work. I would advice that you describe your use case in more detail. We may then be able to give you an alternative.



                            • 11. Re: Cookies usage with jDev

                              Hi Timo,

                              At this stage, I don’t have any preferences on where the DB is query... it just need to be base on information found in the cookie.

                              I think the problem that I describe in my previous post is related to the declaration of my variables (i can find the information i’m looking for in the listener (user id)... i don’t know how to make it visible so that i could use it as a parameter when i “invoke” my query in the page def... )