jiz zz在亚洲,精品无码专区亚洲,大桥未久亚洲无av码在线 http://m.tkk7.com/luluyanglu/category/38269.htmlzh-cnTue, 07 Jun 2011 09:28:05 GMTTue, 07 Jun 2011 09:28:05 GMT60JSF h:commandLink 添加確認(rèn)對話框confirmhttp://m.tkk7.com/luluyanglu/archive/2009/10/25/299707.html大魚大魚Sun, 25 Oct 2009 15:26:00 GMThttp://m.tkk7.com/luluyanglu/archive/2009/10/25/299707.htmlhttp://m.tkk7.com/luluyanglu/comments/299707.htmlhttp://m.tkk7.com/luluyanglu/archive/2009/10/25/299707.html#Feedback0http://m.tkk7.com/luluyanglu/comments/commentRss/299707.htmlhttp://m.tkk7.com/luluyanglu/services/trackbacks/299707.htmlh:commandLink與h:commandButton都可以通過下面這種方式添加對話框

Js代碼 復(fù)制代碼
  1. onclick="if(!comfirm('確認(rèn)刪除么?')) return false;"  

 

同樣的,RichFaces的a:commandLink與a:commandButton也是一樣操作

 

但是對于seam的s:link與s:button就不用,按照以前一樣的方式

Js代碼 復(fù)制代碼
  1. onclick="return confirm('確認(rèn)刪除?');"  


大魚 2009-10-25 23:26 發(fā)表評論
]]>
JSF使用注意點http://m.tkk7.com/luluyanglu/archive/2009/10/25/299702.html大魚大魚Sun, 25 Oct 2009 14:50:00 GMThttp://m.tkk7.com/luluyanglu/archive/2009/10/25/299702.htmlhttp://m.tkk7.com/luluyanglu/comments/299702.htmlhttp://m.tkk7.com/luluyanglu/archive/2009/10/25/299702.html#Feedback0http://m.tkk7.com/luluyanglu/comments/commentRss/299702.htmlhttp://m.tkk7.com/luluyanglu/services/trackbacks/299702.htmlJSF使用注意點

1.轉(zhuǎn)換時間時,必須加上時區(qū)GMT+8,不然相差一天。
<f:convertDateTime  timeZone="GMT+8" dateStyle="long" type="date"/>
 
2.<h:outputText value="#{productBean.view}"/>當(dāng)view為空時,不顯示。
 
3. 
actionListener在執(zhí)行了action之后再執(zhí)行。
 
可以沒有action,而只有actionListener。
 
action可以設(shè)置成一個方法,也可以設(shè)置為一個導(dǎo)航用例的<from-outcome>
多個頁面如果使用了同一個request級的backingBean,可能導(dǎo)致一些莫名其妙的問題。如:不能執(zhí)行指定的Action.
 
4.對于向managed-bean的屬性注入request參數(shù)時,其<managed-bean-scope>必須為request,<property-class>不要為值類型(如果是值類型,當(dāng)指定的request參數(shù)為空時,注入時會出錯,因為一個空對象如Integer null不能自動轉(zhuǎn)換為一個值類型如int的0)。如下所示:
<managed-bean>
   <managed-bean-name>productBean</managed-bean-name>
   <managed-bean-class>demo.view.ProductBean</managed-bean-class>
   <managed-bean-scope>request</managed-bean-scope>
   <managed-property>
    <property-name>id</property-name>
    <property-class>java.lang.Integer</property-class>
    <value>#{param.id}</value>
   </managed-property>
   <managed-property>
    <property-name>view</property-name>
    <property-class>java.lang.Boolean</property-class>
    <value>#{param.view}</value>
   </managed-property>
  </managed-bean>
 
5.對于以下查找是按部件id查找的,不是按參數(shù)名稱查找的。
UIParameter uip =(UIParameter)event.getComponent().findComponent("productId");
//event是actionListener中的參數(shù)ActionEvent類型。
所以
<h:commandLink action="view">
<f:param id="productId" name="id" value="#{product.id}"/>
</h:commandLink>
<f:prarm>必須設(shè)置id
 
Map params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
String someValue = params.get("id");

這個是按參數(shù)名稱查找的
JSF標(biāo)簽只是JSF組件的外衣,Id就是組件的命名,與Delphi的組件名是一樣的,之所以用Id不用Name,是為了與HTML中的一致(HTML input組件 id是其標(biāo)識,name是其傳遞到服務(wù)器端的參數(shù)名。),所以查找JSF組件當(dāng)然用Id了。
 
6.當(dāng)一個頁面的BackingBean的構(gòu)造函數(shù)中運行出錯或?qū)傩宰⑷氤鲥e時,表面上會報計算表達(dá)式錯誤,原因是這個BackingBean沒有構(gòu)造出來,為空,當(dāng)然在Reader頁面時會沒有辦法求相關(guān)的表達(dá)式的值。
 
 
7.request級的BackingBean在從客戶端到服務(wù)端一次請求后,就被銷毀。在這次請求中,只會被創(chuàng)建一次。在Forward之前創(chuàng)建的BackingBean在Forward之后,并不會被再次創(chuàng)建。
 
8.判斷是否是回傳。
protected boolean isPostBack()
 {
  if (FacesContext.getCurrentInstance().getRenderResponse())
   return false;
  else
   return true;
 }
 
 
9.<f:view>里使用<jsp:include>時的注意事項
感謝 tdwebber 提供。

1) When using a jsp:include within the f:view tags, must include f:subview in the included file (or around the jsp:include tag).

當(dāng)在f:view中使用jsp:include標(biāo)簽插入一個文件時,必須用f:subview把jsp:include包起來

2) In the include file, cannot have any HTML. All HTML tags must be wrapped in f:verbatim tags.

在被插入的文件中,不能有任何的html標(biāo)簽,如果必須使用html標(biāo)簽,必須用f:verbatim將它包起來。

3) Within main f:view tags however, it is not necessary to wrap everything in f:verbatim tags (it's not bad either). Just HTML that appears as children to other JSF components (i.e. t:newspaperTable).

在主f:view中,沒有必要用f:verbatim將html標(biāo)簽包起來(當(dāng)然包起來也可以)。當(dāng)html標(biāo)簽出現(xiàn)在子視圖或其它JSF部件標(biāo)簽中時,就要用f:verbatim包起來。

10.JSF的緩存能力好像太強了,有時停止了服務(wù)器,改動了jsp頁面中的jsf標(biāo)簽,再啟動服務(wù)器,但到該頁面時,還是原來的內(nèi)容,需要手動刷新一下。有時需要先轉(zhuǎn)到別的頁面,再回來刷新一下才能看到更新的內(nèi)容。



大魚 2009-10-25 22:50 發(fā)表評論
]]>
JSF中commandLink與dataTable搭配不能正常工作的解決辦法http://m.tkk7.com/luluyanglu/archive/2009/10/15/298385.html大魚大魚Thu, 15 Oct 2009 06:28:00 GMThttp://m.tkk7.com/luluyanglu/archive/2009/10/15/298385.htmlhttp://m.tkk7.com/luluyanglu/comments/298385.htmlhttp://m.tkk7.com/luluyanglu/archive/2009/10/15/298385.html#Feedback0http://m.tkk7.com/luluyanglu/comments/commentRss/298385.htmlhttp://m.tkk7.com/luluyanglu/services/trackbacks/298385.html1.     環(huán)境

Myfaces1.4 + tomahawk-1.1.3 + tomcat5.x + JDK5

下載:http://myfaces.apache.org

2.     問題描述

假設(shè)場景,首先顯示用戶列表(用dataTable來實現(xiàn)列表顯示),然后可以點擊用戶的名字導(dǎo)航到用戶詳細(xì)信息頁面。

3.     嘗試實現(xiàn)以及出現(xiàn)的問題

UserInfo.java

package com.wide.jsf.model;

 

/**

 * 用戶信息

 *

 * @author cydooo

 *

 */

public class UserInfo {

    private Long userId;

    private String username;

    private String userdesc;

    public UserInfo() {

    }

    public UserInfo(Long userId, String username) {

        this.userId = userId;

        this.username = username;

    }

    public UserInfo(Long userId, String username, String userdesc) {

        this(userId, username);

        this.userdesc = userdesc;

    }

    //省略getter和setter

}
 


UserInfoAction.java

package com.wide.jsf.web;

 

import java.util.Arrays;

import java.util.List;

 

import javax.faces.context.FacesContext;

 

import com.wide.jsf.model.UserInfo;

 

public class UserInfoAction {

 

    /*

     * 用于顯示詳細(xì)信息

     */

    private UserInfo userInfo;

 

    /*

     * 用于顯示用戶列表

     */

    private List<UserInfo> userInfos;

 

    public UserInfo getUserInfo() {

       return userInfo;

    }

 

    public void setUserInfo(UserInfo userInfo) {

       this.userInfo = userInfo;

    }

 

    public List<UserInfo> getUserInfos() {

       return userInfos;

    }

 

    public void setUserInfos(List<UserInfo> userInfos) {

       this.userInfos = userInfos;

    }

 

    public String listUser() {

       userInfos = Arrays.asList(new UserInfo[] { new UserInfo(1L, "Tom"),new UserInfo(2L, "John"), new UserInfo(3L, "Lily") });

         return "listUser";

    }

 

    public String showDetail() {

       FacesContext context = FacesContext.getCurrentInstance();

       Long userId = Long.parseLong((String) context.getExternalContext()

              .getRequestParameterMap().get("userId"));

       System.out.println("==>" + userId);

       switch (userId.intValue()) {

       case 1:

           userInfo = new UserInfo(1L, "Tom", "I am Tom");

           break;

       case 2:

           userInfo = new UserInfo(2L, "John", "I am John");

           break;

       case 3:

           userInfo = new UserInfo(3L, "Lily", "I am Lily");

       }

       return "userdetail";

    }

}
 


Backingbean和navigation的配置

<managed-bean>

       <managed-bean-name>userInfoAction</managed-bean-name>

       <managed-bean-class>

           com.wide.jsf.web.UserInfoAction

       </managed-bean-class>

       <managed-bean-scope>request</managed-bean-scope>

    </managed-bean>

    <navigation-rule>

       <from-view-id>/listUser.jsp</from-view-id>

       <navigation-case>

           <from-outcome>userdetail</from-outcome>

           <to-view-id>/userdetail.jsp</to-view-id>

       </navigation-case>

    </navigation-rule>

    <navigation-rule>

       <from-view-id>/userdetail.jsp</from-view-id>

    </navigation-rule>
 


Jsp頁面內(nèi)容

A. listUser.jsp

<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>

<%@ page contentType="text/html; UTF-8" pageEncoding="UTF-8"%>

 

<f:view>

<html>

  <head>

    <title>userlist</title>

  </head>

 

  <body>

    <h:form>

       <h:dataTable var="user" value="#{userInfoAction.userInfos}">

           <h:column>

              <h:commandLink value="#{user.username}" action="#{userInfoAction.showDetail}">

                  <f:param value="#{user.userId}" name="userId"/>

              </h:commandLink>

           </h:column>

       </h:dataTable>

    </h:form>

  </body>

</html>

</f:view>
 


B. userdetail.jsp

<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>

<%@ page contentType="text/html; UTF-8" pageEncoding="UTF-8"%>

 

<f:view>

<html>

  <head>

    <title>userDetail</title>

  </head>

 

  <body>

    <h:form>

    <h:outputText value="#{userInfoAction.userInfo.userdesc}"/>

    </h:form>

  </body>

