如何将参数传递给 JSF 2.0 页面上的 javascript 函数
我正在制作一个自定义登录对话框,类似于 http://www.primefaces 上找到的对话框.org/showcase/ui/dialogLogin.jsf 但我在构建时遇到错误:
javax.el.PropertyNotFoundException:/WEB-INF/templates/BasicTemplate.xhtml @58,83 oncomplete =“handleLoginRequest(#{securityController.logIn})”:类“managementbeans.SecurityController”没有属性“登录'。
我认为错误在于我尝试触发日志记录程序的方式。有人可以看看我的语法是否正确吗?
<p:dialog id="dialog" header="Login" widgetVar="dlg" modal="true" width="400" resizable="false" draggable="false" fixedCenter="true">
<h:form>
<h:panelGrid columns="2" cellpadding="5">
<h:outputLabel for="username" value="Em@il: *" />
<p:inputText value="#{securityController.email}"
id="email" required="true" label="email" />
<h:outputLabel for="password" value="Password: * " />
<h:inputSecret value="#{securityController.password}"
id="password" required="true" label="password" />
<f:facet name="footer">
<p:commandButton value="Login" update="growl"
oncomplete="handleLoginRequest(#{securityController.logIn})"/>
</f:facet>
</h:panelGrid>
</h:form>
</p:dialog>
<script type="text/javascript">
function handleLoginRequest(input) {
if(input == false) {
jQuery('#dialog').parent().effect("shake", { times:3 }, 100);
} else {
dlg.hide();
jQuery('#loginLink').fadeOut();
}
}
</script>
这是托管 bean,它保存正在调用 onComplete 事件的方法:
@ManagedBean
@RequestScoped
public class SecurityController {
@EJB
private IAuthentificationEJB authentificationEJB;
private String email;
private String password;
private String notificationValue;
public void logIn() {
if(authentificationEJB.saveUserState(email, password)) {
notificationValue = "Dobro dosli";
}
}
//getters and setters...
I am making a custom login dialog, similar to the one found on http://www.primefaces.org/showcase/ui/dialogLogin.jsf but i get an error when building:
javax.el.PropertyNotFoundException: /WEB-INF/templates/BasicTemplate.xhtml @58,83 oncomplete="handleLoginRequest(#{securityController.logIn})": The class 'managedbeans.SecurityController' does not have the property 'logIn'.
I think the mistake is in the way i try to trigger the logging procedure. Could someone have a look if my syntax is correct?
<p:dialog id="dialog" header="Login" widgetVar="dlg" modal="true" width="400" resizable="false" draggable="false" fixedCenter="true">
<h:form>
<h:panelGrid columns="2" cellpadding="5">
<h:outputLabel for="username" value="Em@il: *" />
<p:inputText value="#{securityController.email}"
id="email" required="true" label="email" />
<h:outputLabel for="password" value="Password: * " />
<h:inputSecret value="#{securityController.password}"
id="password" required="true" label="password" />
<f:facet name="footer">
<p:commandButton value="Login" update="growl"
oncomplete="handleLoginRequest(#{securityController.logIn})"/>
</f:facet>
</h:panelGrid>
</h:form>
</p:dialog>
<script type="text/javascript">
function handleLoginRequest(input) {
if(input == false) {
jQuery('#dialog').parent().effect("shake", { times:3 }, 100);
} else {
dlg.hide();
jQuery('#loginLink').fadeOut();
}
}
</script>
And this the managed bean that holds the method that is being called onComplete event:
@ManagedBean
@RequestScoped
public class SecurityController {
@EJB
private IAuthentificationEJB authentificationEJB;
private String email;
private String password;
private String notificationValue;
public void logIn() {
if(authentificationEJB.saveUserState(email, password)) {
notificationValue = "Dobro dosli";
}
}
//getters and setters...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须从
p:commandButton
的actionListener
属性调用登录方法,而不是在oncomplete
属性内调用。示例中的 javascript 函数无需更改即可使用。仅用于展示效果。以这种方式更改您的
p:commandButton
:并使用与 primefaces 展示中完全相同的 js 函数:
You have to call your login method from the
actionListener
attribute ofp:commandButton
and not inside theoncomplete
attribute. The javascript function from the example can be used without changes. It is only for displaying the effect.Change your
p:commandButton
this way:And use the js function exactly as in the primefaces showcase:
如果您想在 javascript 事件上执行方法,请使用
示例 此处。
If you want to execute method on a javascript event then use
<a4j:jsfunction>
Example here.