• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Gustavo Santos
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Vijitha Kumara
Bartender
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Think of where the scope attribute is going to be set in the <c:set> and how you are trying to retrieve it?
 
Gustavo Santos
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64715
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Lorand Komaromi
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64715
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64715
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64715
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic