File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Setting Value Attribute of Bean Property in jsp in Struts Application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Setting Value Attribute of Bean Property in jsp in Struts Application" Watch "Setting Value Attribute of Bean Property in jsp in Struts Application" New topic
Author

Setting Value Attribute of Bean Property in jsp in Struts Application

Robert Wiscup
Ranch Hand

Joined: Oct 18, 2009
Posts: 45
Hi All,

In my Struts application I'm trying to set the value attribute of <input> tag in my .jsp. In other words I'm trying to set the initial value of my <input> tag . . .

In regards to the field "ReportDateTime" (next to last line of code shown below) the following code doesn't work. Can someone tell me how to set the value attribute of an <input> tag with a bean property?

Thanks,

Rob




David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Please see the ItDoesntWorkIsUseless entry.

What type of input field is it supposed to be? Is the value you're accessing via JSP EL in any scope?
Robert Wiscup
Ranch Hand

Joined: Oct 18, 2009
Posts: 45
Hi David,

Here's some more info . . .

This .jsp is just simply displaying the values of a given record from the database. So in the "reportDateTime" field I'm just trying to display the date from the (Oracle) database. However, when the code below is run it shows the string "${defect.reportDateTime}" . . . when what I really want is the actual date value of course. So I guess the issue is how do I get the reportDateTime property of the defect bean to display as the initial value in the <input> tag.

Rob
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Are you running a JSP 2.0 container? Is there a value in scope?
Robert Wiscup
Ranch Hand

Joined: Oct 18, 2009
Posts: 45
Hi David,

There is definitely a value in scope because when I execute the following code I can see it:





However, I don't know how to set this property to the value attribute of the <input> tag . . . still working on this . . .

Rob
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Um... why don't you just use the Struts HTML tag, then?

In any case, having the value in a Struts ActionForm, which *is* in scope, isn't the same as having the value *itself* in scope. The value either needs to be in scope, or you need to get it from the action form, if you're not going to put it in scope, or you can just use the convenience tag, which sure seems more reasonable.
Robert Wiscup
Ranch Hand

Joined: Oct 18, 2009
Posts: 45
Hi David,

The problem here is that the <input> tag is part of the dynarch calendar control found here: Dynarch Calendar Control . . . I'm sorry . . . I should've mentioned this in my initial post . . .

So I guess the real issue is how do I set the initial value text (i.e. date as a string) in this control? There has to be a way . . . I just haven't discovered it yet . . .

Also, I'm not sure I understand your "scoping" comments . . . In this case the value is retrieved from the database and put into request scope in the action form with this statement: request.setAttribute("defect", Def);

Rob
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Oh, you never said you were putting it into scope--that's why I asked.

Are you using a JSP 2.0 container?
Robert Wiscup
Ranch Hand

Joined: Oct 18, 2009
Posts: 45
I'm using Apache Tomcat 5.5 in this case
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

What happens if you simply display the scoped value? Are you sure that control allows setting the date in the fashion you're trying to set it? A cursory look at the API suggests that it needs to be initialized in the constructor.
Robert Wiscup
Ranch Hand

Joined: Oct 18, 2009
Posts: 45
This particular field uses a "popup" calendar . . . the date you set in the constructor is what displays on the calendar . . . and I can do this . . . but what I'm trying to do is to set the text in the textbox that appears next to the button that you press to "popup" the calendar to a string that represents the date coming from the database . . .

I did try this approach . . . basically a javascript function gets called when the page loads. I attemp to pass the date to the javascript function but I get the literal string instead of the actual date . . .

********* Javascript Function *****************




************** Calling code in .jsp ***************




David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I suspect the onload is what you want (although a DOM ready would be safer). If you want the textual representation of the date you'd need to give it that rather than a date object.
Robert Wiscup
Ranch Hand

Joined: Oct 18, 2009
Posts: 45
Hi David,

Ok . . . I finally figured out something that works . . .

I did this in the Action Class



and this in the .jsp



I really appreciate your help . . .

Now it's time to work on some Tiles . . .

Rob
 
wood burning stoves
 
subject: Setting Value Attribute of Bean Property in jsp in Struts Application