jsf in action 笔记:理解组件和客户端的标识(Understanding component and client identifiers)--2008.04.09

本文介绍了JavaServer Faces(JSF)中UI组件的工作原理,重点阐述了服务器端组件标识与客户端标识之间的关系及其作用。组件标识有助于组件在服务器端和客户端间进行定位与交互。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

摘自 JSF in action 2.3 Understanding component and client identifiers  页面:Page/103

1. UI component 生活在两个分开的世界,服务器端和客户端.在服务器端以java对象的形式存在(猜想应该是一个UIViewRoot对象),表达的是一个组件树.在客户端通常以标记语言的形式存在(例如Html).

2. 组件在服务器端有一个组件标识(component identifier),可以通过这个标识找到这个组件对象,在客户端,每个组件可以通过客户端标识(client identifier)来得到组件,客户端的标识起源于服务器端的组件标识.在客户端,通过javascript,css等语言取得客户端标识对组件进行控制.

3. 客户端的标识为服务器端和客户端架起了一座桥梁,当用户在客户端进行提交时,客户端的这些标识会随request一起传递到服务器端,服务器端根据这些标识(也就是参数的名称)对服务器端的组件进行赋值.

4.以下为组件的示例图
 JSF in action component and client identifiers
Figure 2.6 Components instances on the server are referenced via component identifiers. On the client, they are referenced by client identifiers. Sometimes the two are the same.

5. 以下为服务器端的代码:

<p>
<h:outputText id="outputText" value="What are you looking at?"/>
</p>
<h:form id="myForm">
<p>
<h:inputText/>
</p>
<p>
<h:inputText id="inputText"/>
</p>
...
</h:form>

客户端的显示为:

<p>
<span id="outputText">What are you looking at?</span>
</p>
<form id="myForm" method="post"
action
="/jia-standard-components/client_ids.jsf"
enctype
="application/x-www-form-urlencoded">
<p>
<input type="text" name="myForm:_id1" />
</p>
<p>
<input id="myForm:inputText" type="text" name="myForm:inputText" />
</p>
...
</form>

6. 可以看出如果在组件中不设定id那么JSF会自动设定这个id,组件标识和客户端标识中间存在着对应关系,有时两个的值是一样的,组件的标识名称要符合一定的规范,只能以字母或下划线开头,后面跟字母,数字,中划线和下划线(Component identifiers must start with a letter or an underscore (_) and be composed of letters, numbers, dashes (-) and underscores),而且长度尽量要短,以避免提交回复时的字节长度.如果组件不被java程序或客户端来引用,那么可以不用设定标识.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值