</html>

</f:view>
 


編碼結(jié)束,啟動tomcat測試,進(jìn)入userlist頁面之后,我們可以看到用戶列表,但點擊用戶查看詳細(xì)信息的時候,發(fā)現(xiàn)并沒有調(diào)用showDetail方法。

4.     解決辦法

A.                        將<managed-bean-scope>request</managed-bean-scope>改為<managed-bean-scope>session</managed-bean-scope>。這是最簡單的做法,改了之后重起Tomcat之后馬上就看到效果了。但是很明顯的使用session scope不好,比如這個例子,用戶列表在當(dāng)前seesion有效的情況下將一直保留,多窗口瀏覽器中也容易發(fā)生意想不到的問題。沒有必要不要用session。

B.                        將用戶列表綁定到dataTable控件。

首先修改UserInfo類,讓他實現(xiàn)Serializable接口,其他代碼完全一樣,實現(xiàn)Serializable接口是必須的,否則會拋出java.io.NotSerializableException異常。

public class UserInfo implements Serializable{…}
 


UserInfoAction.java的修改

package com.wide.jsf.web;

 

import java.util.Arrays;

import java.util.List;

 

import javax.faces.component.html.HtmlDataTable;

import javax.faces.context.FacesContext;

 

import com.wide.jsf.model.UserInfo;

 

public class UserInfoAction {

 

    /*

     * 用于顯示詳細(xì)信息

     */

    private UserInfo userInfo;

 

    /*

     * 綁定用戶列表

     */

    private HtmlDataTable dataTable = new HtmlDataTable();

   

    public UserInfo getUserInfo() {

       return userInfo;

    }

 

    public void setUserInfo(UserInfo userInfo) {

       this.userInfo = userInfo;

    }

 

    public String listUser() {

       List<UserInfo> userInfos = Arrays.asList(new UserInfo[] { new UserInfo(1L, "Tom"),

              new UserInfo(2L, "John"), new UserInfo(3L, "Lily") });

       dataTable.setValue(userInfos);

       return "listUser";

    }

 

    public String showDetail() {

       FacesContext context = FacesContext.getCurrentInstance();

       Long userId = Long.parseLong((String) context.getExternalContext()

              .getRequestParameterMap().get("userId"));

       System.out.println("==>" + userId);

       switch (userId.intValue()) {

       case 1:

           userInfo = new UserInfo(1L, "Tom", "I am Tom");

           break;

       case 2:

           userInfo = new UserInfo(2L, "John", "I am John");

           break;

       case 3:

           userInfo = new UserInfo(3L, "Lily", "I am Lily");

       }

       return "userdetail";

    }

 

    public HtmlDataTable getDataTable() {

       return dataTable;

    }

 

    public void setDataTable(HtmlDataTable dataTable) {

       this.dataTable = dataTable;

    }

}
 


listUser.jsp的修改

<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>

<%@ page contentType="text/html; UTF-8" pageEncoding="UTF-8"%>

 

<f:view>

<html>

  <head>

    <title>userlist</title>

  </head>

 

  <body>

    <h:form>

       <h:dataTable var="user" binding="#{userInfoAction.dataTable}">

           <h:column>

              <h:commandLink value="#{user.username}" action="#{userInfoAction.showDetail}">

                  <f:param value="#{user.userId}" name="userId"/>

              </h:commandLink>

           </h:column>

       </h:dataTable>

    </h:form>

  </body>

</html>

</f:view>
 


重起Tomcat一切OK,不需要非得在session scope下了。

 

本文來自CSDN博客,轉(zhuǎn)載請標(biāo)明出處:http://blog.csdn.net/pengrg166/archive/2007/01/22/1490174.aspx



