aspose file tools*
The moose likes JSF and the fly likes textfields value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "textfields value" Watch "textfields value" New topic
Author

textfields value

Carlos Mendoza
Greenhorn

Joined: Sep 14, 2009
Posts: 22
Hi do you know which is the best (or correct) way to set a textfield's value? By binding its component's value to a bean property or binding its component's instance to a bean property.
If i bind its component's value to a bean property, the text field doesn't show the value after submit.
thanks in advance.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16250
    
  21

I usually recommend binding to the value. It makes for simpler code and less dependency on the framework. You'd bind to the component primarily if you had a need to alter the component's properties at runtime, and that's relatively uncommon.


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

Joined: Sep 14, 2009
Posts: 22
ok ok, for example i need to copy the value from a static text field to a text field, after submit, so in this case i should bind the component's instance to a bean property, right?

Hatem Alimam
Ranch Hand

Joined: Dec 14, 2008
Posts: 30
Carlos Mendoza wrote:
If i bind its component's value to a bean property, the text field doesn't show the value after submit.


I believe you are losing the value because your backing bean on the request-scope.
try to put it on the session-scope and see what happens.

Best Regards.


SCJP 5.0, SCWCD 1.4, SCBCD 3.0 with 100 score
Carlos Mendoza
Greenhorn

Joined: Sep 14, 2009
Posts: 22
it works, but i have one text field inside a table Column and that text field is visible after an action's button is fired and that text field's value doesn't change, i mean the text field's value is blank by default. The goal is that when i fire an action by clicking a button, the text field's value copy the static text's value, and display it.

thank you.
Hatem Alimam
Ranch Hand

Joined: Dec 14, 2008
Posts: 30
You mean that you have field in the backing bean or managed bean you want the textfield to display it after an action ?
Carlos Mendoza
Greenhorn

Joined: Sep 14, 2009
Posts: 22
That's right man
maybe i have to try something with javascript, because everything what I have tried does not work.
Rohit Boorugu
Greenhorn

Joined: Oct 06, 2009
Posts: 14
Hey carlos, I am not sure what exactly you want but based on my understanding i think this is what you shoudl be doing.

<h:inputText value="#{backingBean.value}">

backing bean

setValue(String value)
{
this.value=value;
}

String getValue()
{
setValue(getValue());
return value;
}

the statement in the bold should keep you value in the textfield.

Hope this helps.
Carlos Mendoza
Greenhorn

Joined: Sep 14, 2009
Posts: 22
Ok , Rohit i am trying to make a java server faces table "editable", by setting visible and not visible, static text and text field, the objective is that when i click on a button, hide the static text and show the text field and copy the static 's value to the text field, your suggestion works fine when the text field is not wrapped in a component, but in this case the text field is inside a column table and doesn't works, it's weird.




Rohit Boorugu
Greenhorn

Joined: Oct 06, 2009
Posts: 14
can you post the code so that i can be more clear.
Carlos Mendoza
Greenhorn

Joined: Sep 14, 2009
Posts: 22
Ok this is the jsp code.




i have tried this in a button's action :
staticTextTiandasSegmento1Pendientes.setValue();
staticTextTiandasSegmento2Pendientes.setValue();
staticTextTiandasSegmento3Pendientes.setValue();

but this doesn't changes the text field's value after the pages reloads.

Carlos Mendoza
Greenhorn

Joined: Sep 14, 2009
Posts: 22
obviously
haha
staticTextTiandasSegmento1Pendientes.setValue("1");
staticTextTiandasSegmento2Pendientes.setValue("1");
staticTextTiandasSegmento3Pendientes.setValue("1");
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: textfields value