我的 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)并且当前页面被再次发布。
这样做的正确方法是什么?
更新:这有效(在一个空页面上,没有 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: Error Parsing /sample0.xhtml: Error 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 重新发送:
替代文字 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 发布。