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