lifecycleexception:JSF 原始碼賞析之Lifecycle

來源:互聯網
上載者:User

JSF的生命週期在JSF應用中起著至關重要的作用,每一個JSF請求的處理都需要經過一次生命週期,本文從源碼的角度分析JSF的生命週期。
在討論生命週期之前,我們先要討論FacesContext的一些元素,他們在整個生命週期中扮演了非常重要的角色。麼個JSF應用必須儲存它所處理的請求資訊,FacesContext為處理請求和產生響應儲存了所有必需的上下文資訊,具體而言,它包括:
1.資訊隊列,MessageQueue,儲存所有的訊息
2.當前的組件樹,ViewRoot,
3.外部內容,ExternalContext
4.Application。
下面就是Sun的FacesContextImpl中的變數:
com.sun.faces.context.FacesContextImpl:
//RelationshipInstanceVariables
privateResponseStreamresponseStream=null;
privateResponseWriterresponseWriter=null;
privateExternalContextexternalContext=null;
privateApplicationapplication=null;
privateUIViewRootviewRoot=null;
privateELContextelContext=null;
privateRenderKitFactoryrkFactory;
privateRenderKitlastRk;
privateStringlastRkId;

/**
*StoremappingofclientIdtoArrayListofFacesMessage
*instances.ThenullkeyisusedtorepresentFacesMessageinstances
*thatarenotassociatedwithaclientIdinstance.
*/
privateMap<String,List<FacesMessage>>componentMessageLists;
//AttributeInstanceVariables

privatebooleanrenderResponse=false;
privatebooleanresponseComplete=false;
這裡面有很多重要的對象值得我們去研究,按照從上到下的順序,我們先來看看ExternalContext。
ExternalContext其實是對ServletContext(或PortletContext)的封裝,提供了訪問外部容器資源的各種方法,ExternalContext基類定義如下:
javax.faces.context.ExternalContext:
publicabstractclassExternalContext{


publicstaticfinalStringBASIC_AUTH="BASIC";
publicstaticfinalStringCLIENT_CERT_AUTH="CLIENT_CERT";
publicstaticfinalStringDIGEST_AUTH="DIGEST";
publicstaticfinalStringFORM_AUTH="FORM";

//----------------------------------------------------------PublicMethods
publicabstractvoiddispatch(Stringpath)
throwsIOException;
publicabstractStringencodeActionURL(Stringurl);

publicabstractStringencodeNamespace(Stringname);
publicabstractStringencodeResourceURL(Stringurl);
publicabstractStringgetAuthType();
publicabstractObjectgetContext();
publicabstractStringgetInitParameter(Stringname);
publicabstractMapgetInitParameterMap();
publicabstractStringgetRemoteUser();
publicabstractObjectgetRequest();
publicvoidsetRequest(Objectrequest){
ExternalContextimpl;
if(null!=(impl=(ExternalContext)this.getRequestMap().
get("com.sun.faces.ExternalContextImpl"))){
impl.setRequest(request);
return;
}

thrownewUnsupportedOperationException();
}
publicvoidsetRequestCharacterEncoding(Stringencoding)throwsUnsupportedEncodingException{
ExternalContextimpl;
if(null!=(impl=(ExternalContext)this.getRequestMap().
get("com.sun.faces.ExternalContextImpl"))){ 本文連結http://www.cxybl.com/html/wyzz/JavaScript_Ajax/20130620/38738.html

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.