2012-06-21 136 views
0

我的網頁中有以下一段代碼。在action中的方法執行之後,將呈現指示過程是否成功的標籤。單擊按鈕後隱藏標籤richfaces

我想要的是該標籤隱藏在按鈕被點擊後。我怎樣才能做到這一點?

我想使用actionListener但我不知道,如果它的工作原理是:

  1. 調用的ActionListener的方法
  2. 重新渲染MyView的(清除我的標籤)
  3. 呼叫行動的方法
  4. 重新渲染myView(顯示標籤過程是否成功)

或者,在onclick="getElementById().hide"

任何想法?

乾杯,

... 
    ... 
    <a4j:commandButton id="btnActualizaCubo" 
         value="Actualizar Cubo" 
         render="messageDependenciaCubo actualizacionCuboLabels @this" 
         onclick="return confirm('Las fechas seleccionadas son correctas?');" 
         onbegin="this.disabled=true; 
         document.getElementById('formActualizacionCubo:imgProcesandoCubo').style.display='block'" 
         oncomplete="this.disabled=false; 
         document.getElementById('formActualizacionCubo:imgProcesandoCubo').style.display='none'" 
         action="#{administrationBean.doActualizaCubo}"/> 
    ... 
    <a4j:outputPanel id="actualizacionCuboLabels" style="font-size: 14px; color: #D17100"> 
     <h:outputText rendered="#{administrationBean.actualizacionCuboCorrectaLabelRendered}" 
         value="Actualización correcta !"/> 
     <h:outputText rendered="#{administrationBean.actualizacionCuboFalloLabelRendered}" 
         value="Fallo la actualización !"/> 
    </a4j:outputPanel> 
    ... 

回答

1

使用 「點擊」 的方法來隱藏使用JavaScript的文本。一個簡單的方法就是用一個div來包裝你的標籤,並分別在onclick/oncomplete方法中隱藏/顯示div。另外,請記住,生成一個div來完成這項工作,所以你只需要獲取HTML生成的id並隱藏/顯示它。我會讓你的JS功能隱藏/顯示一個div(很容易,我必須說):

<script type="text/javascript"> 
    function ocultaDiv(divId) { 
     document.getElementById(divId).style.display = 'none'; 
    } 

    function muestraDiv(divId) { 
     document.getElementById(divId).style.display = 'block'; 
    } 
</script> 
<a4j:commandButton id="btnActualizaCubo" 
    value="Actualizar Cubo" 
    render="messageDependenciaCubo actualizacionCuboLabels @this" 
    onclick="return confirm('Las fechas seleccionadas son correctas?'); ocultaDiv('myForm:actualizacionCuboLabels');" 
    onbegin="this.disabled=true; document.getElementById('formActualizacionCubo:imgProcesandoCubo').style.display='block'" 

的onComplete =「this.disabled = FALSE;的document.getElementById('formActualizacionCubo:imgProcesandoCubo ').style.display =' 無 '; muestraDiv(' myForm的:actualizacionCuboLabels');」 action =「#{administrationBean.doActualizaCubo}」/>

請記住,如果您使用普通JavaScript並保存性能,請不要使用服務器調用呈現您的項目。另外,如果您使用RF 3.3或RF 4添加關於您正在使用的圖像的提示,請添加,如「正在加載,請稍候」,這可以使用甚至可以凍結整個頁面的圖像來完成(無需禁用你的按鈕和鏈接!)。

+0

謝謝Luiggi我會嘗試你對標籤的建議。有一個線程,我問這裏的圖像http://stackoverflow.com/questions/10900860/disable-button-and-show-loading-image-while-processing-jsf – BRabbit27

+0

@ BRabbit27你使用JSF 1.2或JSF 2 ? –

+0

JSF 2.1.6(Mojarra) – BRabbit27