【问题标题】:JSF 2 Composite component insertChildren tag making @ViewScoped into @RequestScoped :(JSF 2 复合组件 insertChildren 标记使 @ViewScoped 变为 @RequestScoped :(
【发布时间】:2011-05-04 06:24:13
【问题描述】:

我遇到了一个问题,即我的 @ViewScoped 托管 bean 的行为类似于 @RequestScoped managedBean,因为我使用的是复合:insertChildren 标记。我已阅读有关该主题的其他帖子,并且知道 @ViewScoped managedBeans 的局限性,但我没有任何显式绑定,也没有在我的复合组件中使用 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),一切都按预期工作。我输入了一些文本,按提交,错误与输入的文本一起显示。在这一点上,我很高兴。

<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 标记,如下所示,当我输入一些文本并按下提交时,会显示正确的错误消息,但由于再次调用@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>

有什么想法或建议吗?

提前致谢。

【问题讨论】:

    标签: java jsf-2 composite-component


    【解决方案1】:

    对于有同样问题的其他人:

    这是 JSF 中的一个已知错误 -> 更多信息请参阅 http://java.net/jira/browse/JAVASERVERFACES-2040

    一种可能的解决方法是向复合界面添加一个构面,并使用 cc:renderFacet 而不是 cc:insertChildren 呈现构面。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-10
      • 2012-08-12
      • 2013-11-10
      • 1970-01-01
      • 2011-07-10
      • 1970-01-01
      • 1970-01-01
      • 2011-09-14
      相关资源
      最近更新 更多