File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes How to set default value in input text box - jsf Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "How to set default value in input text box - jsf" Watch "How to set default value in input text box - jsf" New topic
Author

How to set default value in input text box - jsf

Preethi Lm
Greenhorn

Joined: Feb 27, 2011
Posts: 9

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

Joined: Jun 25, 2001
Posts: 15665
    
  15

The default value is whatever value was in the property referenced by the 'value=' attribute on the inputTextBox before the view was displayed.


Customer surveys are for companies who didn't pay proper attention to begin with.
Preethi Lm
Greenhorn

Joined: Feb 27, 2011
Posts: 9

Thanks for giving response.


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

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15665
    
  15

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

Joined: Feb 27, 2011
Posts: 9

Thanks Tim for clarifying my doubt
Bishal Ghimire
Greenhorn

Joined: Feb 01, 2011
Posts: 26

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

Joined: Jun 25, 2001
Posts: 15665
    
  15

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

Joined: Apr 01, 2011
Posts: 19
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

Joined: Jan 28, 2008
Posts: 5575

Welcome to JavaRanch nikola!

Please start a new thread for a new question! UseOneThreadPerQuestion
nikola petanjak
Greenhorn

Joined: Apr 01, 2011
Posts: 19
Ok sorry about that, thing is, i didn't wanted to start new thread for something related with default value in input text box.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to set default value in input text box - jsf
 
Similar Threads
tabbing in Netscape
please help a extreme beginner get started?!?
html text box issues
want to display value in a text box
combo box length