user2033789
user2033789

Reputation: 21

Primefaces binding Bean with form

I'm developing an application with primefaces, I´m trying to map my form with my Bean of User but i can't, this is my code:

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

Backing 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());
    }

}

in my bean declare a object of User, I'm using the object user for map my form with my bean but I get an error when map to bean with my form

Upvotes: 2

Views: 4544

Answers (2)

fante76
fante76

Reputation: 55

I think it's also wrong the syntax of method calling, it should be

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

without parenthetis.

Upvotes: 0

partlov
partlov

Reputation: 14277

You are using binding attribute completely wrong. In your case you shouldn't use binding, replace it with value attribute. binding is used if you want to bind whole component with some UIComponent property of your backing bean, and manage component attributes programmatically. Value provide connection between component value, and some backing bean property.

Upvotes: 4

Related Questions