jsf标签_JSF Facelet标签示例教程

jsf标签

JSF provides a special set of tags that gives the flexibility to manage common tags/parts in one place for more than one application. These tags allow us to create a common layout that can be used across applications.

JSF提供了一组特殊的标记,这些标记提供了灵活性,可以在一个地方管理多个应用程序中的通用标记/部件。 这些标签使我们能够创建可在应用程序之间使用的通用布局。

To use the Facelet tags in the JSF page include the following namespace.

要在JSF页面中使用Facelet标记,请包含以下名称空间。

The following tags are provided by the Facelet tags.

Facelet标签提供了以下标签。

标签 ( tag)

The tag creates a new component and specifies the filename in ui:include tag or in the source of facelet tag. Any text used outside this tag will be ignored by the facelet tag view handler.

标记创建一个新组件,并在ui:include标记或facelet标记的源中指定文件名。 facelet标签视图处理程序将忽略此标签之外使用的任何文本。

The component attributes supported by this tag are;

该标签支持的组件属性是;

binding: Binds the component to the backing bean property as specified

binding :将组件绑定到指定的backing bean属性

class: represents the CSS class name

class :表示CSS类名称

id: unique identifier of the component

id :组件的唯一标识符

parent: represents the parent component for the child or a facet.

parent :表示孩子或构面的父组件。

rendered: flag that indicates whether the component should be rendered or not.

rendering :标志,指示是否应渲染组件。

renderedType: If this property is set, operations during the request processing lifecycle will be delegated to render instance of the type. If this is not set, implement these methods directly.

renderingType :如果设置了此属性,则在请求处理生命周期中的操作将委派给该类型的实例。 如果未设置,则直接实现这些方法。

transient: boolean flag set to true indicates that this component must not be included in the state of component tree.

瞬态 :布尔标志设置为true表示此组件不得包含在组件树的状态中。

Consider an example of using the ui:component tag by creating a JSF page carcomponent.xhtml as below.

考虑一个通过创建JSF页面carcomponent.xhtml来使用ui:component标记的carcomponent.xhtml ,如下所示。

carcomponent.xhtml

carcomponent.xhtml





	UI Component tag


	
            Hello!!!
            
        
        Hi You there?
    

The text inside the ui:component tag will be displayed in the output and the text outside this tag will be ignored, as shown in the below image.

ui:component标记内的文本将显示在输出中,并且该标记外的文本将被忽略,如下图所示。

标记 ( tag)

The tag provides a template encapsulating the content to be included in the other facelet.

标记提供了一个模板,该模板封装了要包含在另一个facelet中的内容。

The attributes supported by this tag are;

该标签支持的属性是;

class: The CSS component class name

class :CSS组件类名称

id: unique identifier for the component

id :组件的唯一标识符

parent: reperesents the parent component for the child or a facet.

parent :代表孩子或构面的父组件。

rendered: flag that indicates whether the component should be rendered or not.

rendering :标志,指示是否应渲染组件。

renderedType: If this property is set, operations during the request processing lifecycle will be delegated to render instance of the type. If this is not set,implement these methods directly.

renderingType :如果设置了此属性,则在请求处理生命周期中的操作将委派给该类型的实例。 如果未设置,则直接实现这些方法。

transient: boolean flag set to true indicates that this component must not be included in the state of component tree.

瞬态 :布尔标志设置为true表示此组件不得包含在组件树的状态中。

template: inserts the piece of page such as layout defined in the composition.

template :插入页面,例如合成中定义的布局。

The ui:composition tag is used in conjunction with the ui:insert tag shown in the example of ui:insert tag.

ui:composition标签与ui:insert标签示例中显示的ui:insert标签结合使用。

标签 ( tag)

This tag decorates the current JSF page including the content of another facelet. Decorating includes a layout, header, footer etc.

该标签装饰当前的JSF页面,包括另一个facelet的内容。 装饰包括布局,页眉,页脚等。

The tag attributes are;

标签属性是;

class: The Component CSS class name

class :组件CSS类名称

id: unique identifier for the component

id :组件的唯一标识符

parent: represents the parent component for the child or a facet.

parent :表示孩子或构面的父组件。

rendered: flag that indicates whether the component should be rendered or not.

rendering :标志,指示是否应渲染组件。

renderedType: If this property is set, operations during the request processing lifecycle will be delegated to render instance of the type.If this is not set, implement these methods directly.

renderingType :如果设置了此属性,则请求处理生命周期中的操作将委派给该类型的实例。如果未设置,则直接实现这些方法。

transient: boolean flag set to true indicates that this component must not be included in the state of component tree.

瞬态 :布尔标志设置为true表示此组件不得包含在组件树的状态中。

Consider an example of decorate tag by wrapping the data in a border and color by creating a JSF page named decorate.xhtml.

