iceface 2.0: How to retain value in icepush?
I would like to integrate ice push into my web application.
I have a page(placeinfo.jsf) shows information of a place and ui:include weather.jsf for weather information of the place.
Users access to the page at http://xxx.com/xxx/placeinfo.jsf?place=california.
Simple example of code,
placeinfo.jsf 1) ice:output value="placeInfoBean.population" 2) ice:output value="placeInfoBean.language" 3) ui:include src="./weather.xhtml"weather.jsf 1) ice:output value="weatherBean.humidity" 2) ice:output value="weatherBean.visibility"
PlaceInfoBean.java
@ManagedBean(name="placeInfoBean")
@RequestScoped
public class PlaceInfoBean
{
String population;
String language;
@PostConstruct
public void init()
{
HttpServletRequest request= (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
String place = request.get开发者_JS百科Parameter("place");
setPopulation(PlaceInfoDao.getPopulation(place));
setLanguage(PlaceInfoDao.getlanguage(place));
}
}
WeatherBean.java
@ManagedBean(name="weatherBean")
@RequestScoped
public class WeatherBean
{
String humidity;
String visibility;
@PostConstruct
public void init()
{
HttpServletRequest request= (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
String place = request.getParameter("place");
setHumidity(WeatherDao.getHumidity(place));
setVisibility(WeatherDao.getVisibility(place));
}
public WeatherBean()
{
PushRenderer.addCurrentSession("weather");
}
}
I have another page to update the weather, and the method calls
PushRenderer.render("weather"); WeatherBean actually did a refresh, postconstrust method run again, but found there is no request param of "place" which suppose to be "california", and the page doesn't work properly then. Question: 1) May I know besides session, how can the page remembers the value before PushRenderer did something? 2) Is it a proper way to get the request param for WeatherBean? or request param should be passed by ui:param from placeInfo.jsf? How to get the value of ui:param in WeatherBean?Thank you!
Have you tried to set the managed beans as @SessionScoped? Or @ApplicationScoped? Did it work?
精彩评论