what is backing bean

来源:互联网 发布:怎么找到淘宝客旺旺 编辑:程序博客网 时间:2024/06/04 08:42

from http://groundside.com/blog/DuncanMills.php?p=457&more=1&c=1&tb=1&pb=1

So what is a Backing Bean?

I was chatting with Grant about his quest to clarify all things JSF and ADF for mortals and the question of how best to define a Backing Bean came up.
It's a constant sticking point with JSF newbies and those of us already in the club are notoriously sloppy about our usage of backing bean and managed mean.
The question often comes up as What's the difference between a Managed Bean and a Backing Bean?
The answer is of course none at all.

[More:]

Backing Beans are mearly a convention, a subtype of JSF Managed Beans which have a very particular purpose. There is nothing special in a Backing Bean that makes it different from any other managed bean apart from its usage.
What makes a Backing Bean is the relationship it has with a JSF page, it acts as a place to put component references and Event code. It "backs" the page, geddit?
So here's a rough set of guidelines about what defines a Backing Bean:
Backing Beans should:

 

  1. Be defined in the request scope
  2. Exist in a one-to-one relationship with a particular page
  3. Hold all of the page specific event handling code

Backing Beans should not:

  1. Hold state

How the bean is created (automatically or manually) does not matter although in the case of other IDEs then there may be a more "hardcoded" relationship between the page and its Backing Bean.
In JDeveloper you will see that automatically created Backing Beans (from the JSF page wizard) will be marked with a comment in the faces config:
<!--oracle-jdev-comment:managed-bean-jsp-link:1p1.jsp-->
This comment (along with a corresponding one in the page) is used by the IDE to automatically create component references in the bean as those components are added to the page. However, this is just a convention used by the IDE and has no meaning in purely JSF terms.
Perhaps we should try and strike the term Backing Bean from the lexicon to prevent this confusion in the first place, however, I find it a useful concept and will no doubt continue to use it.

Do you have a better defintion of Backing Bean? Let me know in a comment and we'll see if we can come up with a grand unified defintion.

03:19:16 pm . 03/08/06 . Duncan Mills . JavaServer Faces . 9 comments

Comments:

Comment from: John Flack [Visitor] · http://www.smdi.com/employee/JohnF/
I do notice that when you let JDeveloper create a backing bean when you create the page, you get the following at the top of the class definition:

private DCBindingContainer bindingContainer;
public void setBindingContainer (DCBindingContainer bc) {this.bindingContainer = bc;}
public DCBindingContainer getBindingContainer() {return bindingContainer;}


Plus you get this property of the managed bean in faces-config.xml:

<managed-property>
<property-name>bindingContainer</property-name>
<property-class>oracle.adf.model.binding.DCBindingContainer</property-class>
<value>#{bindings}</value>
</managed-property>
Permalink 03/08/06 @ 17:56

Comment from: Duncan Mills [Member]
You get this managed property addded when you have ADF Bindings in the page and do something like double clicking on a commandButton which is bound to an operation. At this point JDeveloper writes in a code stub for your to customise and it needs the binding reference for that. However, this is another convenience and is not an intrinsic feature of a Backing bean
Permalink 04/08/06 @ 10:11

Comment from: Shawna [Visitor]
Hey Duncan! I found you from a link to a link to another blog to a link!! Whew! I'm a recruiter searching for Java experts. Any chance you can send your resume to me please? scoronado@solpart.com

Thanks!

Shawna
Permalink 04/08/06 @ 14:16

Comment from: Samba Siva Rao Kolusu [Visitor]
Hi Mr.Duncan,
I would like to see the backing bean as a request scoped bean, where as a Managed bean can be of any scope, includng request scope.As the backing bean containg references to the components in the jspx pages directly, we cannot have a backing bean with session scope or of higher scope.
Here is my doubt!
What if we need to access the component's value in a session scoped managed bean ?
Should we import the backing bean's class in the session scoped bean and use the getter and setter methods?

Waiting for your answer,
Samba.
Permalink 04/09/06 @ 19:38

Comment from: Duncan Mills [Member]
If you need to store a value then that can be bound to a separate managed bean that lives in session scope. There is no problem in having a binding of the component to one bean in the request scope and the value of that component in another. Think model-view-controller here. Your model exists in the session but the view part (the actual components) are request based. There is a clean separation.
Permalink 05/09/06 @ 16:05

