aspose file tools*
The moose likes Struts and the fly likes Variable value attribute in jsp:setProperty Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Variable value attribute in jsp:setProperty" Watch "Variable value attribute in jsp:setProperty" New topic
Author

Variable value attribute in jsp:setProperty

P-A Rosenberg
Greenhorn

Joined: Sep 22, 2005
Posts: 15
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
Pranav Sharma
Ranch Hand

Joined: Oct 27, 2003
Posts: 258
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

Joined: Sep 22, 2005
Posts: 15
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
Jason Menard
Sheriff

Joined: Nov 09, 2000
Posts: 6450
"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.
 
Consider Paul's rocket mass heater.
 
subject: Variable value attribute in jsp:setProperty