This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Please Note: This Post is lengthy, but question is simple
I have added all these files for more clarity only. I have a section MyQuestion(please scroll down below) for the question
Iam trying to implement cookies for my application.
I have 3 files for the same. 1) A filter class, which intercepts every request 2) PCH class which has methods to handle cookie related things 3) PCD is a simple Java bean with getters and setters for all the fields, of which we want to create a cookie
Create a Persistent cookie. Create only one cookie, with all fields separated by a , symbol. i.e if user enters from date and to date then the cookie will store <FD>,<td> i.e one single string.I implemented like this
1) MyFilter.java (intercepts every request).
//Has a reference to PCH. PCH is a singleton
2)PCH.java ( has methods for handling cookie related tasks)
//Above class has a reference to PCD. PCD is nothing but a Java Bean with all getters and setters for all fields creating cookie.
To handle multiple client requests,(for real time Scenarios),PCD is stored in a ThreadLocal .
3)PCD //getters and setters for all fields
The GSP (Groovy Server pages) , i want to get the PCD from threadLoca object and display the cookie values in the respective GSP
Someone says "Impossible is nothing". The man next him says "Let me see you licking your elbow tip!"
I found your code difficult to read. It also looks like the PCH.getCookieString() method is using an instance variable in a singleton--it's being *loaded* with a ThreadLocal, but it itself is not. Admittedly, I use ThreadLocals only rarely, and not recently, but this strikes me as incorrect.
A couple of code cleanups (in addition to suggesting that you choose a single brace-placement style and stick with it rather than arbitrarily doing same-line/new-line):If this is Groovy (which I'm assuming it is, but only because of that last getCookieValues() method and its property access shortcut), please *state* what language it's in. Refactor your conditionals--they're essentially unreadable:Ew. In general, particularly when it's a mash of characters like this, I wouldn't recommend doing assignments here either.
Joined: Dec 20, 2007
Thanks David for replying.
Let me try to be more clear
You don't actually say what the problem is.
Problem is sinmple
Assume above works."persch" is a static variable." persistcd" is an instance variable in class PCH.
Assume "persch.persistcd", gets reference to a bean object of type PCData .PCData is simply getters and setters.
Now assuming above all works, i want to populate these fields below without using scripts.Currently i am doing below
Now i dont want to use scriptlet to retrieve my value.I want some other option
The framework used is grails and above is a groovy server page