Commandlink动作和@viewscoped怪异行为 [英] Commandlink action and @viewscoped weird behaviour

查看:96
本文介绍了Commandlink动作和@viewscoped怪异行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些由netbeans向导来自实体类的JSF页面"生成的代码. 对于那些不使用netbeans的人,我将简要描述该向导的作用. 它创建一个JSF页面List.xhtml,其中包含一个固定大小为10行的数据表和两个用于滚动其内容的命令链接(上一个10和下一个10). JSF页面使用具有会话范围的托管bean,并且上述命令链接返回字符串"List". 如果将托管bean范围更改为@viewscoped,则每次按下命令链接时都会重新创建它.在我看来,这是一种奇怪的行为,因为视图实际上并没有改变(它始终是List.xhtml),而且我期望有一个智能的视图作用域机制.

I have some code generated by netbeans wizard 'JSF pages from entity classes'. For those who don't use netbeans I will briefly describe what the wizard does. It creates a JSF page List.xhtml which contains a datatable with a fixed size of ten rows and two commandlinks for scrolling its content (prev 10 and next 10). The JSF page uses a managedbean with session scope and the above mentioned commandlinks return the String 'List'. If I change the managed bean scope to @viewscoped it is re-created every time I push a commandlink. According to me it is a weird behavior because the view actually doesn't change (it always List.xhtml ) and I would have expected a smarted view scope mechanism.

然后我用一个新命令更改了与命令链接关联的操作,该操作执行相同的操作但返回void.现在,@viewscope机制可以正常工作,但我不确定使用带有这种签名的操作方法是正确的

I then changed the action associated to the commandlinks with a new one which does the same things but returns void. Now the @viewscope mechanism works well but I'm not sure it is correct to use an action method with a signature like this

public void doSomething()
// instead of
public String doSomething()

我担心的是,不同的JSF实现可以通过这种动作以不可预测的方式发挥作用.

My concern is that a different JSF implementation can act in an impredictable way with that kind of actions.

谢谢 菲利波(Filippo)

Thanks Filippo

推荐答案

您在public String doSomething()中返回什么?

如果返回null(或空字符串),则不应重新创建视图.

If you return null (or an empty String) it should not re-create the view.

如果返回导航案例,则无论视图是否与您当前所在的视图相同,都会重新创建视图.

If you return a navigation case then the view is re-created, regardless whether it is the same that you are currently in.

这篇关于Commandlink动作和@viewscoped怪异行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