Comment from: Samba Siva Rao Kolusu [Visitor]




Why I'm asking is...

When I have a backing bean(request scoped),used like:



I'm getting the value enterd in the inputtext field,username.

But When I try to get the same from a session Scoped bean I'm getting null value.

Is there any special way to bind to a Session scoped bean?
Thanking you, Samba.



Permalink 09/09/06 @ 20:41

Comment from: Duncan Mills [Member]
No there is no special way of using a session scoped bean - JSF takes care of instanciating a copy of the bean the first time that it is referenced - then it will return that copy thereafter.
If you're not seeing the data you expect to see check the constructor of the session scoped bean to make sure that it is executing as expected
Permalink 11/09/06 @ 21:42

Comment from: Samba Siva Rao Kolusu [Visitor]
ADF Bindings Servlet/Filter not invoking Faces Servlet

Hi,Duncan!


I'm getting ADF Faces and Facelets working properly with pages written in jspx format, but the Faces Servlet being mapped to jsf format.

The problem I'm getting is while displaying ADF Tables with data retrieved from the database using Toplink and bindings provided by ADF Databindings.

The following is the Web.xml mappings for Faces Servlet and ADF bindings filter:


Faces Servlet
javax.faces.webapp.FacesServlet
1



resources
/adf/*



Faces Servlet
*.jsf




adfBindings
oracle.adf.model.servlet.ADFBindingFilter



adfBindings
*.jsp



adfBindings
*.jspx



I'm getting the ADF tables displayed using ADF Bindings, if the faces servlet is mapped for jspx format;but, at the cost of losing Facelets...Facelets is not working with Faces Servlet mapped to jspx format(though written in jspx format, the faces servlet mappping has to be made for jsf format.

On the other hand, if I use faces servlet mapping for jsf pages I'm getting Facelets working but ADF Databindings are not working ,(I guess) and hence ADF Faces Tables are not being displayed(I'm getting Access Denied message).

I even tried to change the ADF binding filter mappings

---- from ---- jsp &jspx---- to ----- jsp and jsf ----

But I got the same Access denied message.

I read a similar post on Oracle's JDeveloper forum by Mr.Ashish Kumar who said he is using java script and automatic form submission, to refresh the page and that gave him the table working.

as quoted in the post:

http://forums.oracle.com/forums/thread.jspa?threadID=421336&tstart=105


Why should the page be refreshed at all. I Guess , the Faces Servlet is not being invoked by the ADF Bindings Filter/Servlet, and for this , I suppose , Mr.Ashish is using java script to provide the action required.



And one more thing which that Automatic Refreshing of page using JavaScript cannot do.

Suppose,

I need customised display, rather than just a Table or Form,like:

public String getEmp() {
BindingContainer bindings = getBindings();
OperationBinding operationBinding =
bindings.getOperationBinding("findAllEmp");
Object result = operationBinding.execute();
if (!operationBinding.getErrors().isEmpty()) {
return null;
}

List res=(List)result;
for(int i=0;i

What I'm getting is a disabled button.


Why doesn't ADF bindings servlet invoke the faces Servlet?
Can't we make ADF Bindings Servlet invoke Faces Servlet by configuring in the web.xml?

Can't we get ADF Bindings filter mapped to work with jsf pages?
Won't ADF Bindings work with jsf pages, will they work only with jspx pages?

This may not be a proper place to ask this question, but I tried so many forums, but could not get the answer!

Simply put,
Can't we get ADF Bindings work in pages with .jsf extension?

When the bindings are working with .jspx pages, why can't we get those working with .jsf pages?




Please Help me.

Thanking you,

Samba
Permalink 12/09/06 @ 13:14

Comment from: Om [Visitor] · http://www.hostitwise.com
I just need to get back to the basics of backing beans nd what I would like to see is a simple explnation on when the page ADF components get rendered what exactly happen? I mean we have the .jspx file, the page definition file (xml), the page java class! what are the steps of rendering the class components?

Thanks
Permalink 06/02/07 @ 04:10

 

原创粉丝点击