Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Retrieve values from a bean in JSP

 
Maan Suraj
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

Agenda
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




 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't actually say what the problem is.

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.
 
Maan Suraj
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks David for replying.
Let me try to be more clear
You don't actually say what the problem is.

Problem is sinmple
GSP code



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

Thanks in advance
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wouldn't you just put the same object into the page's model and get it normally? Or with ${} notation? Or fill the value in the controller and use the text input tag?

GSP Intro
 
Maan Suraj
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i thought of using <jsp:get property....etc>, though it is a GSP page. is it possible?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64700
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<g:form>? Not a JSP tag. If you are using a framework, you need to clearly state that.
 
Maan Suraj
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using Grails Framework.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moved to Groovy/Grails forum. Please make sure you choose the best forum for questions; thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic