aspose file tools*
The moose likes Groovy and the fly likes Retrieve values from a bean in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Languages » Groovy
Bookmark "Retrieve values from a bean in JSP" Watch "Retrieve values from a bean in JSP" New topic
Author

Retrieve values from a bean in JSP

Maan Suraj
Ranch Hand

Joined: Dec 20, 2007
Posts: 299
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





Man Suraj
Someone says "Impossible is nothing". The man next him says "Let me see you licking your elbow tip!"
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Dec 20, 2007
Posts: 299
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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Dec 20, 2007
Posts: 299
i thought of using <jsp:get property....etc>, though it is a GSP page. is it possible?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61589
    
  67

<g:form>? Not a JSP tag. If you are using a framework, you need to clearly state that.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Maan Suraj
Ranch Hand

Joined: Dec 20, 2007
Posts: 299
I am using Grails Framework.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Moved to Groovy/Grails forum. Please make sure you choose the best forum for questions; thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Retrieve values from a bean in JSP