This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes JSP and the fly likes A little issue with <c:set ...> Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "A little issue with <c:set ...>" Watch "A little issue with <c:set ...>" New topic
Author

A little issue with <c:set ...>

Gustavo Santos
Ranch Hand

Joined: Jan 22, 2009
Posts: 40
I'm having a problem attempting to get an attribute that has been set in a JSP, I'm using Struts as a framework and the Action class is where I wanna get the attribute that's been set.


JSP:


Action:


Can anyone give me a hand please???

Regards.
Lorand Komaromi
Ranch Hand

Joined: Oct 08, 2009
Posts: 276
Gustavo Santos wrote:I'm having a problem attempting to get an attribute that has been set in a JSP, I'm using Struts as a framework and the Action class is where I wanna get the attribute that's been set.


What is the relationship of this JSP and the Action class? If the JSP is the view of the action, it's rendered AFTER the action method has returned!

Why would you like to set those values in the JSP?


OCJP 6 (93%)
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3827

Think of where the scope attribute is going to be set in the <c:set> and how you are trying to retrieve it?


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Gustavo Santos
Ranch Hand

Joined: Jan 22, 2009
Posts: 40
Lorand Komaromi wrote:
Gustavo Santos wrote:I'm having a problem attempting to get an attribute that has been set in a JSP, I'm using Struts as a framework and the Action class is where I wanna get the attribute that's been set.


What is the relationship of this JSP and the Action class? If the JSP is the view of the action, it's rendered AFTER the action method has returned!

Why would you like to set those values in the JSP?


I got the values from a form and when I click on another link, I want the same values that has been set on that form to be used on the "contact_action", does that make sense?



Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61103
    
  66

Well, using <c:set> to place the values into page scope just isn't going to accomplish anything.

Why aren't you just submitting the values as parameters? Why all the complications?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Lorand Komaromi
Ranch Hand

Joined: Oct 08, 2009
Posts: 276
Gustavo Santos wrote:I got the values from a form and when I click on another link, I want the same values that has been set on that form to be used on the "contact_action"


Pass them to the action as GET parameters. I don't know how to do that in Struts 1.
Gustavo Santos
Ranch Hand

Joined: Jan 22, 2009
Posts: 40
OK! Thank you so much guys! I passed it as a parameter... does anyone know how to pass more than just one parameter???

anyway, It turned out that I got another issue... which is that I want to pass a Map to another Action, shouldn't I set it as an Attribute then retrieve it on my Action ?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61103
    
  66

You can pass as many parameters as you want. Do you think forms are limited to a single field?

Scoped variables (the proper term for "attributes") placed in session scope should be used sparingly across requests. Check your logic for a design flaw before proceeding. Why do you need to pass this data around?
Gustavo Santos
Ranch Hand

Joined: Jan 22, 2009
Posts: 40
alright... now I got how to pass more than one String parameter, by using:



now the issue is... how can I pass a Map to another Action class? through an Attribute or what?
Gustavo Santos
Ranch Hand

Joined: Jan 22, 2009
Posts: 40
Bear Bibeault wrote:You can pass as many parameters as you want. Do you think forms are limited to a single field?

Scoped variables (the proper term for "attributes") placed in session scope should be used sparingly across requests. Check your logic for a design flaw before proceeding. Why do you need to pass this data around?


I want to pass the Map because I can use it instead of doing another search on my DataBase.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61103
    
  66

Then why aren't you caching it in the data access layer? Passing it around in the presentation layer is just a mess.
Gustavo Santos
Ranch Hand

Joined: Jan 22, 2009
Posts: 40
Bear Bibeault wrote:Then why aren't you caching it in the data access layer? Passing it around in the presentation layer is just a mess.


Thanks for the quick reply! but I'm sorry this is the first project (with JSP & Struts I mean) I'm working on and I have no idea what you're talking about, can you please be a little bit more specific?

Many thanks!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61103
    
  66

Any such caching for DB performance reasons is not the job of the UI (presentation layer). Whatever layer you have designed to fetch the data from the DB should be abstracting that process from the UI and can be written to cache the data rather than having to go back to the DB each time.

But this should be entirely transparent to the UI code.

Mixing data access code into the UI is a very, very, and did I mention very, poor practice.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A little issue with <c:set ...>