You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Garner, Shawn" <sh...@pearson.com> on 2005/12/05 23:54:57 UTC

[shale] View Controller methods

Can somebody elaborate on more uses of these?

 

init()

preprocess() 

prerender() 

destroy() 

 

I currently have a start and save struts (in a struts 1.1) methods that
populate the form bean values from a session object for the start and save
the values from the form bean into a session value object.

Could these be used for the same purpose with a managed bean in a shale
application?

 

 

Shawn

 


**************************************************************************** 
This email may contain confidential material. 
If you were not an intended recipient, 
Please notify the sender and delete all copies. 
We may monitor email to and from our network. 
****************************************************************************

Re: [shale] View Controller methods

Posted by Craig McClanahan <cr...@apache.org>.
On 12/5/05, Garner, Shawn <sh...@pearson.com> wrote:
>
> Can somebody elaborate on more uses of these?
>
>
>
> init()
>
> preprocess()
>
> prerender()
>
> destroy()


Feature description of the "View Controller" feature:

    http://struts.apache.org/struts-shale/features-view-controller.html

The javadocs for ViewController are also pretty thorough.  They're in the
package you downloaded, as well as available online:

    http://struts.apache.org/struts-shale/features-view-controller.html


I currently have a start and save struts (in a struts 1.1) methods that
> populate the form bean values from a session object for the start and save
> the values from the form bean into a session value object.
>
> Could these be used for the same purpose with a managed bean in a shale
> application?


Partly.

The stuff you do in a "start" type action could go in the prerender()
method.  The "save" type action (in a Struts app) would generally correspond
to the action method that you bind the submit button to.

A particular use case might make this more clear.  Let's assume that you
have some sort of a table that is going to display a bunch of data out of
your database.  You obviously do not want to leave the database connection
open across requests, so in Struts you'd typically write a start action that
loaded up all the data into an array of beans or something, and then
released the database connection.  The page would be able to render it.

With Shale, another design approach would be something like this:

* In the prerender() method, go get the JDBC connection and execute your
query
  (or go get your Hibernate session and execute the query; whatever
technology
  you're using is fine).

* In the page itself, the components would be bound to a DataModel
representing
  this data.  As the components rendered themselves, you'd be indexing
through
  the beans as usual.

* In the destroy() method, which is called after rendering is complete, you
can
  release the JDBC connection (or close down your Hibernate session, or
whatever).

Craig


Shawn
>
>
>
>
>
> ****************************************************************************
> This email may contain confidential material.
> If you were not an intended recipient,
> Please notify the sender and delete all copies.
> We may monitor email to and from our network.
>
> ****************************************************************************
>
>

Re: [shale] View Controller methods

Posted by Alexandre Poitras <al...@gmail.com>.
Good news for you! You don't have to populate any beans or forms in JSF. You
use value and method binding properties so the framework can populate them
itself.

Those methods are there when you need some page level functionalities. For
example, I use init() usually when I need to load some data from my service
layer into the ViewController backing bean to display on the page.

On 12/5/05, Garner, Shawn <sh...@pearson.com> wrote:
>
> Can somebody elaborate on more uses of these?
>
>
>
> init()
>
> preprocess()
>
> prerender()
>
> destroy()
>
>
>
> I currently have a start and save struts (in a struts 1.1) methods that
> populate the form bean values from a session object for the start and save
> the values from the form bean into a session value object.
>
> Could these be used for the same purpose with a managed bean in a shale
> application?
>
>
>
>
>
> Shawn
>
>
>
>
>
> ****************************************************************************
> This email may contain confidential material.
> If you were not an intended recipient,
> Please notify the sender and delete all copies.
> We may monitor email to and from our network.
>
> ****************************************************************************
>
>


--
Alexandre Poitras
Québec, Canada