【问题标题】:Why can't my redirected webflow find my bean and use it为什么我的重定向 webflow 找不到我的 bean 并使用它
【发布时间】:2011-06-10 19:21:00
【问题描述】:

我将 JSF2.0 与 Spring Webflow 2.3 一起使用。

我一直在尝试获取有关在我的页面中点击了哪些链接以及点击了多少次的信息。现在,当我留在流程中并转到另一个流程时它可以工作,但是当我重定向然后返回时,它只会重置我的 bean。我觉得我错过了一些东西,但我不知道是什么。

我已经尝试了我的小脑袋能想到的所有事情,我也尝试过研究,但我的猜测是我的搜索参数不正确,因为我找到的所有内容都无济于事。

这是我的支持 bean:

@SessionScoped
public class CountBean implements Serializable{

private static final long serialVersionUID = 7498596369206276696L;
private static Log logger = LogFactory.getLog(CountBean.class);
private String link;
private Map<String,Integer> counter;



public CountBean(){
    if(counter == null || counter.isEmpty()){
        counter = new LinkedHashMap<String,Integer>();
    }
    link = null;
}



public void countTheCount(){
    if(link != null){
    int value;
    if(counter.containsKey(link)){
        value = counter.get(link);
        value++;
        counter.put(link, value);
    } else {
        value = 1;
        counter.put(link, value);
    }
    logger.debug("Click: "+link+" , times: "+value);
    }
}

public String getLink() {
    return link;
}

public void setLink(String link) {
    this.link = link;
}


}

这是我的流程:

<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="testBean" class="be.admb.myadmbresearch.beans.TestBean" />
<var name="countBean" class="be.admb.myadmbresearch.beans.CountBean" />


<view-state id="test-view" model="testBean">
    <transition on="logTest">
        <evaluate expression="testBean.testWarning()" />
        <evaluate expression="countBean.countTheCount()" />
    </transition>
    <transition on="gotoxy" to="sample-view">
        <evaluate expression="countBean.countTheCount()" />
    </transition>
    <transition on="gotoab" to="sample-redirect-view">
        <evaluate expression="countBean.countTheCount()" />
    </transition>
    <transition on="gotogoogle" to="gotoGoogle-view">
        <evaluate expression="countBean.countTheCount()" />
    </transition>
</view-state>
<view-state id="sample-redirect-view" view="externalRedirect:contextRelative:sample.html" />
<view-state id="gotoGoogle-view" view="externalRedirect:http://www.google.be" />
<view-state id="sample-view">
    <transition on="keerdekewere" to="test-view">
        <evaluate expression="countBean.countTheCount()"/>
    </transition>
</view-state>

编辑:忘记添加重定向的样本流:

<var name="countBean" class="be.admb.myadmbresearch.beans.CountBean" />
<view-state id="sample-view" >
    <transition on="keerdekewere" to="test-view">
        <evaluate expression="countBean.countTheCount()"/>
    </transition>
</view-state>

<view-state id="test-view" view="externalRedirect:contextRelative:test.html" />

如果有人可以帮助我,甚至想到任何事情,我将非常感激。

提前致谢。

拉斐尔

【问题讨论】:

    标签: jsf-2 spring-webflow


    【解决方案1】:

    我已经通过每次运行 countTheCount() 时使用 HttpSession 直接设置计数器来修复它,现在这似乎可行,但我不知道这是否是正确的解决方案,一些反馈会很好。

    这是我得到的:

    public CountBean(){
        HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
        if(session != null){
            counter = (Map<String, Integer>) session.getAttribute("counter");
        if(counter == null || counter.isEmpty()){
            counter = new LinkedHashMap<String,Integer>();
            session.setAttribute("counter", counter);
        }
        }
        link = null;
    }
    
    public void countTheCount(){
        HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
        if(link != null){
        int value;
        if(counter.containsKey(link)){
            value = counter.get(link);
            value++;
            counter.put(link, value);
            session.setAttribute("counter", counter);
        } else {
            value = 1;
            counter.put(link, value);
            session.setAttribute("counter", counter);
        }
        logger.debug("Click: "+link+" , times: "+value);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-12
      • 2023-04-10
      • 1970-01-01
      • 2010-10-19
      • 1970-01-01
      • 2014-12-20
      • 1970-01-01
      • 2019-09-05
      相关资源
      最近更新 更多