• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to set default value in input text box - jsf

 
Preethi Lm
Greenhorn
Posts: 9
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,


Can anybody suggest me, how to set default value for input text box (<h:inputText/>)?

Any help is appreciated...

Thanks in advance.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18098
50
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The default value is whatever value was in the property referenced by the 'value=' attribute on the inputTextBox before the view was displayed.
 
Preethi Lm
Greenhorn
Posts: 9
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for giving response.


If <h:inputText value="#{dataBean.value}"/>, then it calls either getValue() or setValue() method ???

 
Tim Holloway
Saloon Keeper
Pie
Posts: 18098
50
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Preethi Lm wrote:Thanks for giving response.


If <h:inputText value="#{dataBean.value}"/>, then it calls either getValue() or setValue() method ???



JSF will call the getValue() method to fetch the data for display (it may do this several times when processing a request). It will invoke setValue() when the user submits the form back to the server.
 
Preethi Lm
Greenhorn
Posts: 9
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Tim for clarifying my doubt
 
Bishal Ghimire
Greenhorn
Posts: 26
Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about if I want to redisplay the default value?

I have a drop down menu, which fires ValueChangeListener, and do some logic inside the method and sets the values for input Text. That's fine. It works perfect before submitting the page. But, if validation fails; I get the same view back and from now onwards it is not able to modify the content of textboxes.

I am using JSF 1.2/Richfaces 3.3
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18098
50
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
valueChangeListener should not set the property value. The JSF framework will do that automatically at the proper time (which isn't at valueChangeListener time).

ValueChangeListener is for things like setting up context - internal objects that don't expose themselves as properties. For example, I zap SelectItem list objects in listeners so that the SelectItem propery get method is put on notice that it needs to build a new (updated) SelectItem List. And DEFINITELY don't call heavy-duty services such as database code in listeners!


When validation fails, the valueChangeListener will not be invoked, because the value will only be updated when it's valid. Likewise, the value set method won't be invoked. The value get method won't be invoked either, since JSF expects you to fix whatever invalid data you entered - it doesn't simply erase all your work and make you start over.
 
nikola petanjak
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

still being new to web programming i have the following problem with inputtext field:



The problem is, it seems like inputHelperDatePicker "overwrites" the initial value="#{bean.someDate} with it's own value, that is, the current date.
I would like the default value from my bean and not the current date to be displayed by default.
Any suggestion would be appreciated.

Nikola
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch nikola!

Please start a new thread for a new question! UseOneThreadPerQuestion
 
nikola petanjak
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok sorry about that, thing is, i didn't wanted to start new thread for something related with default value in input text box.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic