Kibo wrote:
Hi konference
I read the article there:
http://struts.apache.org/2.0.9/docs/scope-interceptor.html
and a want use scope interceptor, but it not work my. I dont know exactly,
that i good understand it.
I want save into session model: Employee.
Hi Tomas,
You are close to getting it to work. There are two issues to understand:
- the ValueStack and the impact of the ModelDriven interface
- the role of the scope interceptor
ValueStack: the stack contains all the relevant objects created by the
framework. Normally your Action is the object at the top/root and you
can access a property like:
<s:property value="employee.firstName"/> where getEmployee() is provided
by your action.
When you enable the ModelDriven<Employee> interface, instead the
framework pushes the model (Employee) on top of the stack. Now, to
access a property of the employee you can use this:
<s:property value="firstName"/> (as an employee is the top of the tack,
it accesses the employee's first name)
The stack still contains your action behind the Model and the framework
will search it for properties that the model doesn't have.
Next, the role of the scope interceptor is to get the Model after your
action executes and put it into the session (or another scope). Also,
when an action is invoked, it will also set the Model on your action by
getting it from the session. The reason this in an interceptor is so
that your action and JSPs doesn't have to know; the interceptor hides
that a session (or other scope) was used.
That means you should design your JSP as if it was populated by a normal
ModelDriven action.
This line in your original code tries to access an object named model in
the session. It does need to (and shouldn't)
<s:property value="%{#session.model}" />
Instead, your model is already there (at the top of the stack that is; either newly created or fetched for you by the interceptor)
<s:property value="firstName" />
I hope that helps,
Jeromy Evans
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]