开发者

Commandlink action and @viewscoped weird behaviour

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 'Lis开发者_运维知识库t'. 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.

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

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

Thanks Filippo


What do you return in public String doSomething()?

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