• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

binding vs value

 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I just have a quick question regard when a value/backing bean should be used over a binding. This is something that there seems to be a lack of clarity over in any of the documentation I've read and seems to cause problems in certain action methods and value change listeners. Typically I use JavaBeans to model my data (lightweight classes that basically have getter/setter methods to hold data) and these are linked via handler classes (which I have set up as managed beans in the faces-config.xml file) to value fields in my JSPs. This all works well on output screens and input forms except in two particular scenarios: a "clear" action to clear the contents of a form and on linked drop down fields (i.e. where the contents of one drop down field determines the contents of another) whose states are maintained by value change listeners. I've found that by manipulating the state of my JavaBeans, these changes are not always reflected in my JSPs because their values seem to be linked to their component bindings.

Can any offer any advice in this area? I should mention that I'm using the Apache Trinidad JSF framework, which seems to have it's own small quirks.

Thanks for any help,

Kev
 
Ranch Hand
Posts: 598
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
binding and values are two really different things. I will give you a short description on both.

Value on one hand is used to assign value to the component while binding is used to bind a component itself to some reference in the backing bean. Then you can change the properties of the binded component in the backing bean itself.

Read this article
[ November 14, 2008: Message edited by: Himanshu Gupta ]
 
Kev D'Arcy
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So when I'm manipulating values in my code, should I be using the values on the binding component or the values themselves?
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I think I have an issue related to this topic.

I have created a HtmlInputText object in the Backing Bean (the getter and setter are in another Bean used to manage the data, getEditableInputText and setEditableInputText)

//getter and setter in Bean
public HtmlInputText getEditableInputText() {
return this.editableInputText;}

public void setEditableInputText(HtmlInputText editableInputText) {
this.editableInputText = editableInputText;

I set the value in the Backin Bean

initializing the component in this way:

HtmlInputText newIT = new HtmlInputText ();
newIT.setId("Test");
newIT.setValue("Luca");
bean.setEditableInputText(newIT);

in the OnContextChange

The HtmlInputText is bound in the jsp page in this way:
<h:inputText id="test" binding="#{Bean.editableInputText}"></h:inputText>

When I load the page I can see the TextField with the value that I set previously (in the backin bean).

The problem is when I try to change the value of the texField:
I change the value, then I click on a button (its action is to call a method to get the value of the field).

In debug mode I see that the value is allways the first set instead of the new value inserted.

I tried with getValue and similar but it does not work.
I tried also to put HtmlInputText in a panel (using a similar logic) and then to get it using getChildren() method but also this does not work.

Is it possible?

Any idea?

Thanks in advance
 
Himanshu Gupta
Ranch Hand
Posts: 598
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Kev D'Arcy:
So when I'm manipulating values in my code, should I be using the values on the binding component or the values themselves?



If you just want to manipulate the values of the field then use value attribute.
 
They weren't very bright, but they were very, very big. Ad contrast:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic