Tuesday 16 October 2012

on-entry vs. on-render in Spring Webflow

The action defined in <on-entry> is executed upon entering the state.

The action defined in <on-render> is executed before the view is rendered.

The distinction seems very clear but in practice, say you need to load some information from the database to be displayed, will you use <on-entry> or <on-render>?

Both seem to be legitimate choices. Does it really matter if the data is loaded upon entry or right before the view is rendered?

Well, the answer depends on whether you want the data to be reloaded if the page gets refreshed (including partially refreshed).

Let's see an example.

In web-flow.xml, we have a view-state.

<view-state id="dummy">
    <on-entry>
        <evaluate expression="dummy.onEntry()"></evaluate>
    </on-entry>
    <on-render>
        <evaluate expression="dummy.onRender()"></evaluate>
    </on-render>
</view-state>

Dummy.java

public class Dummy implements Serializable{
    private static final long serialVersionUID = 1L;
 
    public void onRender(){
        System.out.println("On Render");
    }
 
    public void onEntry(){
        System.out.println("On Entry");
    }
}

After the view is rendered on the browser, we will see in the console

On Entry
On Render

Now we refresh the page (i.e. press F5), we will see in the console

On Entry
On Render
On Render

So the on-entry action wouldn't be executed but on-render action still would.

3 comments:

  1. Hi
    I have been trying to set a value in and it didn't call the function in evaluate. The same function in works fine.
    Caused me a problem. Anyone any idea why this should be so ?

    ReplyDelete
  2. Explore stunning Webflow portfolio templates to showcase your work elegantly. Boost your online presence with these professionally designed layouts.

    flowgiri

    ReplyDelete
  3. Absolutely thrilled to discover these Webflow portfolio templates! The elegant designs are a perfect match for showcasing my work professionally. Excited to boost my online presence with these thoughtfully crafted layouts. Kudos to Webflow for making the process of creating a stunning portfolio so seamless and stylish!

    ReplyDelete