开发者

javaserverfaces property access problem

I have index.html page with

<h:dataTable id="usersTable" value="#{mainViewController.users}" var="user" border="1">
 ....

and request scoped mainViewController bean

@Component("mainViewController")
@Scope("request")
public class MainViewController {
@Inject
private UserDao userDao开发者_如何转开发;
private Collection<User> users;

public Collection<User> getUsers() {
    if (users == null) {
        users = userDao.findAll();
    }
    return users;
}

when I access index.html getUsers is called, that is absolutely normal, but when I leave index.html to some other page getUsers is also called, how avoid secondary call?


Don't use POST for page-to-page navigation. So don't use a <h:commandLink> or <h:commandButton> to navigate to another page. It will unnecessarily submit the form to the server and recreate the same bean. Just use <a>, <h:outputLink>, <h:link> or <h:button> for page-to-page navigation. They fire a GET request straight on the target URL.

Another advantage of using GET for page-to-page navigation is that Searchbots will index the pages. Thus, better for SEO.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