• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Retrieve values from a bean in JSP

 
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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




 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i thought of using <jsp:get property....etc>, though it is a GSP page. is it possible?
 
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using Grails Framework.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moved to Groovy/Grails forum. Please make sure you choose the best forum for questions; thanks.
 
Acetylsalicylic acid is aspirin. This could be handy too:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic