2013-02-12 120 views
2

我正在開發與primefaces的應用程序,我正嘗試繪製自己的狀態與我的用戶的Bean的,但我不能結合豆,這是我的代碼:Primefaces與形式

<h:form> 
    <p:panelGrid columns="2"> 
     <h:outputLabel for="usuario" value="Usuario: *"/> 
     <h:inputText id="usuario" binding="#{beanPrueba.user.usuario}"></h:inputText> 

     <h:outputLabel for="contrasena" value="Contraseña: *" /> 
     <h:inputSecret id="contrasena"></h:inputSecret> 

    <f:facet name="footer"> 
    <p:commandButton icon="ui-icon-check" value="Entrar" ajax="false" 
       action="#{beanPrueba.prueba()}"/> 
    </f:facet> 
    </p:panelGrid> 
</h:form> 

支持bean :

@ManagedBean(name = "beanPrueba") 
@SessionScoped 
public class BeanLogin { 

private Usuario user = new Usuario(); 

public Usuario getUser() { 
    return user; 
} 

public void setUser(Usuario user) { 
    this.user = user; 
} 

public void prueba() 
{ 
    try { 
     //my code 
    } 
    catch(Exception ex) 
    { 
     System.out.print(ex.getMessage()); 
    } 

} 
在我的豆

聲明用戶的對象,我使用我的地圖形式與我的bean對象用戶但當地圖與我的form bean

+1

你會得到什麼錯誤? – 2013-02-13 04:24:20

回答

4

您使用我得到一個錯誤綁定屬性完全錯誤。在你的情況下,你不應該使用綁定,用value屬性替換它。 binding用於如果要將整個組件綁定到支持bean的某些UIComponent屬性並以編程方式管理組件屬性。值提供組件值和一些支持bean屬性之間的連接。

0

我想這也是錯誤的方法調用的語法,它應該是

<p:commandButton icon="ui-icon-check" value="Entrar" ajax="false" 
      action="#{beanPrueba.prueba}"/> 

沒有parenthetis。