Author: mvitenkov
Date: 2008-06-28 03:04:33 -0400 (Sat, 28 Jun 2008)
New Revision: 9281
Added:
trunk/test-applications/jsp/src/main/java/fileUpload/FileUploadValidator.java
trunk/test-applications/jsp/src/main/java/rich/RichBean.java
Modified:
trunk/test-applications/jsp/src/main/java/fileUpload/FileUpload.java
trunk/test-applications/jsp/src/main/java/util/event/Event.java
trunk/test-applications/jsp/src/main/webapp/FileUpload/FileUpload.jsp
trunk/test-applications/jsp/src/main/webapp/ModalPanel/ModalPanel.jsp
trunk/test-applications/jsp/src/main/webapp/WEB-INF/faces-config-FileUpload.xml
trunk/test-applications/jsp/src/main/webapp/pages/Action/EventInfo.jsp
Log:
FileUpload validator.
Modified: trunk/test-applications/jsp/src/main/java/fileUpload/FileUpload.java
===================================================================
--- trunk/test-applications/jsp/src/main/java/fileUpload/FileUpload.java 2008-06-27
17:23:07 UTC (rev 9280)
+++ trunk/test-applications/jsp/src/main/java/fileUpload/FileUpload.java 2008-06-28
07:04:33 UTC (rev 9281)
@@ -25,8 +25,7 @@
private String listHeight;
private String listWidth;
private String align;
- private String bindLabel;
-
+ private String bindLabel;
private String addButtonClass;
private String addButtonClassDisabled;
private String cancelButtonClass;
@@ -42,13 +41,22 @@
private String uploadListClass;
private String uploadListClassDisabled;
private String changedLabel;
-
-
+ private String allowFlash;
private List data;
private Integer maxFilesQuantity;
private HtmlFileUpload myFileUpload;
private boolean noDuplicate;
+ private boolean ajaxSingle;
+ private boolean immediate;
+ public boolean isImmediate() {
+ return immediate;
+ }
+
+ public void setImmediate(boolean immediate) {
+ this.immediate = immediate;
+ }
+
public String getBindLabel() {
return bindLabel;
}
@@ -95,6 +103,9 @@
uploadListClass="test";
uploadListClassDisabled="test";
noDuplicate = false;
+ allowFlash = "false";
+ ajaxSingle = false;
+ immediate = false;
}
public void fileUploadListener(UploadEvent event) throws Exception{
@@ -343,4 +354,20 @@
public void setChangedLabel(String changedLabel) {
this.changedLabel = changedLabel;
}
+
+ public String getAllowFlash() {
+ return allowFlash;
+ }
+
+ public void setAllowFlash(String allowFlash) {
+ this.allowFlash = allowFlash;
+ }
+
+ public boolean isAjaxSingle() {
+ return ajaxSingle;
+ }
+
+ public void setAjaxSingle(boolean ajaxSingle) {
+ this.ajaxSingle = ajaxSingle;
+ }
}
Added: trunk/test-applications/jsp/src/main/java/fileUpload/FileUploadValidator.java
===================================================================
--- trunk/test-applications/jsp/src/main/java/fileUpload/FileUploadValidator.java
(rev 0)
+++
trunk/test-applications/jsp/src/main/java/fileUpload/FileUploadValidator.java 2008-06-28
07:04:33 UTC (rev 9281)
@@ -0,0 +1,39 @@
+package fileUpload;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import javax.faces.application.FacesMessage;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.validator.Validator;
+import javax.faces.validator.ValidatorException;
+import org.richfaces.model.UploadItem;
+
+
+public class FileUploadValidator implements Validator {
+
+ public void validate(FacesContext context, UIComponent component,
+ Object value) throws ValidatorException {
+
+ UploadItem upload = (UploadItem)value;
+
+ if (upload.isTempFile()) {
+ File file = upload.getFile();
+ String name = file.getName();
+ System.out.println("fileName: " + name);
+ if (name == "ExadelMinsk.avi") {
+ throw new ValidatorException(new FacesMessage("Test validator: ExadelMinsk.avi
file is restricted!"));
+ }
+ } else {
+ ByteArrayOutputStream b = new ByteArrayOutputStream();
+ try {
+ b.write(upload.getData());
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ }
+
+}
Added: trunk/test-applications/jsp/src/main/java/rich/RichBean.java
===================================================================
--- trunk/test-applications/jsp/src/main/java/rich/RichBean.java
(rev 0)
+++ trunk/test-applications/jsp/src/main/java/rich/RichBean.java 2008-06-28 07:04:33 UTC
(rev 9281)
@@ -0,0 +1,153 @@
+package rich;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.faces.context.FacesContext;
+import javax.faces.model.SelectItem;
+
+//import org.richfaces.VersionBean;
+
+public class RichBean {
+ private static final String EXT = ".jsp";
+ private String version = "3.2.2"; //VersionBean.SCM_REVISION;
+ private String src;
+ private String srcContainer;
+ private MapComponent map;
+ private List<SelectItem> list;
+
+
+ public RichBean() {
+ list = new ArrayList<SelectItem>();
+ src = "Blank";
+ srcContainer = "Blank";
+ map = new MapComponent();
+ // map.add( value, add( pages_path/name_pages, array<boolean>(Property,
Straightforward) );
+ map.add("Blank", add("/pages/Blank/Blank", new boolean [] {true,
true, true}));
+ map.add("Calendar", add("/Calendar/Calendar", new boolean [] {true,
true, true}));
+ map.add("DataFilterSlider",
add("/DataFilterSlider/DataFilterSlider", new boolean [] {true, true, false}));
+ map.add("DataScroller", add("/DataScroller/DataScroller", new
boolean [] {true, true, true}));
+ map.add("DataTable", add("/DataTable/DataTable", new boolean []
{true, true, true}));
+ map.add("DragAndDrop", add("/DragAndDrop/DragAndDrop", new boolean
[] {false, false, false}));
+ map.add("DropDownMenu", add("/DropDownMenu/DropDownMenu", new
boolean [] {false, true, true}));
+ map.add("Effect", add("/Effect/Effect", new boolean [] {false,
false, false}));
+ map.add("Gmap", add("/Gmap/Gmap", new boolean [] {false, true,
false}));
+ map.add("InputNumberSlider",
add("/InputNumberSlider/InputNumberSlider", new boolean [] {false, true,
true}));
+ map.add("InputNumberSpinner",
add("/InputNumberSpinner/InputNumberSpinner", new boolean [] {false, true,
true}));
+ map.add("Insert", add("/Insert/Insert", new boolean [] {false,
true, false}));
+ map.add("Message", add("/Message/M essage", new boolean [] {false,
true, true}));
+ map.add("ModalPanel", add("/ModalPanel/ModalPanel", new boolean []
{false, true, true}));
+ map.add("Paint2D", add("/Paint2D/Paint2D", new boolean [] {false,
true, true}));
+ map.add("Panel", add("/Panel/Panel", new boolean [] {false, true,
true}));
+ map.add("PanelBar", add("/PanelBar/PanelBar", new boolean []
{false, true, true}));
+ map.add("PanelMenu", add("/PanelMenu/PanelMenu", new boolean []
{false, true, true}));
+ map.add("Separator", add("/Separator/Separator", new boolean []
{false, true, true}));
+ map.add("SimpleTogglePanel",
add("/SimpleTogglePanel/SimpleTogglePanel", new boolean [] {false, true,
true}));
+ map.add("Spacer", add("/Spacer/Spacer", new boolean [] {false,
true, true}));
+ map.add("SuggestionBox", add("/SuggestionBox/SuggestionBox", new
boolean [] {false, true, true}));
+ map.add("TabPanel", add("/TabPanel/TabPanel", new boolean []
{false, true, true}));
+ map.add("TogglePanel", add("/TogglePanel/TogglePanel", new boolean
[] {false, true, true}));
+ map.add("ToolBar", add("/ToolBar/ToolBar", new boolean [] {false,
true, false}));
+ map.add("Tooltip", add("/Tooltip/Tooltip", new boolean [] {false,
true, true}));
+ map.add("Tree", add("/Tree/Tree", new boolean [] {false, true,
false}));
+ map.add("VirtualEarth", add("/VirtualEarth/VirtualEarth", new
boolean [] {false, true, false}));
+ map.add("ScrollableDataTable",
add("/ScrollableDataTable/ScrollableDataTable", new boolean [] {false, true,
false}));
+ map.add("jQuery", add("/jQuery/jQuery", new boolean [] {false,
false, false}));
+ map.add("OrderingList", add("/OrderingList/OrderingList", new
boolean [] {false, true, true}));
+ map.add("DataDefinitionList",
add("/DataDefinitionList/DataDefinitionList", new boolean [] {false, true,
false}));
+ map.add("DataOrderedList", add("/DataOrderedList/DataOrderedList",
new boolean [] {false, true, false}));
+ map.add("ContextMenu", add("/ContextMenu/ContextMenu", new boolean
[] {false, true, false}));
+ map.add("ListShuttle", add("/ListShuttle/ListShuttle", new boolean
[] {false, true, true}));
+ map.add("ComponentControl",
add("/ComponentControl/ComponentControl", new boolean [] {false, false,
false}));
+ map.add("Columns", add("/Columns/Columns", new boolean [] {false,
true, false}));
+ map.add("PickList", add("/PickList/PickList", new boolean []
{false, true, false}));
+ map.add("Combobox", add("/Combobox/Combobox", new boolean []
{false, true, false}));
+ map.add("ProgressBar", add("/ProgressBar/ProgressBar", new boolean
[] {false, false, false}));
+ map.add("SortingAndFiltering",
add("/SortingAndFiltering/SortingAndFiltering", new boolean [] {false, false,
false}));
+ map.add("FileUpload", add("/FileUpload/FileUpload", new boolean []
{false, false, false}));
+ map.add("InplaceSelect", add("/InplaceSelect/InplaceSelect", new
boolean [] {false, true, false}));
+ map.add("InplaceInput", add("/InplaceInput/InplaceInput", new
boolean [] {false, true, false}));
+ map.add("Skinning", add("/Skinning/Skinning", new boolean []
{false, false, false}));
+ map.add("Validator", add("/Validator/Validator", new boolean []
{true, true, true}));
+ Iterator<String> iterator = map.getSet().iterator();
+ while(iterator.hasNext()){
+ list.add(new SelectItem(iterator.next()));
+ }
+ }
+
+ public String getSrc() {
+ return src;
+ }
+
+ public String getPathComponent() {
+ return map.get(src).get(0);
+ }
+
+ public String getDefaultPathComponent() {
+ return map.get(src).get(1);
+ }
+
+ public String getPathProperty() {
+ return map.get(src).get(2);
+ }
+
+ public String getPathStraightforward() {
+ return map.get(src).get(3);
+ }
+
+ public void setSrc(String src) {
+ this.src = src;
+ }
+
+ private ArrayList<String> add(String path, boolean [] arr){
+ ArrayList<String> list = new ArrayList<String>();
+ list.add(path + EXT);
+ if(arr[0]) list.add(path + "Default" + EXT); else
list.add("/pages/Blank/BlankDefault" + EXT);
+ if(arr[1]) list.add(path + "Property" + EXT); else
list.add("/pages/Blank/BlankProperty" + EXT);
+ if(arr[2]) list.add(path + "Straightforward" + EXT); else
list.add("/pages/Blank/BlankStraightforward" + EXT);
+ return list;
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public void setVersion(String version) {
+ this.version = version;
+ }
+
+ public List<SelectItem> getList(){
+ return list;
+ }
+
+ public String getSrcContainer() {
+ return srcContainer;
+ }
+
+ public void setSrcContainer(String srcContainer) {
+ this.srcContainer = srcContainer;
+ }
+
+ public String getPathComponentContainer() {
+ return map.get(srcContainer).get(0);
+ }
+
+ public List<SelectItem> getListContainer() {
+ Iterator<String> iterator = map.getSet().iterator();
+ List<SelectItem> l = new ArrayList<SelectItem>();
+ String str;
+ while(iterator.hasNext()){
+ str = iterator.next();
+ if(!str.equals(src))
+ l.add(new SelectItem(str));
+ }
+ return l;
+ }
+
+ public String invalidateSession(){
+ FacesContext context = FacesContext.getCurrentInstance();
+ System.out.println("RichBean.invalidateSession()");
+ return "RichFaces";
+ }
+}
Modified: trunk/test-applications/jsp/src/main/java/util/event/Event.java
===================================================================
--- trunk/test-applications/jsp/src/main/java/util/event/Event.java 2008-06-27 17:23:07
UTC (rev 9280)
+++ trunk/test-applications/jsp/src/main/java/util/event/Event.java 2008-06-28 07:04:33
UTC (rev 9281)
@@ -113,6 +113,7 @@
private String onbeforeshow;
private String opened;
private String onobjectchange;
+ private String onadd;
public String getOpened() {
return opened;
@@ -230,6 +231,7 @@
onviewactivation = "showEvent('onviewactivationInputID',
'onviewactivation work!')";
onbeforehide = "showEvent('onbeforehideInputID', 'onbeforehide
work!')";
onbeforeshow = "showEvent('onbeforeshowInputID', 'onbeforeshow
work!')";
+ onadd = "showEvent('onaddInputID', 'onadd work!')";
}
public String getOncontextmenu() {
@@ -1272,4 +1274,12 @@
this.onobjectchange = onobjectchange;
}
+ public String getOnadd() {
+ return onadd;
+ }
+
+ public void setOnadd(String onadd) {
+ this.onadd = onadd;
+ }
+
}
\ No newline at end of file
Modified: trunk/test-applications/jsp/src/main/webapp/FileUpload/FileUpload.jsp
===================================================================
--- trunk/test-applications/jsp/src/main/webapp/FileUpload/FileUpload.jsp 2008-06-27
17:23:07 UTC (rev 9280)
+++ trunk/test-applications/jsp/src/main/webapp/FileUpload/FileUpload.jsp 2008-06-28
07:04:33 UTC (rev 9281)
@@ -2,9 +2,18 @@
<%@ taglib
uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib
uri="http://richfaces.org/a4j" prefix="a4j"%>
<%@ taglib
uri="http://richfaces.org/rich" prefix="rich"%>
-
+<style>
+.addButton{
+color:white;
+background-color:red;
+}
+</style>
<f:subview id="FileUploadSubviewID">
<rich:fileUpload id="fileUploadID" status="a4jStatusID"
+ onadd="#{event.onadd}"
+ immediate="#{fileUpload.immediate}"
+ validator="fileUploadValidator"
+ ajaxSingle="#{fileUpload.ajaxSingle}"
uploadData="#{fileUpload.data}"
acceptedTypes="#{fileUpload.acceptedTypes}"
disabled="#{fileUpload.disabled}"
autoclear="#{fileUpload.autoclear}"
@@ -47,13 +56,14 @@
progressLabel="progress" sizeErrorLabel="sizeError"
stopControlLabel="stopControl"
stopEntryControlLabel="stopEntryControl"
- transferErrorLabel="transferError"
uploadControlLabel="uploadControl">
+ transferErrorLabel="transferError"
uploadControlLabel="uploadControl"
+ allowFlash="#{fileUpload.allowFlash}">
<f:facet name="label">
<h:outputText value="{_KB}KB from {KB}KB uploaded :[ {mm}:{ss}
]"></h:outputText>
</f:facet>
<f:facet name="header">
<h:outputText value="some text"></h:outputText>
- </f:facet>
+ </f:facet>
</rich:fileUpload>
<h:panelGrid columns="2">
@@ -122,8 +132,26 @@
<a4j:support event="onchange"
reRender="fileUploadID"></a4j:support>
</h:selectBooleanCheckbox>
+ <h:outputText value="ajaxSingle"></h:outputText>
+ <h:selectBooleanCheckbox value="#{fileUpload.ajaxSingle}">
+ <a4j:support event="onchange"
reRender="fileUploadID"></a4j:support>
+ </h:selectBooleanCheckbox>
+
+ <h:outputText value="immediate"></h:outputText>
+ <h:selectBooleanCheckbox value="#{fileUpload.immediate}">
+ <a4j:support event="onchange"
reRender="fileUploadID"></a4j:support>
+ </h:selectBooleanCheckbox>
+
<h:outputText value="Uploaded data:"></h:outputText>
<h:outputText value="#{fileUpload.changedLabel}"></h:outputText>
+
+ <h:outputText value="allowFlash" />
+ <h:selectOneRadio value="#{fileUpload.allowFlash}">
+ <f:selectItem itemValue="true" itemLabel="true"/>
+ <f:selectItem itemValue="false" itemLabel="false"/>
+ <f:selectItem itemValue="auto" itemLabel="auto"/>
+ <a4j:support event="onchange"
reRender="fileUploadID"></a4j:support>
+ </h:selectOneRadio>
<a4j:commandLink
onclick="$('formID:FileUploadSubviewID:fileUploadID').component.enable()"
Modified: trunk/test-applications/jsp/src/main/webapp/ModalPanel/ModalPanel.jsp
===================================================================
--- trunk/test-applications/jsp/src/main/webapp/ModalPanel/ModalPanel.jsp 2008-06-27
17:23:07 UTC (rev 9280)
+++ trunk/test-applications/jsp/src/main/webapp/ModalPanel/ModalPanel.jsp 2008-06-28
07:04:33 UTC (rev 9281)
@@ -38,7 +38,7 @@
onmaskmouseout="#{event.onmaskmouseout}"
onmaskmouseover="#{event.onmaskmouseover}"
onmaskmouseup="#{event.onmaskmouseup}" onmove="#{event.onmove}"
- onresize="#{event.onresize}" onshow="#{event.onshow}"
+ onresize="#{event.onresize}" onshow="#{event.onshow}"
<f:facet name="header">
<h:outputText value="Heder goes here..." />
Modified: trunk/test-applications/jsp/src/main/webapp/WEB-INF/faces-config-FileUpload.xml
===================================================================
---
trunk/test-applications/jsp/src/main/webapp/WEB-INF/faces-config-FileUpload.xml 2008-06-27
17:23:07 UTC (rev 9280)
+++
trunk/test-applications/jsp/src/main/webapp/WEB-INF/faces-config-FileUpload.xml 2008-06-28
07:04:33 UTC (rev 9281)
@@ -7,4 +7,8 @@
<managed-bean-class>fileUpload.FileUpload</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
+ <validator>
+ <validator-id>fileUploadValidator</validator-id>
+ <validator-class>fileUpload.FileUploadValidator</validator-class>
+ </validator>
</faces-config>
Modified: trunk/test-applications/jsp/src/main/webapp/pages/Action/EventInfo.jsp
===================================================================
--- trunk/test-applications/jsp/src/main/webapp/pages/Action/EventInfo.jsp 2008-06-27
17:23:07 UTC (rev 9280)
+++ trunk/test-applications/jsp/src/main/webapp/pages/Action/EventInfo.jsp 2008-06-28
07:04:33 UTC (rev 9281)
@@ -109,5 +109,6 @@
<f:verbatim><div style="position: relative"><input
id="onbeforeshowInputID" type="hidden" value="don't
work!" size="42" /></div></f:verbatim>
<f:verbatim><div style="position: relative"><input
id="openedInputID" type="hidden" value="don't work!"
size="42" /></div></f:verbatim>
<f:verbatim><div style="position: relative"><input
id="onobjectchangeInputID" type="hidden" value="don't
work!" size="42" /></div></f:verbatim>
+ <f:verbatim><div style="position: relative"><input
id="onaddInputID" type="hidden" value="don't work!"
size="42" /></div></f:verbatim>
</f:subview>