您的位置:首页 > Web前端 > JavaScript

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

2008-04-09 10:21 591 查看
摘自 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.以下为组件的示例图



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程序或客户端来引用,那么可以不用设定标识.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: