Jsf 使p:commandButton像h:button一样工作
我的webapp中有以下工作代码:Jsf 使p:commandButton像h:button一样工作,jsf,jsf-2,primefaces,Jsf,Jsf 2,Primefaces,我的webapp中有以下工作代码: <h:button value="Edit user..." outcome="/public/user" > <f:param name="userName" value="#{authBean.authUser}"/> </h:button> 它的作用是: 它使按钮发送一个GET 它在URL中传递指定的参数,使其成为可书签的 我需要的是: 它应该像上面的h:按钮一样工作(send-GET) 该按钮应与其他
<h:button value="Edit user..." outcome="/public/user" >
<f:param name="userName" value="#{authBean.authUser}"/>
</h:button>
它的作用是:
- 它应该像上面的h:按钮一样工作(send-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>
它发送一个帖子,该帖子被重定向到带有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&secondParam=otherValue">
后者的结果是:
500:javax.servlet.ServletException:
分析/sample0.xhtml时出错:错误
跟踪[第14行]对
实体“secondParam”必须以
';' 定界符
更新2:应转义(&S):
<p:linkButton value="Edit user..." href="http://localhost:8080/contextpath/faces/public/user.xhtml?userName=myusername&secondParam=otherValue">
看起来不错。。。但我仍然得到了“放弃”和“重新发送”的消息:
这是我一直在尝试的完整空页:
<?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版本。使用
更新:根据代码示例的更新,URL应该在
href
属性中指定,而不是在URL
属性中指定。另请参阅我在上面链接的组件文档
这些症状至少听起来像是在触发异步(Ajax)GET请求,而不是同步请求。当请求在不同的域上触发时,FireBug确实会给出这种错误
难道您没有其他一些Java脚本干扰/冲突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>
试验
在PrimeFaces 2.2中,我们将弃用linkButton并引入p:button。出票
我确实尝试了p:linkButton,但它不起作用。Firebug说GET请求被中止,当前页面再次发布。抱歉,我没有进行完整复制/粘贴。我使用的是“href”属性,“url”甚至不被Netbeans接受。我现在将检查其他javascript…在一个空页面上p:linkButton工作。。。某种程度上。f:参数不起作用。如果我直接在URL中指定参数(例如:“…/user.xhtml?userName=myusername”),它就会工作。当我再指定一个参数时,Glassfish说500:javax.servlet.ServletException:Error Parsing/sample0.xhtml:Error tracked[line:14]对实体“relVerMin”的引用必须以“;”结尾定界符。(relVerMin是我的第二个参数,比如:“…/delrel.xhtml?relVerMaj=1&relVerMin=0”)呜呼!我在原始页面上使用p:dataTable。我在空白页上插入了相同的表格,问题出现了。。。没有自定义javascript。。。那么p:dataTable与p:linkButton不兼容?好吧,我想我累了。也许我应该逃离“&”!明天就试试。啊,不错。你能详细解释一下具体的问题吗?好的,现在我将继续使用没有图片的h:按钮。感谢巴卢斯克的时间和努力,当然也感谢卡加泰的回答;-)这是新的p:按钮;
<!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>