Jsf 2 p:commandButton未触发actionlistener
好的,我已经阅读了所有关于这个问题的帖子,但我找不到。我的情况非常简单——我所做的就是使用Primefaces 3.3.1和JSF 2.1来呈现登录页面。代码如下:Jsf 2 p:commandButton未触发actionlistener,jsf-2,primefaces,Jsf 2,Primefaces,好的,我已经阅读了所有关于这个问题的帖子,但我找不到。我的情况非常简单——我所做的就是使用Primefaces 3.3.1和JSF 2.1来呈现登录页面。代码如下: <?xml version="1.0" encoding="ISO-8859-1" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:pe="http://primefaces.org/ui/extensions"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>ACME Systems - Home Page</title>
<style>
.noBorders tr, .noBorders td {
background: none !important;
border: none !important;
}
</style>
</h:head>
<h:body>
<p:panel id="mainPanel"
style="height: 106px; height: auto !important; margin: 0 auto; min-height: 106px; position: relative; width: 960px; z-index: 100;">
<h:form id="loginForm">
<p:panel header="Secure Login"
style="padding-bottom: 40px; width: 380px;">
<p:panelGrid columns="2" styleClass="noBorders">
<h:outputText value="Username:" />
<p:inputText id="username" required="true"
requiredMessage="Username is required." title="Username"
value="#{LoginBean.username}" />
<h:outputText value="Password:" />
<p:password id="password" required="true"
requiredMessage="Password is required"
value="#{LoginBean.password}" />
</p:panelGrid>
<p:commandButton id="loginButton" value="Login"
actionListener="#{LoginBean.login}"
style="margin-top: 5px; float: right;" />
</p:panel>
</h:form>
</p:panel>
</h:body>
</html>
ACME系统-主页
.NOBOORDERS tr、.NOBOORDERS td{
背景:无!重要;
边界:没有!重要;
}
commandbutton上的actionlistener未启动。如果我把它改成h:commandbutton,一切都很好。我更喜欢使用primefaces标记,因为它使用了主题。如果我使用h:那么我需要获取css。有什么想法吗?还有一件事,如果我在primefaces按钮前面放一个h:commandbutton,然后用它来做初始触发,primefaces按钮从那时起就开始工作了:P,开始 既然我修好了,就要结束这个了。也许将来有人可以使用这些信息。我会确保您阅读了Primefaces(或任何框架)的代码样本,并使用它们的确切代码,直到您感觉自己掌握了它为止。在使用JSF 6年之后,我仍然没有弄明白所有的事情,比如BalusC:-)我不知怎么修复了它。我向commandbutton添加了一个update=并将其设置为outerpanel。我还将label属性添加到输入字段中。添加更新属性是什么修复了它,还是向外部面板添加了id?奇怪。在执行操作后,您确实没有更新UI,因此最终用户根本不会得到反馈(除非操作方法使用
ExternalContext\redirect()
或NavigationHandler\handleNavigation()
)。您是如何确认动作侦听器没有启动的?您是在实际方法上设置了调试断点还是在其中添加了记录器?或者你只是得出这样的结论:在没有查看HTTP流量和代码执行的情况下,你没有得到任何UI反馈?我添加了一个日志,但什么也没有出现。那时我知道我通过primefaces组件做了错事。也许这就是为什么他们的showcase示例有时会在自己的示例上使用h标记的原因。在我的例子中,我想把所有的东西都保持在主题内,否则我会选择h标签。