2

I'm really getting confused because I'm pretty new to this whole topic. I'm currently developing a project using spring webflow. In my webinterface a user has to type in a username that is than stored in a bean.

The Form:

  <fieldset>
       <legend>User Details</legend>
       <h:outputText value="Please enter the Name for your Broker:    " />
       <h:inputText id="brokerName" value="#{brokerBean.brokerName}"/>
       <h:outputText value="Please enter the password for your Broker: " />
       <h:inputSecret id="password" value="#{brokerBean.password}"/>
    </fieldset>
    <p:commandButton value="Register Broker" action="register" ajax="false"/> 

The according bean:

public class HumanBrokerBean  implements Serializable{

    /** The Constant serialVersionUID. */
    private static final long serialVersionUID = 1L;

    /** The broker name. */
    private String brokerName;

    /** The password. */
    private String password;

    private double cashPosition = 0;

    ... getters & setters...

After typing in the username the user is forwarded to the next page where his current cashPosition should be displayed and updated every 5 seconds, because the value might have changed (managed that with PrimeFaces poll). This is working so far.

When the user has typed in his username and some other values he presses a button and a transition of the according flow is fired.

<view-state id="view">
        <transition on="register" to="mainpage">    
            <evaluate expression="brokerBean.checkCredentials(flowRequestContext)" />
            <evaluate expression="connectionBean.connect(brokerBean.brokerName, brokerBean.password, brokerBean)" /> 
        </transition>
    </view-state>

And the method of the ConnectionBean:

public boolean connect(String username, String password, HumanBrokerBean brokerBean){

        ConnectionService connection = new ConnectionService();
        //if there have been problems while establishing the connection
        if(!connection.connect(username, password, this.serverConnection, byPass, brokerBean)){
            return false;
        }
        //if connection was established
        return true;
    }

To update the values of the bean, I forwarded the bean object to some other class

public class ConnectionService {
    public boolean connect (String username, String password, String serverURL,
        boolean bypass, HumanBrokerBean brokerBean){ ....
    }
}

When i try to outprint the variable-values of the bean object with

System.out.println("Brokername :"+brokerBean.getBrokerName())

I'm getting the correct results. When I now try to update the cashPosition with

brokerBean.setCashPosition();

The correct result is not displayed in my webinterface poll-section. The initial value of zero is returned always.

As mentioned above, I implemented the polling function with primefaces-poll, which uses AJAX.

<h:form>  
    <h:outputText id="txt_cash" value="#{brokerBean.cashPosition}" />  
    <p:poll interval="3" update="txt_cash" />  
</h:form> 

And the AJAX response I always get... returns always 0.0, which is the initial value of the cashPosition of each Broker...

<?xml version='1.0' encoding='UTF-8'?>
<partial-response><changes><update id="j_idt16:txt_cash"><![CDATA[<span id="j_idt16:txt_cash">0.0</span>]]></update><update id="javax.faces.ViewState"><![CDATA[e1s2]]></update></changes><extension primefacesCallbackParam="validationFailed">{"validationFailed":false}</extension></partial-response>

For me that means, that there are two different instances of my BrokerBean but I'm not sure why. I think I will have to use some annotation in my bean, but I'm not sure which one.

What would I need to do to make this scenario run?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Nikolaus Hartlieb
  • 339
  • 1
  • 5
  • 17

1 Answers1

0

Does your SWF servlet contain "component-scan" tag? If yes, this will cause beans to be scanned twice: first in root web application context, then in SWF servlet context. Your flow actions will refer to SWF-servlet bean instance, but JSF EL expressions will be in main application context.

For MVC/SWF it is recommended to scan only @Controller beans in servlet context. See Why DispatcherServlet creates another application context?

Community
  • 1
  • 1
rootkit
  • 2,165
  • 2
  • 29
  • 43