Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question on html struts tag

 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,

Let's say I want to retrieve a value from the database and show that in my jsp using the <html:text> tag. Now what value should I give for the value attribute as I will be populating my bean and I want the value from the bean to be displayed in the textbox.

<html:text property = "name" value="??" />

If I only specify the property without a value, then I know that the value will be taken from the associated bean, but I would like to know what if I give a default value and if there is a value in the database, populate that value and if else use the default value.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jothi Shankar Kumar Sankararaj:
I would like to know what if I give a default value and if there is a value in the database, populate that value and if else use the default value

Just override ActionForm's reset(...) method and set default values for the properties there. The default will remain until some other process such as an Action calls the setter to set another value.

I've found it's best to leave out the value attribute entirely and just manipulate the ActionForm property if you want to change the value.
[ April 10, 2008: Message edited by: Merrill Higginson ]
 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's fine but what would it mean when I specify the value = "john" and I don't do anything in my reset () method? the value will always be john despite the actual value that comes from my database. Clarification?
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just don't use the value attribute at all. Manipulate the ActionForm property instead.
 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was thinking in the same lines. Thanks for the reply!
[ April 11, 2008: Message edited by: Jothi Shankar Kumar Sankararaj ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic