小编Tuk*_*uaz的帖子

访问支持组件中的JSF2组合组件属性

我正在开发一个JSF2/Primefaces应用程序,我在访问此组件的支持bean中复合组件的接口中定义的属性时遇到问题.

我的组件定义如下:

<!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:h="http://java.sun.com/jsf/html"
    xmlns:composite="http://java.sun.com/jsf/composite">

<composite:interface componentType="testComponent">
    <composite:attribute name="text" required="true" type="java.lang.String" />
</composite:interface>

<composite:implementation>

    <h:outputText value="Passed text is: #{cc.attrs.text}" />

</composite:implementation>

</html>
Run Code Online (Sandbox Code Playgroud)

它存储在名为text.xhtml:application/src/main/webapp/resources/my_componentdirectory 的文件中.

我在另一个页面(这是一个Facelets组合元素)上使用此组件,如下所示:

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:myc="http://java.sun.com/jsf/composite/my_component"
    template="./resources/templates/template.xhtml">

<ui:define name="content"> 
    <h:form id="products">
        <myc:test id="test" text="A text" />
    </h:form>
</ui:define>    

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

支持组件类定义如下:

package my.application.component;

import javax.faces.component.FacesComponent;
import javax.faces.component.UINamingContainer;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@FacesComponent ( value="testComponent" )
public class TestComponent extends UINamingContainer {
    Logger log = …
Run Code Online (Sandbox Code Playgroud)

primefaces composite-component jsf-2

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

标签 统计

composite-component ×1

jsf-2 ×1

primefaces ×1