标签: faces-config

在JSF 2中使用faces-config.xml有什么用?

在JSF 2对注释的大力支持之后,我想知道我将使用它faces-config.xml.它现在的重要性是什么?

换句话说,只能faces-config.xml通过注释而不是通过注释完成哪些配置?

现在我用它的所有东西都是声明Spring的EL解析器.

<?xml version="1.0" encoding="UTF-8"?>
<faces-config
    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"
    version="2.0">

    <application>
        <el-resolver>
            org.springframework.web.jsf.el.SpringBeanFacesELResolver
        </el-resolver>
    </application> 
</faces-config>
Run Code Online (Sandbox Code Playgroud)

jsf faces-config jsf-2

87
推荐指数
1
解决办法
7万
查看次数

引用文件包含错误(jar:file:/.../ plugins/org.jboss.tools.jst.web_3.5.0.Final-v20130717-0309-B75.jar!/catalog/web-facesconfig_2_2.xsd)

我在eclipse中使用JSF Project制作文件faces-config.xml会出错

Referenced file contains errors (jar:file:/D:/eclips/eclipse k/plugins/org.jboss.tools.jst.web_3.5.0.Final-v20130717-0309-B75.jar!/catalog/web-facesconfig_2_2.xsd). 
Run Code Online (Sandbox Code Playgroud)

faces-config.xml中

<?xml version="1.0" encoding="UTF-8"?>
<faces-config
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"
version="2.2">

</faces-config>
Run Code Online (Sandbox Code Playgroud)

当我删除以下行时,faces-config.xml中的错误指示消失

http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd
Run Code Online (Sandbox Code Playgroud)

更新我如何解决此问题?

xml jsf jboss-tools faces-config jsf-2

11
推荐指数
2
解决办法
2万
查看次数

faces-config.xml中的EL解析器

在进行Spring-JSF集成时,我看到了这个条目faces-config.xml.

<application>
    <el-resolver>
        org.springframework.web.jsf.el.SpringBeanFacesELResolver
    </el-resolver>
</application>
Run Code Online (Sandbox Code Playgroud)

有人可以解释究竟是什么<application>以及<el-resolver>是谁?

jsf spring el faces-config

8
推荐指数
1
解决办法
7771
查看次数

将faces-config.xml从2.2更改为2.3会导致javax.el.PropertyNotFoundException:无法到达目标,标识符“ bean”解析为null

具有以下代码段:

豆:

import javax.faces.view.ViewScoped;
import javax.inject.Named;

@Named(value = "directoryBean")
@ViewScoped
public class DirectoryBean implements Serializable {

private static final long serialVersionUID = 1L;
    ....
}
Run Code Online (Sandbox Code Playgroud)

faces-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<faces-config
    xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_3.xsd"
    version="2.3">
     ....
</faces-config>
Run Code Online (Sandbox Code Playgroud)

group.xhtml

<ui:composition ...>

    <f:metadata>
        <f:viewParam name="id" value="#{directoryBean.id}" />
    </f:metadata>

</ui:composition>
Run Code Online (Sandbox Code Playgroud)

结果得到异常:

javax.el.PropertyNotFoundException: /group.xhtml @6,64 value="#{directoryBean.id}": Target Unreachable, identifier 'directoryBean' resolved to null
Run Code Online (Sandbox Code Playgroud)

在将faces-config.xml从2.2版语法更改为2.3版语法后得到了它。

意思是,使用带有以下内容的faces-config.xml,一切正常:

<faces-config version="2.2" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd">
....
</faces-config>
Run Code Online (Sandbox Code Playgroud)

JSF 2.3.2部署在Payara 4.1.2.172(完整)服务器上,并且还添加到pom.xml中,“提供”范围。

....
<dependencies>
    ...
    <dependency>
        <groupId>org.glassfish</groupId>
        <artifactId>javax.faces</artifactId>
        <version>2.3.2</version>
        <scope>provided</scope> …
Run Code Online (Sandbox Code Playgroud)

jsf faces-config cdi jsf-2.3 propertynotfoundexception

7
推荐指数
1
解决办法
6278
查看次数

JSF面向WEB-INF外的配置文件?