大魚 2009-10-15 14:28 發(fā)表評論
]]>
jsf幾個常用取值方法和技巧總結(jié)http://m.tkk7.com/luluyanglu/archive/2009/03/17/260241.html大魚大魚Tue, 17 Mar 2009 06:17:00 GMThttp://m.tkk7.com/luluyanglu/archive/2009/03/17/260241.htmlhttp://m.tkk7.com/luluyanglu/comments/260241.htmlhttp://m.tkk7.com/luluyanglu/archive/2009/03/17/260241.html#Feedback0http://m.tkk7.com/luluyanglu/comments/commentRss/260241.htmlhttp://m.tkk7.com/luluyanglu/services/trackbacks/260241.html jsf幾個常用取值方法和技巧總結(jié)(持續(xù)更新)

1、獲取managedbean或是解析表達(dá)式
有三種方法

(1)
[code]
FacesContext context =FacesContext.getCurrentInstance();
ValueBinding binding =
context.getApplication().createValueBinding("#{bean}");
YourBean bean = (YourBean ) binding.getValue(context);
[/code]

(2)
[code]
FacesContext ctx = FacesContext.getCurrentInstance();
VariableResolver variableResolver =ctx.getApplication().getVariableResolver();
YourBean bean = (YourBean ) variableResolver.resolveVariable(ctx, "bean");
[/code]

(3)
[code]
Application application=context.getApplication();
YourBean ManageBeanProperty=(YourBean )application.evaluateValueExpressionGet(context,"#{bean}",YourBean .class);
[/code]

第3種方法只對jsf1.2可用。(evaluateValueExpressionGet方法1.1種沒有)
其實還有一種方法。后面會提到。


2、對于已知范圍和名字的bean,可以
externalContext.getRequestMap().get(beanName)
externalContext.getSessionMap().get(beanName)
externalContext.getApplicationMap().get(beanName)


3、FacesContext
組件實例相關(guān)

facesContext.getViewRoot()
可以獲取ViewRoot,然后遞歸循環(huán)其children得到整個組件樹,
可以實現(xiàn):
(1)根據(jù)組建id得到組件。
(2)得到form,添加新的組件到此集合,或是改變form的屬性。
(3)得到某個類型的所有組件,然后加上監(jiān)聽器。
。。。。。
從這個root入手,再加上事件,綁定和分析,幾乎可以完全控制整個組件樹。


4、Application
獲取方式Application application=facesContext.getApplication();
用處可以見下面的代碼:
(1)組件類型的注冊和組件集合的獲取
(2)converter,validator的。。。
(3)屬性分析器和變量分析器的。。。
(4)NavigationHandler、ViewHandler....
(5)添加一個listener
(6)創(chuàng)建一個組件的實例
(7)創(chuàng)建一個值綁定或方法綁定

大部分全局性配置的東西都在這兒可以找到。而且?guī)缀醵际强梢詿崽鎿Q的。
其中5、6比較常用。


5、RuntimeConfig
獲取方式RuntimeConfig runtimeConfig = RuntimeConfig.getCurrentInstance();

兩個功能:
(1)獲取配置文件中所有的導(dǎo)航規(guī)則,或者運行時添加新的導(dǎo)航規(guī)則。
(2)獲取配置文件中所有的managedmean類型,或者運行時添加一個新的managedmean類型。

第一條可以實現(xiàn)通過一個給定的url,動態(tài)添加一條規(guī)則,然后在action中return起outcome字符串。
后一條可以獲取給定的bean的class全稱,實例化一個bean。或者動態(tài)配置一個bean。


6、ExternalContext
servlet相關(guān)操作和各種參數(shù)
(1)獲取response和request、session、servletContext
(2)redirect和dispacth
(3)獲取resquest、session、application、servlet參數(shù)
(4)獲取資源和url本地路徑
(5)encode url

 
7、綁定List和Map
使用JSF開發(fā)時,經(jīng)常遇到要把MBean中的一個List或Map中的值通過EL顯示在頁面上,EL中訪問Map或List的方法如下:

假設(shè)FacesConfig中配置一個bean的MBean,它的類中定義了一個List類型的list屬性和一個Map型的map屬性。

首先是訪問List,頁面中引用bean中l(wèi)ist屬性的方法為:#{bean.list[index]}

而對于Map,EL可以把Key作為一個屬性來讀取,因此對map的訪問可以寫為:#{bean.map.key},當(dāng)然這樣可以解決基本的問題,但是如果map中的key是一個包含了空格或特殊字符的String,那么很明顯,這個字符串不符合作為屬性名的條件,那么用上面的方法去訪問明顯是有問題的,所以我們很可以用另外一種方法訪問Map中的value,#{bean.map['key']}。同時可以看到,因為EL中的內(nèi)建對象基本都是用Map實現(xiàn)的,因此,EL中的訪問方法也是:#{sessionScope['key']}。


8、JSF動態(tài)為DataTable添加列
開發(fā)JSF的朋友可能會遇到這樣的問題,如果DataTable的列不固定,需要動態(tài)生成, 該如何實現(xiàn)呢。

假設(shè)FacesConfig中配置一個名為bean的MBean,該MBean中需定義一個類型為javax.faces.component.html.HtmlDataTable類型的變量dt,頁面中的DataTable設(shè)置bingding="#{bean.dt}"。

首先了解一下JSF中DataTable的渲染方式:

DataTable

--<Header> UIComponent

--<Children>List<HtmlColumn>

----<HtmlColumn>

------<Header>UIComponent

----<Children>List<UIComponent>

因此,要在后臺變更DataTable的狀態(tài),可以用dt.setHeader(UIComponent)設(shè)置DataTable的表頭,然后可以往dt.getChildren()中添加HtmlColumn類型的列,同樣,列中也可以由Header和Children組成。代碼實現(xiàn)如下:

private void initialReportTable(List<ExcelReport> reportList) ...{
dt.getChildren().clear();
for (ExcelReport report : reportList) ...{
HtmlColumn column = new HtmlColumn();
HtmlOutputText header = new HtmlOutputText();
header.setValueExpression("value",
getValueExpression("#{rmaReport.captions.c"
+ report.getPosition() + "}"));
column.setHeader(header);

HtmlOutputText value = new HtmlOutputText();
String ve = getVEString(report);
System.out.println(report.getCaption() + " : " + ve);
value.setValueExpression("value", getValueExpression(ve));
column.getChildren().add(value);

dt.getChildren().add(column);
}
}其中,動態(tài)建立控件的方法為直接創(chuàng)建一個控件,然后通過ValueExpression來設(shè)置控件在運行時顯示的值,如果是Column中的數(shù)據(jù),則可以使用#{tableVar.ColumnName}格式的EL表達(dá)式。

9、 JSF動態(tài)生成組件

用過Servlet和JSP的開發(fā)者對動態(tài)生成組件應(yīng)該是情有獨鐘了,可以根據(jù)數(shù)據(jù)的情況生成特定的組件,這樣增大了Form的靈活性,那么JSF中如何生成動態(tài)的窗體呢,其實非常簡單。主要邏輯就是通過FacesContext得到viewRoot對象,然后通過viewRoot對象的getChildren方法可以得到viewRoot下的所有第一級組件,然后分別對每個組件的getChildren方法進(jìn)行遞歸調(diào)用,就可以得到整個組件樹,當(dāng)然可以對某個組件的getChildren得到的List使用add方法添加組件了,代碼如下,頁面有兩個commandButton,其中一個可以添加一個TextBox控件,另外一個可以在console打印出當(dāng)前的組件列表。

package net.moon;

import java.util.List;

import javax.faces.component.UIComponent;
import javax.faces.component.UIViewRoot;
import javax.faces.component.html.HtmlInputText;
import javax.faces.context.FacesContext;

