2013-06-11 31 views
0

我有一個複合控件如下;Javascript函數不能在複合控件內工作JSF

< HTML的xmlns = 「http://www.w3.org/1999/xhtml」 的xmlns:複合= 「http://java.sun.com/jsf/composite」 的xmlns:H = 「http://java.sun.com/jsf/html」>

<composite:interface> 
    <composite:attribute name="validatorId"/> 
    <composite:attribute name="message"/>   
</composite:interface> 

<composite:implementation> 
    <div>     
     <script type="text/javascript"> 
      function #{cc.attrs.validatorId}(){alert('why is it not working :(');}; 
     </script>         
     <div style="background-color: #F2DEDE;color: #b94a48;border-style: solid;border-color: #FAC3CB;border-width: 1.8px;font-family: Arial; 
       font-size: 12px;height:17px;vertical-align: middle;padding-left: 8px;padding-right: 8px;padding-top: 2px;display: none;" 
       id="#{cc.attrs.validatorId}"> 
      #{cc.attrs.message} 
      <img src="images/close-mini.png" style="cursor: pointer;padding-left: 5px;"/>    
     </div> 
    </div> 
</composite:implementation> </html> 

這種控制被放置在一個XHTML文件。該JavaScript和複合控制被渲染爲預期的方式。但是,當對GlassFish服務器發生異常時向xhtml發出請求時:

java.lang.IllegalStateException:PWC3999:響應提交後無法創建會話。

可能是什麼原因?當我刪除javascript函數異常不會發生。

+0

你可以包含整個堆棧跟蹤嗎? –

+1

重複http://stackoverflow.com/search?q=Cannot+create+a+session+after+the+response+has+been+提交。當你添加JS代碼時發生的事情純屬巧合。當您添加相同數量的純HTML或純文本字節時,也會發生這種情況。 – BalusC

回答

0

以下預渲染聽者在複合控制被添加,

<f:event type="preRenderView" listener="#{fieldValidatorBean.PreRenderValidator}"/> 

與聽者函數內部,

public void PreRenderValidator(){ 
    FacesContext.getCurrentInstance().getExternalContext().getSession(true); 
    System.out.println("prerender being called"); 
} 

以重新啓用會話。謝謝@BalusC。