在创建多个面配置文件时,在WEB-INF之外设置faces-config.xml是正确的吗?JSF规范似乎并不十分清楚(第10.1.3节)

如果是,那么应该如何在web.xml中声明faces-config.xml?IDE生成的路径(如Eclipse/JDev)通常使用如下内容:

<context-param>
    <param-name>javax.faces.CONFIG_FILES</param-name>
    <param-value>/WEB-INF/faces-config1.xml</param-value>
</context-param>
Run Code Online (Sandbox Code Playgroud)

现在,如果我的faces-config.xml在WEB-INF之外 - 将param-value声明为"/WebContent/WEB-INF/faces-config2.xml"是否正确?

java jsf web-inf faces-config

6
推荐指数
1
解决办法
1万
查看次数

faces-config.xml是配置文件

默认情况下,当我们创建Web应用程序时,faces-config.xml不会自动创建.我们必须手动创建他,因为我理解faces-config.xml必须严格定位WEB-INF.

所以,我的问题:

我是否必须faces-config.xmlweb.xml创建后WEB-INF或其他文件夹中注册或自动注册.即JSF"知道"是什么,faces-config.xml并且可以在所有项目的文件夹中找到他.

希望,我问了正确的问题.;)

jsf faces-config

6
推荐指数
1
解决办法
2万
查看次数

在ManagedBean中获取类的JSF转换器(JSF 1.2)

我遇到困难,需要JSF专家的外界帮助,遇到以下问题:我在faces-config.xml中为特定类定义了一些转换器,所以我不必一直使用converter-attribute或tag.例如:

    <converter>
      <converter-for-class>org.joda.time.DateTime</converter-for-class>
      <converter-class>com.example.converter.JodaDateTimeConverter</converter-class>
    </converter>
Run Code Online (Sandbox Code Playgroud)

现在需要一个JSF-Component(主要是rich:extendedDataTable)的爬虫,它构建整个组件树并逐级转换为CSV,HTML或稍后可能需要的任何东西.即导出为CSV,HTML,...的通用方法,无需每次重新实现它.这几乎已经完成了(感谢我的一位老同事的好主意),除了一部分之外它确实很有效:

    Object expressionResult = expression.getValue(FacesContext.getCurrentInstance().getELContext());
    expressionResultString = expressionResult.toString();
Run Code Online (Sandbox Code Playgroud)

该命令检索h:outputText的值并将其转换为String.如果有针对特定expressionResult的自定义转换器,那么最后一行就是我想要用converter-for-class替换的.我无法找到如何为我的类找到精确的转换器(由faces-config指定).FacesContext似乎没有为我的用例提供任何有用的方法/对象.直接访问faces-config.xml似乎有点不对劲.正确的方法可能类似于:

    Converter converter = magically_fetch_the_correct_converter_for_expressionResult_type;
    converter.getAsString(FacesContext.getCurrentInstance(), component,
                                expressionResult);
Run Code Online (Sandbox Code Playgroud)

如果我用转换器-ID和相应的属性/标签的组件本身,但我真的想避免那种无用的附加代码这将是相当容易的.

有人可以帮助我吗?

jsf converter faces-config managed-bean

5
推荐指数
1
解决办法
2495
查看次数

jsf过滤器似乎不起作用

我试图用jsf创建一个安全的登录页面,我使用这些代码片段作为解决方案,在这个问题中找到.我的问题是,我可以在不登录的情况下访问/restricted/secret.xhtml,没有重定向,就像没有应用过滤器一样,因为如果我直接去/restricted/secret.xhtml#{user.loggedIn评估为false,我仍然可以查看该页面.这是我的代码:

AuthFilter.java

public class AuthFilter implements Filter {

private FilterConfig config;

@Override
public void destroy() {
    this.config = null;
}

@Override
public void doFilter(ServletRequest req, ServletResponse resp,
        FilterChain ch) throws IOException, ServletException {

    HttpSession s =  ((HttpServletRequest) req).getSession();
    if (s.getAttribute(UserBean.CREDENTIAL)==null)
    {
        ((HttpServletResponse) resp).sendRedirect("/login.faces");
    }else
    {
        ch.doFilter(req, resp);
    }
}
@Override
public void init(FilterConfig config) throws ServletException {
    this.config = config;
}
}
Run Code Online (Sandbox Code Playgroud)

UserBean.java

@ManagedBean(name="user")
@SessionScoped
public class UserBean implements Serializable {

private String name;
private String password;
protected …
Run Code Online (Sandbox Code Playgroud)

jsf login faces-config servlet-filters

5
推荐指数
1
解决办法
4074
查看次数

如何为所有 UIInput 注册(组件)SystemEventListener

我正在尝试创建一个自定义SystemEventListener类型UIInput,用于注册所有类型的实例并对它们的postValidate-Events做出反应。根据我在网上找到的一个例子,我设法HtmlInputText通过faces-config.xml如下注册它来运行它:

<system-event-listener>
   <source-class>javax.faces.component.html.HtmlInputText</source-class>
   <system-event-class>javax.faces.event.PostValidateEvent</system-event-class>
   <system-event-listener-class>com.ourcompany.ourproduct.validators.inputPostValidationListener</system-event-listener-class>
 </system-event-listener>
Run Code Online (Sandbox Code Playgroud)

然后我尝试 1) 将其扩展到一般的 UIInputs 和 2) 使用 @ListenerFor注释,但我似乎无法让其中任何一个工作。

对于 1) 我真的找不到任何示例或文档,所以我只是尝试了 a) 定义多个源类标签或 b) 使用 javax.faces.component.UIInput作为源类。都没有工作。

2)我试过

@ListenerFor(systemEventClass = PostValidateEvent.class, sourceClass = UIInput.class)
Run Code Online (Sandbox Code Playgroud)

它既不适用于 UIInput,也不适用于 html.HtmlInputText。

现在,当我为所有其他类型的 HTML 输入复制相同的 XML 配置时,这确实有效,但它只会使 xml 变得混乱,而且对我来说似乎很烦人。

所以问题是:我通常在@ListenerFor 注释上做错了什么吗?对哪些源类可能有限制,即为什么我不能使用更通用的 UIInput?有没有比重复 XML 更有效的方法来为所有这些不同的输入注册监听器?最后:我宁愿实现ComponentSystemEventListener. 假设上述问题已解决,我只需更改implements-Statement 并相应地实现抽象processEvent,对吗?在这种情况下,这会起作用还是注册/ xml-config 不同(例如,也许<component-system-event-listener>而不仅仅是<system-event-listener>?

(以及作为后记:是只有我还是很难在网络上找到此类内容的任何非平凡示例?)

jsf annotations faces-config systemeventlistener

5
推荐指数
1
解决办法
4025
查看次数

java.util.MissingResourceException:找不到基本名称resources.application,locale en的包

我的faces-config.xml喜欢下面的内容.

<?xml version="1.0" encoding="UTF-8"?>

<faces-config
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"
version="2.0">
<application>
    <message-bundle>resources.application</message-bundle>
    <locale-config>
        <default-locale>en</default-locale>
    </locale-config>
</application>

</faces-config>
Run Code Online (Sandbox Code Playgroud)

Xhtml文件

<f:loadBundle basename="resources.application" var="msg"/>
Run Code Online (Sandbox Code Playgroud)

我得到以下例外

javax.faces.view.facelets.TagAttributeException: //D:/12c_Workspace/VNPO/WebContent/login.xhtml @9,59 <f:loadBundle basename="resources.application"> Can't find bundle for base name resources.application, locale en
    at com.sun.faces.facelets.tag.jsf.core.LoadBundleHandler.apply(LoadBundleHandler.java:233)
    at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:98)
    at com.sun.faces.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:93)
    at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:98)
    at com.sun.faces.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:86)
    at com.sun.faces.facelets.impl.DefaultFacelet.apply(DefaultFacelet.java:152)
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.buildView(FaceletViewHandlingStrategy.java:774)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:100)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:242)
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:216)
    at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:132)
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:338)
    at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:25)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:74)
    at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27)
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:74)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3288)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3254)
    at …
Run Code Online (Sandbox Code Playgroud)

resourcebundle faces-config jsf-2

5
推荐指数
1
解决办法
4万
查看次数