【发布时间】:2011-12-02 21:28:22
【问题描述】:
我真的很困惑,因为我对这整个主题都很陌生。我目前正在使用 spring webflow 开发一个项目。在我的网络界面中,用户必须输入用户名,而不是存储在 bean 中。
形式:
<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"/>
对应的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...
在输入用户名后,用户将被转发到下一个页面,他当前的cashPosition 应该每 5 秒显示和更新一次,因为该值可能已经改变(通过 PrimeFaces 轮询管理)。到目前为止,这是有效的。
当用户输入他的用户名和其他一些值时,他按下一个按钮并触发相应流程的转换。
<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>
以及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;
}
为了更新 bean 的值,我将 bean 对象转发给其他类
public class ConnectionService {
public boolean connect (String username, String password, String serverURL,
boolean bypass, HumanBrokerBean brokerBean){ ....
}
}
当我尝试用
打印bean对象的变量值时System.out.println("Brokername :"+brokerBean.getBrokerName())
我得到了正确的结果。当我现在尝试用
更新cashPosition
brokerBean.setCashPosition();
正确的结果没有显示在我的网页界面投票部分。始终返回初始值零。
如上所述,我用primefaces-poll实现了轮询功能,它使用了AJAX。
<h:form>
<h:outputText id="txt_cash" value="#{brokerBean.cashPosition}" />
<p:poll interval="3" update="txt_cash" />
</h:form>
而我总是得到的 AJAX 响应......总是返回 0.0,这是每个 Broker 的 cashPosition 的初始值......
<?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>
对我来说,这意味着我的BrokerBean 有两个不同的实例,但我不知道为什么。我想我将不得不在我的 bean 中使用一些注释,但我不确定是哪一个。
我需要做什么才能使这个场景运行?
【问题讨论】:
-
不知道我可以做些什么来实现我的目标?
标签: java spring ejb javabeans spring-webflow