0

I have an JSF application that uses Spring Web Flow for navigation. Each time the user navigates to the accounts view from another view a piece of code should be executed. For the accounts view I have a managed bean called accountsBean. I thought of calling a initView method from the bean on flow entry. It throws a PropertyNotFoundException because accountsBean is not recognized by Spring.

WEB-INF/flows/accounts-flow/flow.xml

<flow xmlns="http://www.springframework.org/schema/webflow"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/webflow http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd">  

    <view-state id="accounts" view="accounts.xhtml">
        <on-entry>  
            <evaluate expression="accountsBean.initView()"></evaluate>  
        </on-entry>
    </view-state>

</flow>

EDIT1:
A part of my application manages accounts and groups. The user navigates between different parts of the application using a menu. Spring Web Flow is used to link the navigation from a menu item to a certain view. The accounts view contains a datatable, some buttons for CRUD operation and a select box for choosing the type of accounts. Different accounts are displayed depending on their type. The datatable columns are dynamic. The user can activate or deactivate a certain type. Now the user has to logout to see the account types modification. I need to make it work without the need of a logout.

EDIT2: I have changed the flow definition to:

<flow xmlns="http://www.springframework.org/schema/webflow"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/webflow http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd">  

    <var name="accountsFlow" class="com.acme.accounts.AccountsFlow" /> 

    <view-state id="accounts" view="accounts.xhtml">
        <on-entry>  
            <evaluate expression="accountsFlow.initView()"></evaluate>  
        </on-entry>
    </view-state>

</flow>

AccountsFlow is annotated with org.springframework.stereotype.Component. Inside initView method some code from accountsBean is executed. This works for SessionScoped beans, but the solution proposed by BalusC is better.

Seitaridis
  • 4,301
  • 9
  • 51
  • 83
  • 1
    I'm not sure how Spring plays a role here, but in standard JSF it would be a matter of making the bean `@ViewScoped` and just performing the desired job in its `@PostConstruct` method. – BalusC Sep 05 '12 at 10:54
  • In my implementation the accountsBean is `@SessionScoped`. – Seitaridis Sep 05 '12 at 11:08
  • 1
    Sure that it is the right scope for the job? An "accountsBean" which needs to be reinitialized on every view doesn't seem to represent the logged-in user or its preferences. Are you aware that the same instance would be shared among all opened browser tabs/windows in the same session and that the data is reflected/changed in all others once the enduser performs some action in one of them? – BalusC Sep 05 '12 at 11:11
  • You are right. A `ViewScoped` bean would be more appropriate. – Seitaridis Feb 18 '13 at 08:49

1 Answers1

0

The first comment by BalusC is correct, however Spring does not support ViewScope out of box. You have to implement your own custom ViewScope and declare it through your Spring applicationContext.xml file. There are many examples of this online:

http://cagataycivici.wordpress.com/2010/02/17/port-jsf-2-0s-viewscope-to-spring-3-0/

maple_shaft
  • 10,328
  • 4
  • 42
  • 70