JSF 2.0在commandLink和commandButton上导航不起作用 [英] JSF 2.0 navigating on commandLink and commandButton doesn't work
问题描述
我正在使用JSF 2.0,在commandLink和commandButton之后都无法导航.我使用以下代码:
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" />
这些标记位于表单内,登录仅是示例.单击呈现的控件的结果始终是POST,同时刷新当前页面.我怎么了?
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?
修改: 根据BalusC的评论,我添加了真实的代码片段:
According to comments of BalusC I' adding real code fragment:
<h:commandLink actionListener="#{showElementBean.showElement(element)}"
value="View" > </h:commandLink>
我有一个包含元素列表的页面,并且我想添加指向元素视图页面的链接.因此,我需要将此元素传递给显示页面.我是JSF入门,例如在Rails中,我将使用GET和URL参数,但是我不知道如何在JSF中使用它.
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'.
推荐答案
此行为有很多可能的原因.在以下答案中均引用了它们,并给出了解决方案: commandButton/commandLink/ajax action/未调用侦听器方法或输入值未更新.
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.
但是,在您的特定情况下,您似乎宁愿对普通的GET请求而不是POST请求感兴趣,因为您想要的只是简单的页面到页面导航.在这种情况下,您需要使用<h:link>
或<h:button>
:
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:
<h:link outcome="login" value="Login" />
<h:button outcome="login" value="Move to login.xhtml" />
(我不知道您要使用两者 #{showElementBean.showElement()}
和Login
作为命令链接值做什么,所以我省略了前者)
(I have no idea what you're trying to do with both #{showElementBean.showElement()}
and Login
as command link value, so I omitted the former)
这篇关于JSF 2.0在commandLink和commandButton上导航不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!