为什么我的重定向网络流无法找到我的 bean 并使用它

发布于 2024-11-14 19:32:52 字数 3158 浏览 2 评论 0原文

我将 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" />

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

提前致谢。

拉斐尔

I'm using JSF2.0 with Spring Webflow 2.3 .

I've been trying to get information on what link has been clicked in my page and how many times it has been clicked. Now it works when I stay in the flow and just go to another flow but when I redirect and then return it just resets my bean. I feel like i am missing something but i don't know what.

I've tried about everything my little head can think off and i've tried researching but my guess is my search parameters aren't correct cause all I find doesn't help.

This is my backing 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;
}


}

And this is my flow:

<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>

Edit: Forgot to add the redirected sample-flow:

<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" />

If anyone could help me or even think of anything i would be very gratefull.

Thanks in advanced.

Rafael

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无声静候 2024-11-21 19:32:52

我已经通过每次运行 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);
    }
}

I've fixed it by using a HttpSession directly setting the counter eachtime i run countTheCount(), now this seems to work but i don't know if it is the right solution, some feedback would be nice.

This is what i got:

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);
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文