JSF commandButton URL参数 [英] JSF commandButton URL parameters
问题描述
我想创建一个导航到其他URL并在URL中传递一些请求参数的按钮. outputLink可以工作,但是我想要一个按钮,commandButton看起来不错,但是我可以传递参数.
I would like to make a button which navigates to a different URL and pass some request parameters through in the URL. The outputLink works but I would like a button, the commandButton looks good but I can pass parameters.
有解决方案吗?
推荐答案
h:commandButton
不会触发GET
请求,但是会触发POST
请求,因此您无法使用它.如果您已经在JSF 2.0上并且目标页面位于相同的上下文中,则可以为此使用h:button
:
The h:commandButton
doesn't fire a GET
request, but a POST
request, so you can't use it. If you're already on JSF 2.0 and the target page is in the same context, then you can use the h:button
for this:
<h:button value="press here" outcome="otherViewId">
<f:param name="param1" value="value1" />
<f:param name="param2" value="value2" />
</h:button>
(此处与h:outputLink
一样不需要h:form
).这将创建一个转到otherViewId.jsf?param1=value1¶m2=value2
的按钮.
(no h:form
is required here as in h:outputLink
). This will create a button which goes to otherViewId.jsf?param1=value1¶m2=value2
.
但是,如果您还没有使用JSF 2.0,那么最好的办法就是抓住CSS来像按钮一样设置链接的样式.
But if you're not on JSF 2.0 yet, then your best is just to grab CSS to style the link like a button.
<h:outputLink styleClass="button">
类似
a.button {
display: inline-block;
background: lightgray;
border: 2px outset lightgray;
cursor: default;
}
a.button:active {
border-style: inset;
}
这篇关于JSF commandButton URL参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!