2011-04-13 107 views
2

我想提出一個自定義登錄對話框,類似於一個在http://www.primefaces.org/showcase/ui/dialogLogin.jsf發現卻得到一個錯誤,當建築:我如何將參數傳遞給JavaScript函數的JSF 2.0頁

javax.el。 PropertyNotFoundException:/WEB-INF/templates/BasicTemplate.xhtml @ 58,83 oncomplete =「handleLoginRequest(#{securityController.logIn})」:類'managedbeans.SecurityController'沒有屬性'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="[email protected]: *" /> 
     <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> 

而這一點,認爲被調用的onComplete事件的方法管理bean:

@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... 
+0

可以傳遞參數不是方法的JavaScript – niksvp 2011-04-13 09:50:26

回答

3

您必須致電actionListener屬性actionListener屬性的登錄方法,而不是在oncomplete屬性中。示例中的JavaScript函數可以不加更改地使用。它僅用於顯示效果。

更改p:commandButton這樣:

<p:commandButton value="Login" update="growl"      
     oncomplete="handleLoginRequest(xhr, status, args)" 
     actionListener="#{securityController.logIn}" 
/> 

,準確地使用js函數作爲primefaces展示:

<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> 
+0

@sfrj與您的案例'#{securityController.logIn}'這將在'securityController'控制器bean中搜索'getLogIn()',您將它作爲值傳遞。 @Matt +1 – 2011-04-13 09:59:56

+0

我做到了,現在我沒有得到構建錯誤。但是當我點擊提交按鈕時,我得到一個錯誤。我認爲它與EJB有關。我會進行更新以向你展示。 – sfrj 2011-04-13 10:06:15

0

如果你想在JavaScript事件執行方法,然後用<a4j:jsfunction>

here

+0

您聯繫的ISN」 t工作 – Teneff 2011-04-13 09:54:04

+0

你忘了鏈接到示例 – sfrj 2011-04-13 09:54:17

+0

@sfrj:是的,chk更新 – niksvp 2011-04-13 09:54:52

相關問題