什么时候应该使用h:link而不是h:commandLink? [英] When should one use h:link instead of h:commandLink?

查看:93
本文介绍了什么时候应该使用h:link而不是h:commandLink?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个要链接到的JSF页面,我不需要在该页面上传达任何信息,并且不需要在要链接的页面上执行任何验证,那么我应该始终使用h:link?

If I have a JSF page that I want to link to where I don't need to communicate anything to that page and don't need to perform any validation on the page I'm linking from, should I always use an h:link?

是否通过不使用h:commandLink(带有Instant ="true"或execute ="@ this")丢失任何内容?

Do I lose anything by not using a h:commandLink (with immediate="true" or execute="@this")?

在这种情况下,h:link和h:commandLink之间是否有区别?

Is there any difference between h:link and h:commandLink in this scenario?

推荐答案

h:link将触发完整的GET请求.仅JSF生命周期阶段1(恢复视图)和阶段6(渲染响应)将被调用.没有转换,没有验证,没有任何动作.

The h:link will fire a full GET request. Only JSF lifecycle phases 1 (restore view) and 6 (render response) will be invoked. No conversion, no validation, no action.

因此immediate="true"execute="@this"将不起作用(它们对于h:link完全不可用).

Thus immediate="true" and execute="@this" won't work (they are not available for h:link at all).

使用h:link进行纯页到页面导航,如果需要在服务器上处理输入数据,则使用h:commandLink(触发POST请求).

Use h:link for pure page to page navigation and h:commandLink (which fires a POST request) if input data needs to be processed on the server.

附录:

如果目标页面包含f:viewParam,则根据BalusC的注释生命周期,第2到第5阶段不会被GET请求跳过.

As per BalusC's comment lifecycle phases 2 to 5 are not skipped for a GET request if the target page contains f:viewParams.

这篇关于什么时候应该使用h:link而不是h:commandLink?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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