标签: faces-config

Java EE 中 web.xml 和 faces-config.xml 的用途是什么?

我目前正在学校学习JavaEE,还没有了解web.xml 文件和face-config.xml 文件背后的含义。我从我的教科书“Core Java Server Faces”第三版中知道,face-config 文件中可以放置其他配置参数。例如,我在face-config文件中看到了我认为是对我的一些bean参数的声明以及对其他页面的一些导航,例如......

    <navigation-rule>
        <navigation-case>
            <from-outcome>startOver</from-outcome>
            <to-view-id>/index.xhtml</to-view-id>
        <navigation-case>
    </navigation-case>
Run Code Online (Sandbox Code Playgroud)

web.xml 到底有什么用呢?教科书说需要我的 web.xml 和 beans.xml 来保持应用程序服务器满意。好吧,很酷,但是 web.xml 和face-config.xml 是如何交互的呢?他们吗?这两个文件就像我画画的框架和我画画的画布吗?

jsf web.xml servlets faces-config jakarta-ee

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

jsf-在faces-config中注册SessionListener

我创建了一个,SessionListener但是它不起作用,因为我不知道如何在中注册它faces-config.xml。我尝试了以下方法:

会话监听器

public class SessionListener implements HttpSessionListener {

@Override
public void sessionCreated(HttpSessionEvent arg0) {


    HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
    String param = request.getParameter("language");


    IDAdminLanguage idl = (IDAdminLanguage) JSFUtils.resolve("#{languageBean}");

    if (param != null && param.length() > 0) {
        idl.setLanguage(param);
    } else {
        idl.setLanguage("de");
    }   
}

@Override
public void sessionDestroyed(HttpSessionEvent arg0) { }
Run Code Online (Sandbox Code Playgroud)

}

faces-config

<listener>
   <listener-class>ch.idadmin.util.SessionListener</listener-class>
</listener>
Run Code Online (Sandbox Code Playgroud)

java jsf listener faces-config

3
推荐指数
1
解决办法
1702
查看次数

CommandLink导航在JSF中不起作用

我想使用faces-config.xml(JSF 2.0)的导航规则功能,但我遇到了一些问题.我有三个文件(index.xhtml,index2.html,index3.xhtml),它们看起来像这样:

   <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core">

<f:loadBundle basename="resources.application" var="bundle"/>

<head>
    <title><h:outputText value="#{bundle['welcome.title']}" /></title>
</head>

<body>
<h3>1</h3>
<h:form>

<h:commandButton action="next2" id="nextpagelink" value="Next Link">Next</h:commandButton>
</h:form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

(index.xhtml,其他看起来与不同的动作名和其他h3-field相似)

我的faces-config.xml包含以下与navigation-rules相关的条目:

<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>

    <navigation-rule>
  <display-name>index.xhtml</display-name>
  <from-view-id>/index.xhtml</from-view-id>
  <navigation-case>
      <from-outcome>next2</from-outcome>
   <to-view-id>/index2.xhtml</to-view-id>
  </navigation-case>
 </navigation-rule>

 <navigation-rule>
  <display-name>index2.xhtml</display-name>
  <from-view-id>/index2.xhtml</from-view-id>
  <navigation-case>
      <from-outcome>next3</from-outcome>
   <to-view-id>/index3.xhtml</to-view-id>
  </navigation-case>
 </navigation-rule>


 <navigation-rule>
  <display-name>index3.xhtml</display-name>
  <from-view-id>/index3.xhtml</from-view-id>
  <navigation-case>
      <from-outcome>next1</from-outcome>
   <to-view-id>/index.xhtml</to-view-id>
  </navigation-case>
 </navigation-rule>
</faces-config>
Run Code Online (Sandbox Code Playgroud)

web.xml中:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" …
Run Code Online (Sandbox Code Playgroud)

java navigation jsf faces-config jsf-2

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

我们的JSF应用程序中可以有多个faces-config.xml文件吗?

我正在做一个规模越来越大的项目,但仍有很多工作要做。关键是,我的条目faces-config.xml已经跨越了600行,我担心它会在未来几个月内翻倍。

我在考虑是否可以通过某种方式faces-config.xml在项目中拥有多个文件,然后可以根据我的模块进行配置,从而可以轻松地处理多个文件夹。

jsf faces-config

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

如果我编写@managed bean 注释并在faces-config.xml 中定义相同的bean 是否会有两个实例

在我的应用程序中,我们在某些地方使用 @ManagedBean 注释对 Person bean 和我们在 faces-confing.xml 中定义的同一个 Person bean 同时使用,如下所示。

@ManagedBean("name=person")
 @SessionScoped
 Public class Person{


}
Run Code Online (Sandbox Code Playgroud)

人脸配置文件

<managed-bean>
     <managed-bean-name>person</managed-bean-name>
     <managed-bean-class>com.test.sample.Person</managed-bean-class>
     <managed-bean-scope>session</managed-bean-scope>
</managed-bean>
Run Code Online (Sandbox Code Playgroud)

我的问题是这种方法是否为 Person bean 创建了两个实例,或者如果我这样做很重要?如果我对应用程序中的每个 Bean 都这样做,这对我的应用程序的性能有什么影响吗?

faces-config jsf-2 managed-bean

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

托管Bean的托管Bean类java.time.ZonedDateTime并未声明公共的无参数构造器。

为了获得当前日期,我在faces-config.xml下面声明了一个托管bean 。

<managed-bean>
    <managed-bean-name>currentDate</managed-bean-name>
    <managed-bean-class>java.time.ZonedDateTime</managed-bean-class>
    <managed-bean-scope>request</managed-bean-scope>
</managed-bean>
Run Code Online (Sandbox Code Playgroud)

之前,我一直在使用org.joda.time.DateTime并且工作正常。可以像下面这样在EL中访问此bean。

<h:outputText value="#{currentDate}" converter="#{converter}"/>
Run Code Online (Sandbox Code Playgroud)

但是,这导致引发以下异常。

16:15:29,984 SEVERE [javax.enterprise.resource.webcontainer.jsf.application] (default task-16) Error Rendering View[/admin_side/Home.xhtml]: com.sun.faces.mgbean.ManagedBeanCreationException: Unable to create managed bean currentDate.  The following problems were found:
     - Managed bean class java.time.ZonedDateTime for managed bean currentDate doesnt declare a public no-argument constructor.
    at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:265)
    at com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:257)
    at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:117)
    at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
    at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
    at com.sun.el.parser.AstIdentifier.getValue(AstIdentifier.java:116)
    at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:226)
    at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50)
    at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50)
    at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
    at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
    at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182)
    at javax.faces.component.UIOutput.getValue(UIOutput.java:174)
    at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(HtmlBasicInputRenderer.java:205)
    at …
Run Code Online (Sandbox Code Playgroud)

jsf faces-config managed-bean java-time

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

无法在带有JSF 2.3的Wildfly 14中注入FacesContext(Mojarra,主模块)

我有一个豆:

import javax.faces.context.FacesContext;
import javax.faces.view.ViewScoped;

...

@Named
@ViewScoped
public class SimpleBean implements Serializable
{
    private static final long serialVersionUID = 1L;

    @Inject
    protected FacesContext facesContext;

    ...
}
Run Code Online (Sandbox Code Playgroud)

根据

https://arjan-tijms.omnifaces.org/p/jsf-23.html#1316

这应该与2.3一起工作...

部署到Wildfly 14时,结果是:

13:02:33,516 INFO  [org.hibernate.dialect.Dialect] (ServerService Thread Pool -- 72) HHH000400: Using dialect: org.hibernate.dialect.MySQL8Dialect
13:02:33,563 INFO  [org.hibernate.envers.boot.internal.EnversServiceImpl] (ServerService Thread Pool -- 72) Envers integration enabled? : true
13:02:34,344 INFO  [org.hibernate.hql.internal.QueryTranslatorFactoryInitiator] (ServerService Thread Pool -- 72) HHH000397: Using ASTQueryTranslatorFactory
13:02:34,531 WARN  [org.jboss.weld.Bootstrap] (MSC service thread 1-1) WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class …
Run Code Online (Sandbox Code Playgroud)

faces-config cdi facescontext wildfly jsf-2.3

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

Faces Navigation在JSF2中没有真正起作用

我正在使用JSF 2.0

这是我的faces-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- This file is not required if you don't need any extra configuration. -->
<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">

    <navigation-rule>
        <from-view-id>/pages/test/test.html</from-view-id>
        <navigation-case>
            <from-outcome>write</from-outcome>
            <to-view-id>/pages/test/test-write.html</to-view-id>
        </navigation-case>

    </navigation-rule>

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

TestController.java

@ManagedBean(name="testController")
@SessionScoped
public class TestController implements Serializable {

    private static final long serialVersionUID = -3244711761400747261L; 

    public String test() {


        return "write?faces-redirect=true";
}
Run Code Online (Sandbox Code Playgroud)

在我的test.xhtml文件中

<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    template="/WEB-INF/templates/default.xhtml">
    <ui:define name="content">
            <h:form>
                    <h:commandButton action="#{testController.test()}" value="test" />  
            </h:form>
    </ui:define>

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

这是我的web.xml

<web-app …
Run Code Online (Sandbox Code Playgroud)

navigation faces-config java-ee-6 jsf-2

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

以编程方式从faces-config.xml按结果获取导航大小写<to-view-id>

有没有办法<to-view-id>在支持bean中获得导航案例?

让我们说我想<to-view-id>从结果中得到结果success,这应该是page1.xhtml.有没有帮手功能?

<navigation-rule>
    <from-view-id>start.xhtml</from-view-id>
    <navigation-case>
        <from-action>#{pageController.processPage1}</from-action>
        <from-outcome>success</from-outcome>
        <to-view-id>page1.xhtml</to-view-id>
    </navigation-case>
    <navigation-case>
        <from-action>#{pageController.processPage2}</from-action>
        <from-outcome>success</from-outcome>
        <to-view-id>page2.xhtml</to-view-id>
    </navigation-case>
</navigation-rule>  
Run Code Online (Sandbox Code Playgroud)

如果它有帮助,我正在使用PrettyFaces.

navigation faces-config jsf-2

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