egb*_*kul 5 jsf primefaces jsf-2
我的webapp中有这个工作代码:
<h:button value="Edit user..." outcome="/public/user" >
<f:param name="userName" value="#{authBean.authUser}"/>
</h:button>
Run Code Online (Sandbox Code Playgroud)
它能做什么:
我需要的:
这是我能得到的最接近的:
<p:commandButton value="Edit user..." action="/public/user?faces-redirect=true" ajax="false" immediate="true" >
<f:param name="userName" value="#{authBean.authUser}"/>
</p:commandButton>
Run Code Online (Sandbox Code Playgroud)
它发送一个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>
Run Code Online (Sandbox Code Playgroud)
GET请求被中止(???根据Firebug)并且当前页面再次被POST.
这样做的正确方法是什么?
更新:这是有效的(在空白页面上,没有p:dataTable):
<p:linkButton value="Edit user..." href="http://localhost:8080/contextpath/faces/public/user.xhtml?userName=myusername">
Run Code Online (Sandbox Code Playgroud)
但这不是:
<p:linkButton value="Edit user..." href="http://localhost:8080/contextpath/faces/public/user.xhtml?userName=myusername&secondParam=otherValue">
Run Code Online (Sandbox Code Playgroud)
后者导致:
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">
Run Code Online (Sandbox Code Playgroud)
它看起来不错......但我仍然得到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>
Run Code Online (Sandbox Code Playgroud)
Primefaces 2.1发布.
使用p:linkButton
。
更新:根据代码示例的更新,URL 应在href
属性中指定,而不是在url
属性中指定。另请参阅我上面链接的组件文档。
这些症状至少听起来像是您正在触发异步 (Ajax) GET 请求,而不是同步请求。当请求在不同的域上触发时,FireBug 确实会给出这种错误。
您是否有其他一些 Javascript 会干扰/与 linkButton 的默认行为发生冲突?该按钮通过简单的 进行导航onclick="window.location=newurl;"
。
更新2:如果你在一个简单的页面中独立测试它是否有效?例如
<!DOCTYPE html>
<html xmlns="http://www.w3c.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.prime.com.tr/ui">
<h:head>
<title>Test</title>
</h:head>
<h:body>
<p:linkButton value="test" href="http://stackoverflow.com" />
</h:body>
</html>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
17213 次 |
最近记录: |