考虑一个装饰标签的示例,该示例通过创建一个名为decorate.xhtml的JSF页面将数据包装在边框和颜色中。

decorate.xhtml

decorate.xhtml



	Decorate tag example



	
		
			
		
		
		
	

Here we specify the styles border, color, cellpadding, cellspacing, caption tag and text tag to be inserted.

在这里,我们指定要插入的样式边框,颜色,单元格填充,单元格间距,标题标签和文本标签。

Create cardecorate.xhtml as;

创建cardecorate.xhtml为;

cardecorate.xhtml

cardecorate.xhtml



	Decorate



	
		
			
		

		
		
		
		
		
		

	


Here we specify the values to be displayed for the caption and text tags and also the decorate template mentioning the decorate.xhtml file. Below image shows the output produced.

在这里,我们指定要为caption和text标签显示的值,并指定提及decorate.xhtml文件的装饰模板。 下图显示了产生的输出。

标记 ( tag)

This tag defines the content to be inserted into the page by a template. The name attribute value must match with the tag of the target template to be included.

该标记定义模板将要插入页面的内容。 name属性值必须与要包含的目标模板的标记匹配。

The tag attributes are;

标签属性是;

name: assigns a name to the content inside a define tag.

name :为define标记内的内容分配一个名称。

class: The Component CSS class name.

class :组件CSS类名称。

id: unique identifier for the component

id :组件的唯一标识符

parent: represents the parent component for the child or a facet.

parent :表示孩子或构面的父组件。

rendered: flag that indicates whether the component should be rendered or not.

rendering :标志,指示是否应渲染组件。

renderedType: If this property is set, operations during the request processing lifecycle will be delegated to render instance of the type. If this is not set,implement these methods directly.

renderingType :如果设置了此属性,则在请求处理生命周期中的操作将委派给该类型的实例。 如果未设置,则直接实现这些方法。

transient: boolean flag set to true indicates that this component must not be included in the state of component tree.

瞬态 :布尔标志设置为true表示此组件不得包含在组件树的状态中。

The define tag can be used as

define标签可以用作

Car World
  List Of Cars
  Alto,Zen,Innova

The define tag and insert tag is used in combination to print the values in the insert tag. We will look at the example in the later sections of the post.

define标签和insert标签结合使用以打印insert标签中的值。 我们将在帖子的后面部分中查看示例。

标记 ( tag)

The tag includes the new UI component instance into the JSF Component tree. JSF does not discard the contents outside this tag.

标记将新的UI组件实例包含在JSF Component树中。 JSF不会丢弃此标记之外的内容。

The tag attributes are;

标签属性是;

binding: Binds the component to the backing bean property as specified

binding :将组件绑定到指定的backing bean属性

class: represents the CSS class name

class :表示CSS类名称

id: unique identifier of the component

id :组件的唯一标识符

parent: represents the parent component for the child or a facet.

parent :表示孩子或构面的父组件。

rendered: flag that indicates whether the component should be rendered or not.

rendering :标志,指示是否应渲染组件。

renderedType: If this property is set, operations during the request processing lifecycle will be delegated to render instance of the type. If this is not set, implement these methods directly.

renderingType :如果设置了此属性,则在请求处理生命周期中的操作将委派给该类型的实例。 如果未设置,则直接实现这些方法。

transient: boolean flag set to true indicates that this component must not be included in the state of component tree.

瞬态 :布尔标志设置为true表示此组件不得包含在组件树的状态中。

Consider an example for this tag by creating a JSF page fragment.xhtml as;

通过创建一个JSF页面fragment.xhtml来考虑该标签的示例。

fragment.xhtml

fragment.xhtml





	
		
			
Welcome to the Car World
How can i help you?

Here the contents outside the tag is also displayed in the output along with the contents within the tag.

此处,标记外部的内容也与标记中的内容一起显示在输出中。

标签 ( tag)

This tag includes the component in the src attribute as a part of the current JSF page. The filename in the src attribute is relative to the XHTML file that was rendered as a result of the last request.

此标记将src属性中的组件作为当前JSF页面的一部分。 src属性中的文件名是相对于最后一个请求而呈现的XHTML文件的。

The attributes are;

属性是;

src: the file whose contents to be included in the jsf page.

src :要包含在jsf页面中的文件。

class: represents the CSS class name

class :表示CSS类名称

id: unique identifier of the component

id :组件的唯一标识符

parent: represents the parent component for the child or a facet.

parent :表示孩子或构面的父组件。

rendered: flag that indicates whether the component should be rendered or not.

rendering :标志,指示是否应渲染组件。

renderedType: If this property is set, operations during the request processing lifecycle will be delegated to render instance of the type. If this is not set, implement these methods directly.

renderingType :如果设置了此属性,则在请求处理生命周期中的操作将委派给该类型的实例。 如果未设置,则直接实现这些方法。

