Rick Reumann wrote:
On 8/24/05, *CONNER, BRENDAN (SBCSI)* <[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]>> wrote:
Our CalculatorBean would be a simple JavaBean containing firstNumber,
secondNumber, and result.
Our CalculatorAction class would have a field called calcBean (and its
getter and setter), which is set by JSF, plus the methods add() and
multiply(). (Note that, since the reference to calcBean is a managed
reference, CalculatorAction does *not* instantiate calculatorBean
itself.)
The JSP would then refer to #{calcBean.firstNumber},
#{calcBean.secondNumber }, #{calcBean.result}, #{calcAction.add}, and
#{calcAction.multiply}.
Ok, I really like this, but help me out with trying to understand a
totally noob concept... to help me relate, lets change the above to an
"Employee" and an "EmloyeeAction"...
First what I want to accomplish...
I'm on a JSP and I'm viewing a list of employees. I click on a button
next to the employee that should bring me to an 'editEmployee' screen
after looking up the employee from backend based on id.
Clicking on the button should call the "EmployeeAction" backing bean
and retrieve an "Employee" (which using your scenario would also be a
managed bean). The Employee object is returned from the
EmployeeAction's 'getEmployee' method.
We now foward on to the 'employeeForm.jsp'
*Which backing bean am I now to use on this employeeForm.jsp* and how
does it manage to get a handle to the "Employee" that we just returned
from our EmployeeAction if we are using request scoped managed beans?
If I understand you correctly, you are really asking: "If I have a bean
in a page and then forward to another page, can I still access the
bean?" If so, I think the concept that applies is that of the scope of
the bean - specifically, the session scope. [If I am wrong on this, oh
senior folks, please let me know.]
According to Hans Bergsten's JavaServer Faces (OReilly):
"When JSF evaluates a value binding expression and encounters a variable
that doesn't exist in one of the scopes, it consults the configuration
file and creates an instance of the managed bean with a matching name."
So, if you have already created an instance of employeeBackingBean (and
it is defined as having a session scope), it should be available for all
subsequent pages in the session.
-david-