It's not a secret anymore!*
The moose likes Struts and the fly likes Displaying bean value in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Displaying bean value in JSP" Watch "Displaying bean value in JSP" New topic
Author

Displaying bean value in JSP

AnilPrakash Raju
Ranch Hand

Joined: Jul 26, 2004
Posts: 137
Hi,

I set a value in the a bean in the action.do

Then i want to get the value in the JSP

e.g. In my Action.do

beanSearch.setValueId(new Long(4));

in my jsp,

the following works:

<html:hidden name="beanSearch" property="valueId"/>

but I want to display the value in the button
eg.

<html:button value="Add New" property="Add New" value="<%=beanSearch.getValueId()%>" />

But this does not work?

What am i doing wrong?

thanks in advance

Anil
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
You've got two "value" attributes in
<html:button value="Add New" property="Add New" value="<%=beanSearch.getValueId()%>" />


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
AnilPrakash Raju
Ranch Hand

Joined: Jul 26, 2004
Posts: 137
Hi,
I removed the first value and tried it. it still does not work. I am getting that it does not recognise the bean.

thanks

Anil
poornima balagopal
Ranch Hand

Joined: Dec 02, 2003
Posts: 83
hi,
i dont know the exact answer for your problem.but check the following things in your program
1) your configuration file
for the mappings
2)in your action class after setting the value to the formbean property , whether you are setting that to the request
i mean
if you have done something like as follows
formobj.setName("somename");//this you want to get displayed on the button
then you have to set the formbean object which holds the value to the request , to get that in the jsp.
so set your formbean object to the request as request.setAttribute("formobj",formObj);
Then in your jsp you can display this as the value of the button .please refer struts user guide for more explanation for this part.
hope it will help you
try like this
all the best
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 5270
    
  10

Anil,

I thought it was already explained why your scriptlet is not working in this other thread that you started but to reiterate:

The html:hidden tag works because Struts tags automatically search all contexts by default for the named bean. Scriptlets, on the other hand, need to have the bean available in the page context by something like jsp:useBean.

Also, the value of your property attribute is invalid. The property attribute must be the name of the ActionForm field that will receive the value associated with the button. Struts will not be able to match "Add New" with any property in your ActionForm.

Try this (you need to give a valid value for property):

<html:button property="...">
<bean:write name="beanSearch" property="valueId" />
</html:button>
[ August 04, 2004: Message edited by: Junilu Lacar ]

Junilu - [How to Ask Questions] [How to Answer Questions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Displaying bean value in JSP