标签: facelets

在JSF-Richfaces-facelet中重定向会话超时

我正在使用JSF和RichFacecs来创建一个Web门户.我希望在会话超时时将用户重定向到登录页面.我试图在会话到期/注销阶段抛出SecurityException,如下所示

<error-page>
    <exception-type>java.lang.SecurityException</exception-type>
    <location>/Login.jsf</location>
</error-page>
Run Code Online (Sandbox Code Playgroud)

但这不适合我.处理这个问题的正确方法是什么?

jsf richfaces facelets

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

JSF2:将 cc:attribute 限制为列表中的给定对象类型

如果我有一个托管 bean,如下所示:

@ManagedBean
@RequestSchoped
public class Example {

    private List<String> stringList;
    private List<Long> longList;

    // getters, setters, etc. down here
}
Run Code Online (Sandbox Code Playgroud)

并且有一个接受 List 作为属性的自定义组件:

<?xml version='1.0' encoding='UTF-8' ?>
<!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:cc="http://java.sun.com/jsf/composite"
      xmlns:h="http://java.sun.com/jsf/html">

  <!-- INTERFACE -->
  <cc:interface>
      <cc:attribute name="aList" type="java.util.List" />
  </cc:interface>

  <cc:implementation>
      <!-- code is in here -->
  </cc:implementation>
</html>
Run Code Online (Sandbox Code Playgroud)

我怎么能确保这有效:

<myComp:previousComponent aList="#{example.stringList}" />
Run Code Online (Sandbox Code Playgroud)

但这没有:

<myComp:previousComponent aList="#{example.longList}" />
Run Code Online (Sandbox Code Playgroud)

换句话说,我想做的事情cc:attribute如下:

<cc:attribute name="aList" type="java.util.List<java.lang.String>" />
Run Code Online (Sandbox Code Playgroud)

然而,正如我们所知,xhtml 不喜欢使用 > 或 <。此外,由于仅在编译时检查泛型,我不确定这将如何完成。有谁知道这是否可能?

xhtml jsf facelets composite-component jsf-2

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

JSF <h:outputFormat>:使用数组值作为参数

在我的JSF2页面上,我正在使用国际化的错误消息.

在我的支持bean中,我将消息放入flash范围:

flash.put("error", exception.getType());
Run Code Online (Sandbox Code Playgroud)

在页面上,此字符串以这种方式翻译:

<h:outputText value="#{bundle[flash.error]}"/>
Run Code Online (Sandbox Code Playgroud)

工作良好.

现在我想能够将(任意数量的)参数放入消息文本中,这些参数将插入到message.properties中i18n属性的占位符中.因此,我将参数作为String数组放入Flash Scope中,如下所示:

//exception.getParameters returns String[]
flash.put("errorParams", exception.getParameters())
Run Code Online (Sandbox Code Playgroud)

现在我也希望能够使用这个String数组作为outputFormat元素的参数,将它们插入到像这样的属性中Welcome, {0} {1}.所以我试图通过使用ui实现这一点:重复:

<h:outputFormat value="#{bundle[flash.error]}" rendered="#{! empty flash.error}" class="invalid">
  <ui:repeat value="#{flash.errorParams}" var="_param">
    <f:param value="#{bundle[_param]}"/>
    <!-- also doesn't work: <f:param value="#{_param}"/>-->
  </ui:repeat>
</h:outputFormat>
Run Code Online (Sandbox Code Playgroud)

不幸的是,param值被忽略,并且i18n-property的占位符没有被替换,因此渲染的输出是Welcome, {0} {1}.当使用"常规"转发器时,将数组元素显示为输出文本,它可以工作.所以outputFormat标签似乎不支持使用repeat作为子元素.该死的,如此接近;)任何人都知道一个很好的方法来做我想要的,或者是否有任何组件库支持这样的东西?

jsf facelets jsf-2

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

JSF:为辅助bean中的属性创建别名

我指的是相当深的对象层次结构,在EL中有相当神秘的名字#{myBean.configBaseStack.excludeMethodFromAccounting.method.TimeoutBehaviorEnabled}.

我想通过类似的别名指向这个相同的属性:

<x:alias name="m" value="#{myBean.configBaseStack.excludeMethodFromAccounting.method" />
<h:inputText value="#{m.TimeoutBehaviorEnabled}" />
Run Code Online (Sandbox Code Playgroud)

我想有一种方法可以在支持bean中创建这些别名,但我宁愿把它留给模板.

如何在模板/ facelet级别完成此操作?

jsf facelets

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

<ui:param和缓存

我有以下的事情:

<ui:param name="randomVideo" value="#{bean.randomVideo}" />
<a href="#{randomVideo.link}">#{randomVideo.text}</a&></pre>
Run Code Online (Sandbox Code Playgroud)

因为<ui:param>不缓存的变量,Bean.getRandomVideo()被称为两次,最糟糕的是,.text.link来自不同的视频.我已经尝试<c:set<f:param.他们都没有设置变量,可能是因为我使用facelets(JSF2).

有任何想法吗?

jstl facelets jsf-2

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

获取EL中的字符串长度

我们可以String在Facelets页面中找到一个长度来检查条件<ui:fragment>吗?

facelets el jsf-2

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

如何从JSF 1.2中的Facelet标记文件访问父组件

我正在JSF 1.2中编写Facelet标记文件.我希望能够引用父容器.在JSF 2.0中,我可以将它作为一个复合组件并使用#{cc.parent}.但有没有一个JSF 1.2等效的方法呢?

taglib.xml

