Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

textfields value

 
Carlos Mendoza
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18303
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Carlos Mendoza
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Carlos Mendoza
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's right man
maybe i have to try something with javascript, because everything what I have tried does not work.
 
Rohit Boorugu
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you post the code so that i can be more clear.
 
Carlos Mendoza
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
obviously
haha
staticTextTiandasSegmento1Pendientes.setValue("1");
staticTextTiandasSegmento2Pendientes.setValue("1");
staticTextTiandasSegmento3Pendientes.setValue("1");
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic