我正在制作一个自定义登录对话框,类似于 http://www.primefaces.org/showcase/ui/dialogLogin.jsf 上找到的对话框但我在构建时遇到错误:
javax.el.PropertyNotFoundException: /WEB-INF/templates/BasicTemplate.xhtml @58,83 oncomplete="handleLoginRequest(#{securityController.logIn})": The class 'managedbeans.SecurityController' does not have the property 'logIn'.
我认为错误在于我尝试触发日志记录程序的方式。有人可以看看我的语法是否正确吗?
<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...
最佳答案
您必须从 p:commandButton
的 actionListener
属性调用登录方法,而不是在 oncomplete
属性内调用。示例中的 javascript 函数无需更改即可使用。仅用于展示效果。
按如下方式更改您的 p:commandButton
:
<p:commandButton value="Login" update="growl"
oncomplete="handleLoginRequest(xhr, status, args)"
actionListener="#{securityController.logIn}"
/>
并按照 primefaces 展示中的方式使用 js 函数:
<script type="text/javascript">
function handleLoginRequest(xhr, status, args) {
if(args.validationFailed || !args.loggedIn) {
jQuery('#dialog').parent().effect("shake", { times:3 }, 100);
} else {
dlg.hide();
jQuery('#loginLink').fadeOut();
}
}
</script>
关于java - 如何将参数传递给 JSF 2.0 页面上的 javascript 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5647224/