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 Backing Bean question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Backing Bean question" Watch "Backing Bean question" New topic
Author

Backing Bean question

Kim Ming Yap
Ranch Hand

Joined: Dec 17, 2008
Posts: 53

I'm newbie to JSF and i am confused on this portion written by Cay Horstmann in the Core Java server faces:

=======================================================================================================

The code:

public class QuizFormBean {
private UIOutput scoreComponent;
private UIInput answerComponent;
// PROPERTY: scoreComponent
public UIOutput getScoreComponent() { return scoreComponent; }
public void setScoreComponent(UIOutput newValue) { scoreComponent = newValue; }

// PROPERTY: answerComponent
public UIInput getAnswerComponent() { return answerComponent; }
public void setAnswerComponent(UIInput newValue) { answerComponent = newValue; }
...
}

=========================================================================================================

This is the 2nd edition of this book.

When you use a backing bean, you need to wire up the components on the form to those on the bean. You use the binding attribute for this purpose:

<h : outputText binding="#{quizForm.scoreComponent}"/>

When the component tree for the form is built, the getScoreComponent method of the backing bean is called, but it returns null. As a result, an output component is constructed and installed into the backing bean with a call to setScoreComponent.

Question:
if this is correct .. why another output component is created? I dont see the need since a backing bean is both ways - input and output.


=========================================================================================================

This is the 3rd edition of this book.

When you use a backing bean, you need to wire up the components on the form to those on the bean. You use the binding attribute for this purpose:

<h : InputText binding="#{quizForm.answerComponent}"/>

When the component tree for the form is built, the getAnswerComponent method of the backing bean is called, but it returns null. As a result, an output component is constructed and installed into the backing bean with a call to setAnswerComponent .

Question:
If this edition is correct, shouldn't this be input component since answerComponent is of type UIInput?

=========================================================================================================
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16139
    
  21

Just as a rough guess, I'd suspect that the reason an output component was constructed is that an input component would be useless.

An input component is supposed to be able to set a backing bean property, but if you constructed one without any knowledge of what was going in, you'd have no place to put received input data to begin with. So it would be output-only purely because it had no other abilities.

However, direct control binding is overused by JSF programmers anyway. You should really only use it if you intend to make the backing bean dynamically modify the View tree. For most purposes, the "value=" attribute bound to a data property is quite sufficient.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Backing Bean question