public class DymaComponent ...{

private UIViewRoot viewRoot;
private static int inputIndex = 0;

private List<UIComponent> getComponentChildren(UIComponent component)...{
List<UIComponent> componentList = null;
System.out.println(component.getId());
if(component.getChildCount() > 0)...{
for(UIComponent ui : component.getChildren())...{
componentList = getComponentChildren(ui);
}
}
return componentList;
}

public String getComponentsList()...{
viewRoot = FacesContext.getCurrentInstance().getViewRoot();
for(UIComponent component : viewRoot.getChildren())...{
getComponentChildren(component);
}
return null;
}

public String addTextBox()...{
viewRoot = FacesContext.getCurrentInstance().getViewRoot();
UIComponent form1 = viewRoot.getChildren().get(0);
HtmlInputText input = new HtmlInputText();
input.setId("input" + (inputIndex++));
input.setValue("Input 1");
input.setRendered(true);
form1.getChildren().add(input);
return null;
}

}

<%...@ page contentType="text/html; charset=UTF-8" %>
<%...@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%...@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title></title>
</head>
<body>
<f:view>
<h:form id="form1">
<h:commandButton id="commmand1" action="#{dymaComponent.getComponentsList}" value="Print ViewRoot"></h:commandButton>
<h:commandButton action="#{dymaComponent.addTextBox}" value="Add TextBox"></h:commandButton>
</h:form>
</f:view>
</body>
</html>

<?xml version="1.0" encoding="UTF-8"?>

<faces-config
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"
version="1.2">
<managed-bean>
<managed-bean-name>
dymaComponent</managed-bean-name>
<managed-bean-class>
net.moon.DymaComponent</managed-bean-class>
<managed-bean-scope>
session</managed-bean-scope>
</managed-bean>

</faces-config>