<?xml version="1.0"?>
<!DOCTYPE facelet-taglib PUBLIC "-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN" "facelet-taglib_1_0.dtd">
<facelet-taglib>
  <namespace>http://company.com/jsf</namespace>
  <tag>
     <tag-name>parentid</tag-name>
     <source>../components/parentid.xhtml</source>
  </tag>
</facelet-taglib>
Run Code Online (Sandbox Code Playgroud)

parentid.xhtml

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

  <!-- The next line is the line that isn't working for me -->
  <h:outputText binding="#{obj}" value="Parent id is: #{obj.parent.id}" />
</ui:composition>
Run Code Online (Sandbox Code Playgroud)

testpage.xhtml

<ui:composition
  xmlns="http://www.w3.org/1999/xhtml"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:rich="http://richfaces.org/rich"
  xmlns:test="http://company.com/jsf"
  xmlns:ui="http://java.sun.com/jsf/facelets">

  ...
  <a:form id="form1">
    <test:parentid />
  </a:form>
  <a:form id="form2">
    <test:parentid />
  </a:form>
  ...
</ui:composition>
Run Code Online (Sandbox Code Playgroud)

我编辑了这个以包含来自BalusC链接的信息,我几乎就在那里.

在示例中,如果只有form1,它将完美地工作.但是添加form2,这是我得到的输出:

Parent id is: form2
Parent …
Run Code Online (Sandbox Code Playgroud)

jsf facelets parent tagfile jsf-1.2

6
推荐指数
0
解决办法
1728
查看次数

将复合组件迁移到自定义组件

我必须将复合组件迁移到自定义组件.此示例相当简化,但演示了问题:我的component(my:test)的子节点需要在另一个组件中呈现.my:testC作为一个我不想使用的例子,复合材料看起来像这样

<composite:implementation>
  <p:panel>
    <composite:insertChildren/>
  </p:panel>
</composite:implementation>
Run Code Online (Sandbox Code Playgroud)

显然,(我希望至少我这个假设是正确的),我不能简单地呈现p:panelencodeBegin.

@FacesComponent("test")
public class Test extends UIPanel
{   
  @Override
  public void encodeBegin(FacesContext context) throws IOException
  {
    // ??
  }

  @Override
  public void encodeEnd(FacesContext context) throws IOException
  {
   // ??
  }
}
Run Code Online (Sandbox Code Playgroud)

我希望以my:test这样的方式使用:

<my:test>
  <h:outputText value="some Text"/>
</my:test>
Run Code Online (Sandbox Code Playgroud)

输出应该与使用相同my:testC:在PrimeFaces面板中呈现的一些文本.如何编码p:panelJava类的用法?

java facelets composite-component jsf-2

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

具有多个视图解析器的Spring MVC

我尝试使用2个视图解析器:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans     
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc.xsd">

    <context:component-scan base-package="com.evgeni.dfr.controller" />

    <context:annotation-config />
    <mvc:annotation-driven />

    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <property name="cache" value="false" />
        <property name="viewClass" value="com.evgeni.drf.faces.FacesView" />
        <property name="prefix" value="/WEB-INF/pages/" />
        <property name="suffix" value=".xhtml" />

        <property name="order" value="1" />
    </bean>

    <bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix">
            <value>/WEB-INF/views/</value>
        </property>
        <property name="suffix">
            <value>.jsp</value>
        </property>
        <property name="order" value="0" />
    </bean>
</beans>
Run Code Online (Sandbox Code Playgroud)

应用程序始终只使用最低顺序而不是另一个.在目前的情况下,如果我的控制器返回"someView",The requested resource (/MyProject/WEB-INF/views/someView.jsp) is not available.即使有"pages/someView.xhtml" ,应用程序也会响应.

春季版 - 3.2.3

编辑:如果我在控制器中有2个方法,方法A返回"viewA",方法B返回"viewB".我们在'views'文件夹中有viewA.jsp,在'pages'中有viewB.xhtml.

Case1:UrlBasedViewResolver - > …

spring facelets spring-mvc

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

为什么<h:link>将目标扩展名从.html更改为.xhtml?

我正在使用JSF 2.1,我遇到了<h:link>标签的一些问题.我正在尝试将链接的结果点从我的XHTML文件转换为纯HTML文件.但是,当我运行我的Web应用程序时,.html链接生成的URL中的.xhtml扩展名会自动转换为扩展名.

这是我的Facelet文件:

<h:body>
    <h:form>        
        <h:link value="animation" outcome="#{contentForm.ccAnimationLink}"/>            
    </h:form>
<h:body>
Run Code Online (Sandbox Code Playgroud)

这是我的contentForm bean:

package my.app.content;

import java.io.Serializable;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;

@ManagedBean
@RequestScoped
public class ContentForm implements Serializable {
    private static final long serialVersionUID = -8463354828156798513L; 
    private String ccAnimationLink = "";    

    @PostConstruct
    public void init() {        
        ccAnimationLink = "/content/cc/CC_animation/story.html";        
    }

    public String getCcAnimationLink() {
        return ccAnimationLink;
    }

    public void setCcAnimationLink(String ccAnimationLink) {
        this.ccAnimationLink = ccAnimationLink;
    }
}
Run Code Online (Sandbox Code Playgroud)

现在,当我运行此应用程序时,我收到以下错误:

无法从视图ID'/content/modifiedcc.xhtml'中找到匹配的导航案例,以获得结果'/content/cc/CC_animation/story.html'

我确保我的URL正确,所以我story.xhtml …

jsf facelets hyperlink

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