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 binding vs value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "binding vs value" Watch "binding vs value" New topic
Author

binding vs value

Kev D'Arcy
Ranch Hand

Joined: Jul 26, 2001
Posts: 75
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
Himanshu Gupta
Ranch Hand

Joined: Aug 18, 2008
Posts: 598

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 ]

My Blog SCJP 5 SCWCD 5
Kev D'Arcy
Ranch Hand

Joined: Jul 26, 2001
Posts: 75
So when I'm manipulating values in my code, should I be using the values on the binding component or the values themselves?
Luca Manenti
Greenhorn

Joined: Nov 15, 2008
Posts: 2
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

Joined: Aug 18, 2008
Posts: 598

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: binding vs value
 
Similar Threads
short cut in a JMenuItem
nx:All of URLy Bird 1.1.3 find and search method
ValueChangeListeners in DataTable
Clearing forms
How to add error message before sendRedirect