【问题标题】:JSF custom component with @FacesComponent is not found in Spring Boot在 Spring Boot 中找不到带有 @FacesComponent 的 JSF 自定义组件
【发布时间】:2012-03-29 21:00:58
【问题描述】:

我想创建一个自定义 JSF 2.0 组件,但无法使其工作。 我的组件是这样定义的:

 @FacesComponent(value = "myCustomComponent")
 public class CommaSeperatedOutput extends UIComponentBase { ... }

标签库如下所示:

 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
 <facelet-taglib xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facelettaglibrary_2_0.xsd" version="2.0"> 
<namespace>http://www.company.com/tags</namespace>
<tag>
    <tag-name>custom</tag-name>
      <component>
        <component-type>myCustomComponent</component-type>
      </component>
</tag>
</facelet-taglib>

我的 faces-config 如下所示:

<faces-config version="2.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
  http://java.sun.com/xml/ns/javaee
  http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd">
<application>
    <el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
</application>
</faces-config>

我收到以下错误:

SEVERE: JSF1068: Component with componenttype myCustomComponent could not be instantiated.
javax.faces.FacesException: Expression Error: Named Object: myCustomComponent not found.

不确定它是否重要,但我在这里使用 Spring 3.1 和 JSF 2.1。所以依赖是由 Spring 管理的。

知道这里发生了什么吗?

【问题讨论】:

  • 这绝对是Spring的问题。 JSF 部分看起来不错。所以我添加了[spring] 标签,这样你也可以得到 Spring 家伙的关注。
  • 你也可以尝试使用复合组件来代替自定义组件。
  • 这是一个很好的伴侣。

标签: spring spring-boot jsf custom-component


【解决方案1】:

[这里是移动作者的解决方案]

似乎 Spring 是这里的坏人。 我已经从组件中删除了注释 @FacesComponent(value = "myCustomComponent") 并在我的 faces-config 中定义它,如下所示:

<component>
    <component-type>myCustomComponent</component-type>
    <component-class>com.company.jsf.component.CommaSeperatedOutput</component-class>
</component>

现在可以了。

【讨论】:

    【解决方案2】:

    另外,由于您已将 faces-config.xml 文件配置为使用 Spring 容器,您可以使用 Spring 注释 @Component("myCustomComponent")

    【讨论】:

    • 不,这意味着自定义组件将成为单例。这不是我想要的。
    • 用第二个注解来操作范围:例如@Scope("request") 或@Scope("prototype")。试试这个备忘单:refcardz.dzone.com/refcardz/spring-annotations
    猜你喜欢
    • 2014-10-18
    • 2012-01-29
    • 2014-09-03
    • 1970-01-01
    • 2020-05-30
    • 2014-02-21
    • 2015-01-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多