【发布时间】:2010-07-26 07:00:42
【问题描述】:
我的 webapp 中有这个工作代码:
<h:button value="Edit user..." outcome="/public/user" >
<f:param name="userName" value="#{authBean.authUser}"/>
</h:button>
它的作用:
- 它使按钮发送一个 GET
- 它在 URL 中传递指定的参数,使其可收藏。
我需要什么:
- 它应该像上面的 h:button 一样工作(发送 GET)
- 按钮应该看起来像其他 Primefaces 按钮(例如,装饰有图像......等)。
这是我能得到的最接近的:
<p:commandButton value="Edit user..." action="/public/user?faces-redirect=true" ajax="false" immediate="true" >
<f:param name="userName" value="#{authBean.authUser}"/>
</p:commandButton>
它发送一个 POST,该 POST 使用 GET 重定向到新 URL。但是参数在这个过程中丢失了。
另一个想法:
<p:linkButton value="Edit user..." href="http://localhost:8080/contextpath/faces/public/user.xhtml">
<f:param name="userName" value="#{authBean.authUser}"/>
</p:linkButton>
GET 请求被中止(??? 根据 Firebug),当前页面再次被 POST。
这样做的正确方法是什么?
更新:这有效(在一个空页面上,没有 p:dataTable):
<p:linkButton value="Edit user..." href="http://localhost:8080/contextpath/faces/public/user.xhtml?userName=myusername">
但事实并非如此:
<p:linkButton value="Edit user..." href="http://localhost:8080/contextpath/faces/public/user.xhtml?userName=myusername&secondParam=otherValue">
后者导致:
500:javax.servlet.ServletException: 错误解析 /sample0.xhtml: 错误 Traced[line: 14] 参考 实体“secondParam”必须以 ';'分隔符。
UPDATE2:& 应该被转义:
<p:linkButton value="Edit user..." href="http://localhost:8080/contextpath/faces/public/user.xhtml?userName=myusername&secondParam=otherValue">
它看起来不错......但我仍然得到 GET 中止和 POST 重新发送:
alt text http://img64.imageshack.us/img64/1017/primefaceslinkbutton.jpg
这是我一直在尝试的完整空白页面:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.prime.com.tr/ui">
<h:head />
<h:body>
<h:form>
<p:linkButton value="Click me" href="http://stackoverflow.com" />
</h:form>
</h:body>
</html>
Primefaces 2.1 版本。
【问题讨论】:
标签: jsf jsf-2 primefaces