我有一个使用 rich:fileUpload
和 a4j:commandButton
的页面,我想要实现的是,第一次加载页面时,应该出现 fileUpload(被渲染,我的 backingBean 默认为 true,因此它正确渲染)并且当用户点击 commandButton 时,我很想隐藏 fileUpload 并显示 outputText
(这没有发生,根本没有错误)
我该如何解决这个问题,我的页面看起来像
<div id="content">
<a4j:outputPanel id="contentForm">
<h:form enctype="multipart/form-data"
rendered="#{uploadBean.formRendered}">
<br/><br/>
<h:selectOneRadio value="#{uploadBean.selectedOption}">
<f:selectItems value="#{uploadBean.loadOptions}"/>
</h:selectOneRadio>
<br/>
<rich:fileUpload addLabel="Agregar" clearAllLabel="Quitar todos"
clearLabel="Quitar" deleteLabel="Quitar"
doneLabel="Completado" uploadLabel="Subir archivos"
fileUploadListener="#{uploadBean.doUpload}"
acceptedTypes="txt, csv"
noDuplicate="true"/>
<a4j:commandButton value="Iniciar validación"
action="#{uploadBean.doLaunchProcess}"
render="processLabel"
execute="@form"
/>
</h:form>
</a4j:outputPanel>
<a4j:outputPanel id="processLabel">
<h:outputText
value="#{uploadBean.processStarted}"
rendered="#{not uploadBean.formRendered}"/>
</a4j:outputPanel>
</div>
命令按钮的 Action 代码是:
public String doLaunchProcess() {
formRendered = false;
InfoValidator iv = new InfoValidator(loadOptions,
selectedOption, userBean.getDependencia(),
userBean.getTipoDependencia(), userBean.getUsuario(),
userBean.getIdUsuario(), userBean.getEmail());
iv.start();
return "carga-archivos";
}
似乎 formRendered
总是评估为 true 当我希望它在用户单击按钮时为 false,因此 fileUpload 隐藏并显示 outputText。
更新 基本上我想要的是用户上传文件,当用户单击按钮时,fileUpload 组件消失并且出现 outputText 并说类似“感谢上传”
也许我的方法是错误的,只是让我朝着正确的方向前进,我有点混淆了 ajax 的东西。
干杯,
最佳答案
我终于做到了!
这是代码,因此您可以看到修改。
基本上我必须处理 a4j:commandButton 已经完成的整个表单 (execute="@form"
) 然后 render="contentForm :processLabel"
。
我只是渲染(重新渲染?)只是 processLabel 和表单总是在那里,因为我没有更新 View (我认为这必须与 DOM 树有关,请有人澄清这一点)
<div id="content">
<a4j:outputPanel id="contentForm">
<h:form enctype="multipart/form-data"
rendered="#{uploadBean.formRendered}">
<br/><br/>
<h:selectOneRadio value="#{uploadBean.selectedOption}">
<f:selectItems value="#{uploadBean.loadOptions}"/>
</h:selectOneRadio>
<br/>
<rich:fileUpload addLabel="Agregar" clearAllLabel="Quitar todos"
clearLabel="Quitar" deleteLabel="Quitar"
doneLabel="Completado" uploadLabel="Subir archivos"
fileUploadListener="#{uploadBean.doUpload}"
acceptedTypes="txt, csv"
noDuplicate="true"/>
<a4j:commandButton value="Iniciar validación"
action="#{uploadBean.doLaunchProcess}"
render="contentForm :processLabel"/>
</h:form>
</a4j:outputPanel>
<a4j:outputPanel id="processLabel">
<h:outputText
value="#{uploadBean.processStarted}"
rendered="#{not uploadBean.formRendered}"/>
</a4j:outputPanel>
</div>
backing bean 保持不变。
干杯!!!
关于ajax - Richfaces 使用 a4j 呈现 :ajax,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9121279/