开发者

the best practice for performance bettween using parameter in url ?p=2 and Managed bean [duplicate]

This question already has answers here: ViewParam vs @ManagedProperty(value = "#{param.id}") (2 answers) Closed 7 years ago.

I am using JSF 2.0 and Icefaces and Glassfish for my project and I want to optimise this application the best I can, and I want to know what is the most optimized method to send parameter.

first 1: using /BackOffice/test.xhtml?id=7 in url and String a=(String) FacesContext.getCurrentInstance().getExternalContext().getRequestMap().get("id"); in the bean with @RequestScoped and

<f:metadata>
        <f:viewParam name="id"  value="#{id}">
        </f:viewParam>
    </f:metadata>

in the jsf

or the second : using 开发者_运维知识库backing bean with @SessionScoped


Optimized how exactly? SessionScoped beans are going to hold persistent memory which may be bad if you have a high number of users. RequestScope is going to require the id to be passed per request which isn't over expensive either way but does require a request scoped bean to be created per-request.

I generally favor Request params over session params unless the value really needs to persist for the duration of the user's time on the site.


There is no such thing as "optimize the best I can". Optimizing is about making trade-offs. You trade cpu for memory, memory for bandwith, bandwith for cpu and so on.

The method of passing Id is probably the least important of your problems. Just forget it. If you want to optimize, first ask yourself whether you are keeping your view state on client or on server. This is going to make a huge difference (and no, there is no "optimal" choice here, it is a trade-off). The next thing will be - how to handle the database. Do you load your data per-request or do you keep them with your view or session? If you use JPA, do you enable the second-level cache? These are the questions you should be asking. Not a detail about request params.


If you want to optimize you should start with profiling, I highly doubt the difference between these two will be of any significance.

Request parameters should be passed as request parameters as you will otherwise break bookmarks, browser history, search engine indexing and caching.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