【问题标题】:Primefaces binding Bean with formPrimefaces 将 Bean 与表单绑定
【发布时间】:2013-02-12 18:58:25
【问题描述】:

我正在使用 primefaces 开发一个应用程序,我正在尝试将我的表单与我的用户 Bean 映射但我不能,这是我的代码:

<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 中声明一个用户对象,我正在使用对象用户将我的表单与我的 bean 映射,但是当我用我的表单映射到 bean 时出现错误

【问题讨论】:

  • 你得到什么错误?

标签: jsf primefaces


【解决方案1】:

您使用的绑定属性完全错误。在您的情况下,您不应该使用绑定,请将其替换为 value 属性。 binding 用于将整个组件与支持 bean 的一些 UIComponent 属性绑定,并以编程方式管理组件属性。值提供组件值和一些支持 bean 属性之间的连接。

【讨论】:

    【解决方案2】:

    我觉得也是方法调用的语法不对,应该是

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

    没有括号。

    【讨论】:

      猜你喜欢
      • 2012-04-08
      • 2020-09-01
      • 2016-03-12
      • 1970-01-01
      • 2015-11-19
      • 2015-07-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多