transient: boolean flag set to true indicates that this component must not be included in the state of component tree.

瞬态 :布尔标志设置为true表示此组件不得包含在组件树的状态中。

Consider an example where we want to include an header for the current JSF page from another page.

考虑一个示例,在该示例中,我们希望包含另一个页面中当前JSF页面的标题。

include.xhtml

include.xhtml





	
		
			
                 Alto
                 

Santro

Zen

VolksWagen

Here we include a file “head.xhtml” to display the header information with the “src” attribute of tag.

在这里,我们包含一个文件“ head.xhtml”,以显示带有标记的“ src”属性的标题信息。

Create head.xhtml file as;

创建head.xhtml文件为;

head.xhtml

head.xhtml





	Facelet Title


	

List Of Cars Available

Here we include a header tag

with text in it. Below is the output produced by this.

在这里,我们包括一个带有文本的标头标签

。 以下是由此产生的输出。

标记 ( tag)

This tag inserts the contents into a template.

该标签将内容插入模板。

The tag attributes are;

标签属性是;

class: represents the CSS class name

class :表示CSS类名称

id: unique identifier of the component

id :组件的唯一标识符

name: optional attribute that matches the associated tag in the template.

name :与模板中的关联标签匹配的可选属性。

parent: represents the parent component for the child or a facet.

parent :表示孩子或构面的父组件。

rendered: flag that indicates whether the component should be rendered or not.

rendering :标志,指示是否应渲染组件。

renderedType: If this property is set, operations during the request processing lifecycle will be delegated to render instance of the type. If this is not set, implement these methods directly.

renderingType :如果设置了此属性,则在请求处理生命周期中的操作将委派给该类型的实例。 如果未设置,则直接实现这些方法。

transient: boolean flag set to true indicates that this component must not be included in the state of component tree.

瞬态 :布尔标志设置为true表示此组件不得包含在组件树的状态中。

Create a JSF view page insert.xhtml as

创建一个JSF视图页面insert.xhtml为

insert.xhtml

insert.xhtml




	<ui:insert name="title" />


	

Here we include the title, header and messages by defining their values in another jsp page message.html

在这里,我们通过在另一个jsp页面message.html中定义它们的值来包括标题,标题和消息。

Create message.xhtml as;

创建message.xhtml为;

message.xhtml

message.xhtml





	
		Car World
		List Of Cars
		Alto,Zen,Innova
	

Here we define values for title, header and message and include the insert.xhtml created above.

在这里,我们定义标题,标题和消息的值,并包括上面创建的insert.xhtml。

标记 ( tag)

This tag is used to pass the parameters to an included file or a template.

此标记用于将参数传递到包含的文件或模板。

The attributes are;

属性是;

name: name of the parameter.

name :参数名称。

value: value of the parameter.

value :参数的值。

class: represents the CSS class name.

class :表示CSS类名称。

id: unique identifier of the component.

id :组件的唯一标识符。

parent: represents the parent component for the child or a facet.

parent :表示孩子或构面的父组件。

rendered: flag that indicates whether the component should be rendered or not.

rendering :标志,指示是否应渲染组件。

renderedType: If this property is set, operations during the request processing lifecycle will be delegated to render instance of the type. If this is not set, implement these methods directly.

renderingType :如果设置了此属性,则在请求处理生命周期中的操作将委派给该类型的实例。 如果未设置,则直接实现这些方法。

transient: boolean flag set to true indicates that this component must not be included in the state of component tree.

瞬态 :布尔标志设置为true表示此组件不得包含在组件树的状态中。

Consider an example where we want to print a text in the output with the help of param tag.

考虑一个示例,我们希望借助param标签在输出中打印文本。

Create a bean Welcome.java as;

创建一个bean Welcome.java为;

package com.journaldev.jsf.beans;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

@ManagedBean
@RequestScoped
public class Welcome {

	private String w1 = "Welcome!!!";

	public String getW1() {
		return w1;
	}

	public void setW1(String w1) {
		this.w1 = w1;
	}

}

Here we initialize the value to variable w1 and include getter setter methods to fetch the values.

在这里,我们将值初始化为变量w1,并包括getter setter方法来获取值。

Create welcome.xhtml as;

创建的welcome.xhtml为;

welcome.xhtml

welcome.xhtml





	Facelet Title


	
	

#{w1}

Here we use ui param tag and use w1 variable and fetch the value from the welcome bean class into w1 variable and use this variable to print the value.

在这里,我们使用ui param标记并使用w1变量,并将值从Welcome bean类中提取到w1变量中,然后使用此变量来打印值。

标记 ( tag)

This tag removes the content from a page.This tag is used in conjunction with the facelets for additional markup.

此标签从页面上删除内容。此标签与facelets结合使用以进行其他标记。