大魚 2009-03-17 14:17 發(fā)表評論
]]>
JSF表達(dá)式語言http://m.tkk7.com/luluyanglu/archive/2009/03/17/260208.html大魚大魚Tue, 17 Mar 2009 03:54:00 GMThttp://m.tkk7.com/luluyanglu/archive/2009/03/17/260208.htmlhttp://m.tkk7.com/luluyanglu/comments/260208.htmlhttp://m.tkk7.com/luluyanglu/archive/2009/03/17/260208.html#Feedback0http://m.tkk7.com/luluyanglu/comments/commentRss/260208.htmlhttp://m.tkk7.com/luluyanglu/services/trackbacks/260208.htmlJSF的表達(dá)式語言(EL)的形式跟jSP的表達(dá)式語言的形式類似:#{...}。EL的主要用途是使你可以引用和更新bean的屬性,或者執(zhí)行簡單的語句,而不用寫完整的Java代碼。
l JSF EL基于JSP 2.0中的表達(dá)式語言,它的用法幾乎跟JSP2.0中的表達(dá)式語言一樣,但二者仍有一些關(guān)鍵不同:
l JSF使用(#)來標(biāo)記表達(dá)式的開始,而JSP使用($);
l JSF表達(dá)式是雙向的。即它可以引用屬性的值也可以更新之
l JSF EL也允許引用對象方法;
l 某些JSP特定的特征無效,比如頁面上下文范圍(page);
l JSF EL表達(dá)式可以通過常規(guī)Java代碼求解(結(jié)果是可以不需要JSP);
l JSF EL不官方支持函數(shù)。
JSF EL也支持“.”和“[]”取值。它支持全范圍的算術(shù)運算、邏輯運算與關(guān)系運算:
1.      算術(shù)運算有:
加法 (+), 減法 (-), 乘法 (*), 除法 (/ or div) 與余除 (% or mod) 。下面是算術(shù)運算的一些例子:
表達(dá)式
結(jié)果
#{1}
1
#{1 + 2}
3
#{1.2 + 2.3}
3.5
#{1.2E4 + 1.4}
12001.4
#{-4 - 2}
-6
#{21 * 2}
42
#{3 / 4}
0.75
#{3 div 4}
0.75,除法
#{3 / 0}
Infinity
#{10 % 4}
2
#{10 mod 4}
2,也是求模
#{(1 == 2) ? 3 : 4}
4
如同在Java語法一樣 ( expression ? result1 : result2)是個三元運算,expression為true顯示result1,false顯示result2。
2. 邏輯運算:
and(或&&)、or(或!!)、not(或!)。一些例子為:
表達(dá)式
結(jié)果
#{true and false}
false
#{true or false}
true
#{not true}
false
3. 關(guān)系運算:
小于Less-than(<、lt)、大于Greater-than (>、gt)、小于或等于Less-than-or-equal(<=、le)、大于或等于Greater-than-or-equal(>=、ge)、等于Equal(==、eq)、不等于Not Equal(!=、ne),由英文名稱可以得到lt、gt等運算子之縮寫詞,以下是一些例子:
表達(dá)式
結(jié)果
#{1 < 2}
true
#{1 lt 2}
true
#{1 > (4 / 2)}
false
#{1 > (4 / 2)}
false
#{4.0 >= 3}
true
#{4.0 ge 3}
true
#{4 <= 3}
false
#{4 le 3}
false
#{100.0 == 100}
true
#{100.0 eq 100}
true
#{(10 * 10) != 100}
false
#{(10 * 10) ne 100}
false
關(guān)系運算也可以用來比較字符或字符串,按字典順序來決定比較結(jié)果,例如:
表達(dá)式
結(jié)果
#{'a' < 'b'}
true
#{'hip' > 'hit'}
false
#{'4' > 3}
true
4. Empty:
用來測試空值(null、空字符串、數(shù)組、Map或者沒有值的Collection),如:
表達(dá)式
結(jié)果
#{empty ''}
true
#{empty 'abcd'}
false
JSF EL能搜索Java Web應(yīng)用的三個范圍:application、session、request中以匹配特定關(guān)鍵字的對象。因為JSF一定要鎖定到JSP,所以它不支持page范圍。JSF EL支持的隱含變量有:cookie、header、headerValues、initParam、param、paramValues、applicationScope、sessionScope、requestScope、還有facesContext(當(dāng)前請求的FacesContext實例)和view(當(dāng)前視圖)。

大魚 2009-03-17 11:54 發(fā)表評論
]]>
主站蜘蛛池模板: 亚洲伊人精品综合在合线| 无码天堂亚洲国产AV| 9久久免费国产精品特黄| 伊在人亚洲香蕉精品区麻豆| 亚洲色大成网站www永久男同| 黄色免费网站网址| 亚洲人妖女同在线播放| 亚洲免费视频播放| 久久精品国产亚洲AV久| 大地资源在线观看免费高清| 亚洲a∨无码精品色午夜| 国产在线观看免费不卡| 成人精品综合免费视频| 中文字幕亚洲不卡在线亚瑟| 亚洲国产午夜精品理论片| 99视频全部免费精品全部四虎| 亚洲国产中文在线视频| 成全高清视频免费观看| 男人的天堂av亚洲一区2区| 一本色道久久88综合亚洲精品高清| 老湿机一区午夜精品免费福利| 91麻豆精品国产自产在线观看亚洲 | 国产成人无码免费网站| 亚洲AV无码专区国产乱码4SE| 91视频免费网址| 亚洲人成网亚洲欧洲无码| 亚洲AⅤ无码一区二区三区在线| 成人无码区免费A∨直播| 亚洲视频一区二区在线观看| 成人无码区免费视频观看| 十八禁的黄污污免费网站| 亚洲国产精品高清久久久| 国产乱子精品免费视观看片| 国产亚洲视频在线观看网址| 国内精品99亚洲免费高清| 麻豆一区二区免费播放网站| 亚洲熟妇无码AV| 亚洲VA中文字幕无码毛片| 成年男女男精品免费视频网站| 日本一区二区在线免费观看| 亚洲AV无码国产在丝袜线观看|