2012-06-21 135 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