Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Question on html struts tag

 
Ranch Hand
Posts: 10192
3
Mac PPC Eclipse IDE 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.
 
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: 10192
3
Mac PPC Eclipse IDE 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: 10192
3
Mac PPC Eclipse IDE 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 ]
 
I knew that guy would be trouble! Thanks tiny ad!
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic