JSF 2.0 在 commandLink 和 commandButton 上导航不起作用
我正在使用 JSF 2.0,并且在 commandLink 和 commandButton 之后的导航时遇到问题。我使用以下代码:
<h:commandLink action="login?faces-redirect=true"
value="#{showElementBean.showElement()}"> Login </h:commandLink>
<h:commandButton action="login?faces-redirect=true" value="Move to login.xhtml" />
这些标签位于表单内,登录只是一个示例。单击呈现的控件的结果始终是刷新当前页面的 POST。我有什么错吗?
编辑: 根据 BalusC 的评论,我添加了真实的代码片段:
<h:commandLink actionListener="#{showElementBean.showElement(element)}"
value="View" > </h:commandLink>
我有一个包含元素列表的页面,我想添加指向元素视图页面的链接。因此我需要将此元素传递到显示页面。我是 JSF 入门者,例如在 Rails 中我会使用 GET 和 URL 参数,但我不知道如何“以 JSF 方式”执行此操作。
I'm using JSF 2.0 and I have a problem with navigation after both commandLink and commandButton. I use following code:
<h:commandLink action="login?faces-redirect=true"
value="#{showElementBean.showElement()}"> Login </h:commandLink>
<h:commandButton action="login?faces-redirect=true" value="Move to login.xhtml" />
These tags are inside a form, login is just an example. Result of clicking on rendered controls is always POST with refresh of a current page. What do I wrong?
Edit:
According to comments of BalusC I' adding real code fragment:
<h:commandLink actionListener="#{showElementBean.showElement(element)}"
value="View" > </h:commandLink>
I have a page with a list of elements and I want to add links that leads to element view page. Thus I need to pass this element to a show page. I'm JSF primer, e.g. in Rails I'd use GET and URL params, but I don't know how to do it 'in JSF-way'.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
造成这种行为的可能原因有很多。以下答案中均引用了它们以及解决方案: commandButton/commandLink/ajax action/未调用侦听器方法或未更新输入值。
但是,在您的特定情况下,您似乎对普通 GET 请求而不是 POST 请求更感兴趣,因为您想要的只是简单的页面到页面导航。在这种情况下,您需要使用
或
来代替:(我不知道您要做什么使用 both
#{showElementBean.showElement()}
和Login
作为命令链接值,所以我省略了前者)请参阅还有:
There are a lot of possible causes for this behaviour. They are all cited in the following answer, along with solutions: commandButton/commandLink/ajax action/listener method not invoked or input value not updated.
However, in your particular case, you seem rather to be interested in plain GET requests instead of POST requests, as all you want is simple page-to-page navigation. In that case, you need a
<h:link>
or<h:button>
instead:(I have no idea what you're trying to do with both
#{showElementBean.showElement()}
andLogin
as command link value, so I omitted the former)See also:
请参阅此信息:JSF HTML 标签< /强>
Refer this info: JSF HTML Tags
请注意,如果表单用于文件上传,则不会调用支持 bean 方法:
Noticed that backing bean method is not called if the form is for file upload:
<h:form name="searchForm" enctype="multipart/form-data" method="post" action="/search">
我也遇到了这个问题并添加了
解决了我的问题。
I also faced with that issue and adding the
<h:form><h:commandLink></h:commandLink> </h:form>
solved my problem.