1

我已将其包含primefaces-3.4RC1.jarWEB-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"它运行正常...任何人引导我朝着正确的方向

PS:我已经在应用程序 context.xml 中做了适当的条目


实际错误

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

4

1 回答 1

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>
于 2012-12-14T05:48:28.850 回答