2012-12-14 65 views
1

我已將primefaces-3.4RC1.jar包含在WEB-INF/lib目錄中。在我的控制器即時自動裝配我的模型豆狀PrimeFaces 3.4 RC1,對話框無法識別託管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 @ 230119 值= 「#{myController.loc.countryId}」:類 「com.deltasoft.controller.myCo ntroller'沒有 'loc'屬性。

+0

我認爲你需要用@ManagedBean和一些範圍註釋myController的,那麼你就需要一個getter for loc –

+0

@AkselWillgert我編輯了這個問題來添加更多細節我已經用託管bean註釋了控制器並定義了範圍 – dakait

+0

但是你確實有get之三?還有一個錯字,我認爲:countryID vs countryId? –

回答

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

我需要定義託管道具的getters和setter嗎? – dakait

+0

是的。它就像'@ Autowired'一樣,但是'Autowired'則是將spring bean注入另一個spring定義的bean中。 'ManagedProperty'是將Spring或JSF創建的bean注入到JSF'@ ManagedBean'中。 – SRy

+0

tnx男子,解決了概率... – dakait

相關問題