The attributes are;

属性是;

class: represents the CSS class name.

class :表示CSS类名称。

id: unique identifier of the component.

id :组件的唯一标识符。

parent: represents the parent component for the child or a facet.

parent :表示孩子或构面的父组件。

rendered: flag that indicates whether the component should be rendered or not.

rendering :标志,指示是否应渲染组件。

renderedType: If this property is set, operations during the request processing lifecycle will be delegated to render instance of the type. If this is not set, implement these methods directly.

renderingType :如果设置了此属性,则在请求处理生命周期中的操作将委派给该类型的实例。 如果未设置,则直接实现这些方法。

transient: boolean flag set to true indicates that this component must not be included in the state of component tree.

瞬态 :布尔标志设置为true表示此组件不得包含在组件树的状态中。

Consider an example where we want remove a part of the text from the JSF page. Create carremove.xhtml page as;

考虑一个示例,我们要从JSF页面中删除部分文本。 创建carremove.xhtml页面为;

carremove.xhtml

carremove.xhtml





	Facelet Title


	
            Alto Car has power windows
            
Alto is a good Car
Alto Car gives a good mileage

Here we are enclosing the message “Alto is a good Car” in the tags. So this statement will be excluded in the output.

在这里,我们在标记中附上消息“ Alto是一辆好车”。 因此,该语句将被排除在输出中。

标记 ( tag)

The tag iterates over a collection of objects exposed to the page.

标记遍历暴露给页面的对象的集合。

The attributes are;

属性是;

value: name of the collection that the tag iterates.

value :标签迭代的集合的名称。

var: name of the exported value for the current item of iteration.

var :当前迭代项的导出值的名称。

class: represents the CSS class name.

class :表示CSS类名称。

id: unique identifier of the component.

id :组件的唯一标识符。

offset: read write property setting offset from the beginning of the collection from which to start iteration.

offset :读写属性设置,从开始迭代的集合的开始偏移。

parent: represents the parent component for the child or a facet.

parent :表示孩子或构面的父组件。

rendered: flag that indicates whether the component should be rendered or not.

rendering :标志,指示是否应渲染组件。

renderedType: If this property is set, operations during the request processing lifecycle will be delegated to render instance of the type. If this is not set, implement these methods directly.

renderingType :如果设置了此属性,则在请求处理生命周期中的操作将委派给该类型的实例。 如果未设置,则直接实现这些方法。

size: size of the collection to iterate

size :要迭代的集合的大小

step: Starting from the first one, iteration will process every step in the list of items.

步骤 :从第一个步骤开始,迭代将处理项目列表中的每个步骤。

transient: boolean flag set to true indicates that this component must not be included in the state of component tree.

瞬态 :布尔标志设置为true表示此组件不得包含在组件树的状态中。

varStatus: Name of the exported variable for status of the iteration.

varStatus :用于迭代状态的导出变量的名称。

Consider an example for the ui:repeat tag;

考虑ui:repeat标签的示例;

There is a list of car names and we have to fetch all the names in the jsf page

这里有汽车名称列表,我们必须在jsf页面中获取所有名称

Create a bean named Car.java as;

创建一个名为Car.java的bean作为;

package com.journaldev.jsf.beans;

import java.util.ArrayList;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

@ManagedBean
@RequestScoped
public class Car {

	private String carname;
	private List cars;

	public Car(String carname) {
		this.carname = carname;
	}

	public String getCarname() {
		return carname;
	}

	public void setCarname(String carname) {
		this.carname = carname;
	}

	public Car() {
	}

	public List getCars() {
		if (cars == null) {
			cars = new ArrayList();
			cars.add(new Car("Innova"));
			cars.add(new Car("Qualis"));
			cars.add(new Car("Scorpio"));
			cars.add(new Car("Xylo"));
		}
		return cars;
	}

}

Here we declare list and insert car names into the list with the add method of the list.

在这里,我们声明列表,并使用列表的add方法将汽车名称插入列表中。

Create car.xhtml page as

将car.xhtml页面创建为

car.xhtml

car.xhtml




    
        Facelet Title
    
    
        
    

We use ui:repeat tag to iterate over the list of cars and fetch the values from Car.java bean.

我们使用ui:repeat标记迭代汽车列表,并从Car.java bean中获取值。

Below image shows the output produced.

下图显示了产生的输出。

Finally below image shows the project structure.

最后,下图显示了项目结构。

You can download the project from below link and play around with it to learn more.

您可以从下面的链接下载该项目并进行试用以了解更多信息。

Download JSF Facelet Tags Example Project 下载JSF Facelet标签示例项目

翻译自: https://www.journaldev.com/7012/jsf-facelet-tags-example-tutorial

jsf标签

你可能感兴趣的:(jsf标签_JSF Facelet标签示例教程)