2010-11-03 57 views
4

我有一個問題,我的@ViewScoped託管bean的行爲就像一個@RequestScoped managedBean,因爲我使用的是composite:insertChildren標記。關於這個主題的其他帖子,我知道@ViewScoped managedBeans的侷限性,但是我沒有任何顯式的綁定,也沒有在我的複合組件中使用JSTL。JSF 2複合組件insertChildren標記使@ViewScoped進入@RequestScoped :(

我假設insertChildren標籤被綁定到managedBean,但我希望有人能讓我擺脫不幸,並向我展示一種解決方法 - 我真的不想開始使用@SessionScoped beans。:)

這是我的簡單示例。簡單託管Bean:

@ManagedBean(name = "simpleMB") 
@ViewScoped 
public class SimpleManagedBean implements Serializable { 

    private static final long serialVersionUID = -1; 

    @NotNull 
    @Email 
    private String email; 

    public SimpleManagedBean() { 
     System.out.println("SimpleManagedBean"); 
    } 

    @PostConstruct 
    public void postConstruct() { 
     System.out.println("Post construct"); 
    } 

    public String submit() { 
     return null; 
    } 

    ... setter and getter 
} 

使用上述SimpleManagedBean的形式和複合材料部件(不insertChildren)之下,一切正常。我輸入一些文本,按提交,錯誤與輸入的文本一起顯示。在這一點上,我很高興。現在

<h:form> 
    <foo:simpleNoChildren /> 

    <h:commandButton id="submit" 
        value="Submit" 
        action="#{simpleMB.submit}" /> 
</h:form> 

... and the composite component .... 

<composite:interface /> 
<composite:implementation> 

<h:panelGrid columns="3"> 
    <h:outputText value="Email" /> 

    <h:inputText id="email" 
       value="#{simpleMB.email}" 
       required="true" /> 

    <h:message for="email" /> 
</h:panelGrid> 

</composite:implementation> 

,如果我移動panelGrid中和它的零部件,使之複合材料部件,並用一個複合取代:insertChildren標籤,如下圖所示,當我輸入一些文字,然後按提交,顯示正確的錯誤信息,但由於再次調用@PostConstruct方法,我輸入的文本不再顯示。 :(

<h:form> 
    <foo:simple> 

    <h:panelGrid columns="3"> 
    <h:outputText value="Email" />   
    <h:inputText id="email" value="#{simpleMB.email}" required="true" /> 
     <h:message for="email" /> 
    </h:panelGrid> 

    </foo:simple>  

    <h:commandButton id="submit" value="Submit" action="#{simpleMB.submit}" /> 
</h:form> 

... and my complicated composite component :) ... 

<composite:interface /> 
<composite:implementation> 
    <composite:insertChildren /> 
</composite:implementation> 

任何想法或建議

在此先感謝

回答