【问题标题】:PrimeFaces 3.4 RC1, dialog not recognizing the Managed Bean propertyPrimeFaces 3.4 RC1,对话框无法识别托管 Bean 属性
【发布时间】:2012-12-14 05:18:04
【问题描述】:

我已将primefaces-3.4RC1.jar 包含在WEB-INF/lib 目录中。在我的控制器中,我像

一样自动装配我的模型 bean
@ManagedBean
@RequestScoped
public class MyController{

@Autowired
Location loc;

//other stuff

}

我的Location 类看起来像

public class Location{     
    private Integer countryId;
    //getters setters
}

我的观点看起来像

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui">
    <div class="contentBox cornerBorder border">

    <p:dialog>
    <table class="DialogTable">                                                     
    <tr>
     <td><label>Country</label></td> 
        <h:selectOneMenu required="true" id="contry" styleClass="text-box" value="#{myController.loc.countryId}">   
    ----------------------------------------------------------------------------------------------^here it gives warning and if i run it crashes 

    </tr>
    </table>
    </p:dialog>

当我单击链接打开对话框时,它会抛出一个错误,即找不到属性 countryId。如果我删除 value="myController.loc.countryId" 它运行正常... 任何人都可以指导我正确的方向

P.S:我已经在应用程序 context.xml 中做了相应的条目


实际错误

严重:javax.el.PropertyNotFoundException: /WebPages/personal/personalDiv.xhtml @230,119 value="#{myController.loc.countryId}": 类 'com.deltasoft.controller.myController' 没有属性 'loc'。

【问题讨论】:

  • 我认为你需要用 @ManagedBean 和一些范围注释 MyController,然后你需要一个获取 loc 的方法
  • @AkselWillgert 我已经编辑了问题以添加更多详细信息我已经用托管 bean 注释控制器并定义了范围
  • 但是你有吸气剂吗?我认为也是一个错字:countryID vs countryId?
  • 我已经删除了错字,即使我已经自动装配了成员,我是否还需要 getter 和 setter?顺便说一句,我刚刚尝试从loc 中删除@Autowired 注释并定义了它的getter 和setter,没有运气
  • 在上面的帖子中你不应该用@Autowired注释Location loc。你应该用@ManagedProperty注释。改变它应该可以正常工作。

标签: eclipse jsf jsf-2 primefaces glassfish-3


【解决方案1】:

您可能希望像这样更改您的代码。

@ManagedBean
@RequestScoped
public class MyController{

@ManagedProperty
private Location loc;   // Getters and Setters.

//other stuff

}

@component
public class Location{     
    private Integer countryId;
    //getters setters
}

在你的 spring.xml 中你应该这样做

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:security="http://www.springframework.org/schema/security"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

 <context:component-scan="path to Location class path"/>
</beans>

【讨论】:

  • 我需要定义 managed prop 的 getter 和 setter 吗?
  • 是的。就像@AutowiredAutowired 是将spring bean 注入另一个spring 定义的bean。而ManagedProperty是将Spring或JSF创建的bean注入到JSF@ManagedBean中。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-16
  • 2013-06-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多