• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Variable value attribute in jsp:setProperty

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I'm using a combination of struts and JSP, I use jsp:useBean to call a Bean class that returns objects used to populate my jsp pages. I'm using jsp:setProperty to set attributes in the bean used to determine what information to retrieve from the database.

This works well:
<jsp:useBean id="userbean" scope="session" class="mybeans.UserBean"/>
<jsp:setProperty name="userbean" property="userId" value="12345"/>

I would like to send a variable from my JSP page into the value attribute of the setProperty tagg, like this:
<jsp:useBean id="userbean" scope="session" class="mybeans.UserBean"/>
<jsp:setProperty name="userbean" property="userId" value="${user_id}"/>

This is not supported by the setProperty tag, is there another way to do it? Does anyone undstand what I try to do and have a solution on it?

I guess there is a "struts way" to do it. I know that I'm supposed to use actions to populate my JSP pages but since my webb only contains information and not any user input I found it overkill to build action classes just to populate the jsp pages with information from my database. I have searched the webb for hours but I don't seem to get it...

Thanx in advance
Perros
 
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry i dont know how u would do it using jsp:..

but the action you would have used to populate the jsp, would also be used to set the values. actually come to think of it, thats all struts does.

So maybe u could post the question in the servlets forum.

ps. does'nt perros mean bitch
 
P-A Rosenberg
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi and thanx' for the response.


"but the action you would have used to populate the jsp, would also be used to set the values. actually come to think of it, thats all struts does."



I realize that actions can be used to pre populate a form but I don't realize the power of actions when it comes to read information from a database and display it on a page with just information. Please convince me!

Lets say I have a simple web where a user can logg in and based on the user_id of the user the web displays all registered details about the user that logged in, Name, address etc. No forms are used on the page. Do I gain anything from using struts in this situation?

I have built a model layer with service classes, one of them is a userService that uses Spring to retrieve data from an Oracle database through stored procedures. The service class creates a user object called userDTO and populates this object with all information about a user. This object is returned to my userBean class and made available to the JSP page through the user of jsp:useBean and jsp:getProperty. If I use an action class the action class can call the service class instead and retrieve the userDTO object. If I were to populate a form I would set the attributes of my actionform to the values from the userDTO and have my form pre-populated.

What do I do when I don't have a form to populate?
How can I make my userDTO object available for my JSP page so I can use the syntax to display the name of the user?


Ps. I wasn't aware that I chose an inappropriate nickname, I used an abreviation of my first and lastname and it ended up as the bad word, I have changed it =)

Thankyou for your time.
//PA
 
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"PA",

Welcome to JavaRanch. We don't have many rules here, but we do have a naming policy which we try to strictly enforce. Please re-read this document and edit your display name in order to comply. Thanks in advance, and we look forward to seeing you around the Ranch.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic