Iceface 2.0 commandLink 部分提交不起作用
我有一个页面,它接受地点的请求参数,然后生成信息, 例如,http://example.com/xxx/weather.jsf?place=california
。 这样做的目的是让用户为链接添加书签。
在weather.jsf 中,有两个输出文本和一个命令链接:
Humidity : <ice:outputText value="#{weatherBean.humidity}"/>
Visibility : <ice:outputText value="#{weatherBean.visibility}"/>
<ice:commandLink id="likeButton"
value="Like"
actionListener="#{weatherBean.doLike}" />
在managementBean 中:
@ManagedBean(name="weatherBean")
@RequestScoped
public class WeatherBean
{
String humidity;
String visibility;
int numLike;
@PostConstruct
public void init()
{
System.out.println("init called");
HttpServletRequest request= (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
String place = request.getParameter("place");
setHumidity(WeatherDao.getHumidity(place));
setVisibility(WeatherDao.getVisibility(place));
setNumLike(GeneralDao.getNumLike());
}
public void doLike(ActionEvent event)
{
System.out.println("doLike called");
GeneralDao.addNumberLike();
}
}
好的,页面生成得很完美。 但是,当我单击 doLike
commandLink 时, 它总是先触发 init
方法,然后调用 doLike
方法。 由于请求参数为空,所有其他值都会重置。 有什么方法可以防止刷新页面或调用 init
方法吗? 我尝试了部分提交或立即提交,但没有运气。
I have a page which takes in request params for place, then generate information,
for example, http://example.com/xxx/weather.jsf?place=california
.
The purpose of doing this is to let user bookmark the link.
In the weather.jsf, there are two outputtext and a commandlink:
Humidity : <ice:outputText value="#{weatherBean.humidity}"/>
Visibility : <ice:outputText value="#{weatherBean.visibility}"/>
<ice:commandLink id="likeButton"
value="Like"
actionListener="#{weatherBean.doLike}" />
In the managedBean:
@ManagedBean(name="weatherBean")
@RequestScoped
public class WeatherBean
{
String humidity;
String visibility;
int numLike;
@PostConstruct
public void init()
{
System.out.println("init called");
HttpServletRequest request= (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
String place = request.getParameter("place");
setHumidity(WeatherDao.getHumidity(place));
setVisibility(WeatherDao.getVisibility(place));
setNumLike(GeneralDao.getNumLike());
}
public void doLike(ActionEvent event)
{
System.out.println("doLike called");
GeneralDao.addNumberLike();
}
}
Alright, the page generated perfectly.
However, when I click the doLike
commandLink,
it always triggers the init
method first, then call doLike
method.
Since the request param is empty, all the other values reset.
Is there any way to prevent a refresh of the page or calling of init
method?
I tried partialsubmit or immediate, but no luck.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的 bean 是 @RequestScoped,因此在执行 JSF 生命周期后,您的 bean 实例将丢失,直到下一个请求到来,此时您将获得 bean 的新实例,并且 PostContruct 重新执行。
尝试将 bean 的范围更改为寿命更长的内容,例如 @ViewScoped。
Your bean is @RequestScoped, so after executing the JSF lifecycle, your bean instance is lost, until the next request comes in, at which point you get a new instance of your bean, and the PostContruct re-executes.
Try changing the scope of your bean to something longer lived, like @ViewScoped.