RichFaces 4文件上传清除和清除所有按钮 [英] RichFaces 4 fileupload clear and clear all buttons

查看:141
本文介绍了RichFaces 4文件上传清除和清除所有按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 < rich:fileUpload addLabel =AgregarclearAllLabel =Quitar todos
clearLabel =QuitardeleteLabel =Quitar
doneLabel =CompletadouploadLabel =Subir archivos
fileUploadListener =#{uploadBean.doUpload}
acceptedTypes =txt ,csv
noDuplicate =true>
< a4j:ajax event =uploadcompleterender =validationButton/>
< a4j:ajax event =clearlistener =#{uploadBean.doClearFilesList}
render =validationButton/>
< / rich:fileUpload>

在backing bean上,我有一个上传文件的列表。当我点击 Clear / Clear all 按钮时,会触发事件 clear ,方法 doClearFilesList当用户点击 Clear All 按钮时,(只是清除上传的文件列表)是完美的,但是如果用户点击清除按钮它应该只是删除列表中相应的文件清除的项目。



我可以做什么我的 UploadBean.doClearFilesList 方法从列表中删除单个文件?应该是这样的:

  public void doClearFilesList(){
files.clear(); //当CLEAR ALL被点击
files.remove(oneFile); //当CLEAR被点击时
validationButtonRendered = false;



$ b $ p
$ b $ p







p>干杯



更新

RichFaces 4.1.0最终
JSF Mojarra 2.1.6
Tomcat 7

解决方案

我不清楚您未能运行示例在 https://community.jboss.org/message/727544#727544



然而,我希望以下内容对您的工作非常类似于上面的示例。

strong>

 < h:head> 
< script>
函数clear(event){
var files = new Array();
var data = event.rf.data;
for(var i in data){
files [i] = data [i] .name;
}
clearFunc(files);
}
< / script>
< / h:头>
< body>
< h:form>
< rich:fileUpload onclear =clear(event);/>
< a4j:jsFunction name =clearFuncaction =#{del.clearFile}ajaxSingle =true>
< a4j:param name =fNameassignTo =#{del.fileNames}/>
< / a4j:jsFunction>
< / h:表格>
< / body>

Class:

  public class Del {
String [] fileNames;
public void clearFile(){
for(String name:fileNames){
System.out.println(>>+ name);
//在此删除文件

$ b $ public String [] getFileNames(){
return fileNames;
}
public void setFileNames(String [] fileNames){
this.fileNames = fileNames;
}
}


Well currently I have this:

<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:ajax event="uploadcomplete" render="validationButton"/>
    <a4j:ajax event="clear" listener="#{uploadBean.doClearFilesList}"
              render="validationButton"/>
</rich:fileUpload>

On the backing bean I have a list of the files uploaded. When I click on Clear/Clear all button the event clear is fired and the method doClearFilesList (which just clears the list of files uploaded) is perfectly when the user hits the Clear All button, but If the user clicks on Clear button It should just delete the item on the list corresponding to the file cleared.

What can I do on my UploadBean.doClearFilesList method to delete a single file from the list? Should be something like:

public void doClearFilesList(){
    files.clear(); //when CLEAR ALL is clicked
    files.remove(oneFile); //when CLEAR is clicked
    validationButtonRendered = false;
}

Any idea?

Cheers

UPDATE

RichFaces 4.1.0 Final JSF Mojarra 2.1.6 Tomcat 7

解决方案

I am not clear at which point you failed to run the sample described at https://community.jboss.org/message/727544#727544

However I hope following would work for you which is very similar to above sample.

Page:

<h:head>
<script>
  function clear(event) {
    var files = new Array();
    var data = event.rf.data;
    for (var i in data) {
      files[i] = data[i].name;
    }
    clearFunc(files);
  }
</script>
</h:head>
<body>
  <h:form>
    <rich:fileUpload onclear="clear(event);"/>
    <a4j:jsFunction name="clearFunc" action="#{del.clearFile}" ajaxSingle="true">
      <a4j:param name="fName" assignTo="#{del.fileNames}" />
    </a4j:jsFunction>
  </h:form>
</body>

Class:

public class Del {
  String[] fileNames;
  public void clearFile() {
    for(String name : fileNames) {
      System.out.println(">>" + name);
      //Do file removing part here
    }
  }
  public String[] getFileNames() {
    return fileNames;
  }
  public void setFileNames(String[] fileNames) {
    this.fileNames = fileNames;
  }
}

这篇关于RichFaces 4文件上传清除和清除所有按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