簡體   English   中英

JSF 2復合組件insertChildren標記將@ViewScoped轉換為@RequestScoped :(

[英]JSF 2 Composite component insertChildren tag making @ViewScoped into @RequestScoped :(

我有一個問題,我的@ViewScoped托管bean的行為就像@RequestScoped托管bean一樣,僅僅是因為我正在使用Composite:insertChildren標記。 我已經閱讀了該主題的其他文章,並且知道@ViewScopedmanagedBeans的局限性,但是我沒有任何顯式綁定,也沒有在復合組件中使用JSTL。

我假設insertChildren標記已綁定到ManagedBean,但我希望那里的人可以讓我擺脫困境,並向我顯示解決方法-我真的不想開始使用@SessionScoped bean。 :)

這是我的簡化示例。 簡單托管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)一起使用,一切都會按預期進行。 我輸入了一些文本,請按Submit(提交),同時顯示錯誤和輸入的文本。 在這一點上,我很高興。

<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及其組件移出復合組件,並替換為Composite:insertChildren標記,如下所示,當我輸入一些文本並按Submit時,將顯示正確的錯誤消息,但是由於@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>

有什么想法或建議嗎?

提前致謝。

對於其他有相同問題的人:

這是JSF中的已知錯誤->更多信息,請參見http://java.net/jira/browse/JAVASERVERFACES-2040

可能的解決方法是將構面添加到組合界面,並使用cc:renderFacet而不是cc:insertChildren呈現構面。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM