Ajax picker improvements and fixes, support for mimetype restriction list in the Ajax File picker.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@7751 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Kevin Roast
2008-01-04 11:38:44 +00:00
parent 0027d6d0ad
commit b7965af43d
10 changed files with 266 additions and 19 deletions

View File

@@ -49,6 +49,14 @@ import org.alfresco.web.ui.common.Utils;
import org.springframework.web.jsf.FacesContextUtils;
/**
* Base class for the JSP components representing Ajax object pickers.
*
* Handles the JSF lifecycle for the Ajax component. The Ajax calls themselves
* are processed via the class <code>org.alfresco.web.bean.ajax.PickerBean</code>.
*
* The derived components are only responsible for specifing the ajax service call
* to make, plus any defaults for icons etc.
*
* @author Kevin Roast
*/
public abstract class BaseAjaxItemPicker extends UIInput
@@ -121,7 +129,7 @@ public abstract class BaseAjaxItemPicker extends UIInput
this.initialSelectionId,
this.disabled,
this.height};
return (values);
return values;
}
/**
@@ -268,6 +276,12 @@ public abstract class BaseAjaxItemPicker extends UIInput
{
out.write(" window." + objId + ".setSelectedItems('" + selectedItems + "');");
}
// write any addition custom request attributes required by specific picker implementations
String requestProps = getRequestAttributes();
if (requestProps != null)
{
out.write(" window." + objId + ".setRequestAttributes('" + requestProps + "');");
}
out.write("}");
out.write("window.addEvent('domready', init" + divId + ");");
out.write("</script>");
@@ -371,6 +385,14 @@ public abstract class BaseAjaxItemPicker extends UIInput
*/
protected abstract String getDefaultIcon();
/**
* @return custom request properties optional for some specific picker implementations
*/
protected String getRequestAttributes()
{
return null;
}
// ------------------------------------------------------------------------------
// Strongly typed component property accessors

View File

@@ -25,6 +25,8 @@
package org.alfresco.web.ui.repo.component;
/**
* JSF Ajax object picker for navigating through and selecting categories.
*
* @author Kevin Roast
*/
public class UIAjaxCategoryPicker extends BaseAjaxItemPicker

View File

@@ -24,16 +24,51 @@
*/
package org.alfresco.web.ui.repo.component;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import javax.faces.context.FacesContext;
import javax.faces.el.ValueBinding;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.web.ui.common.Utils;
/**
* JSF Ajax object picker for navigating through folders and selecting a file.
*
* @author Kevin Roast
*/
public class UIAjaxFilePicker extends BaseAjaxItemPicker
{
/** list of mimetypes to restrict the available file list */
private String mimetypes = null;
@Override
public String getFamily()
{
return "org.alfresco.faces.AjaxFilePicker";
}
/**
* @see javax.faces.component.StateHolder#restoreState(javax.faces.context.FacesContext, java.lang.Object)
*/
public void restoreState(FacesContext context, Object state)
{
Object values[] = (Object[])state;
super.restoreState(context, values[0]);
this.mimetypes = (String)values[1];
}
/**
* @see javax.faces.component.StateHolder#saveState(javax.faces.context.FacesContext)
*/
public Object saveState(FacesContext context)
{
Object values[] = new Object[] {
super.saveState(context),
this.mimetypes};
return values;
}
@Override
protected String getServiceCall()
@@ -47,4 +82,51 @@ public class UIAjaxFilePicker extends BaseAjaxItemPicker
// none required - we always return an icon name in the service call
return null;
}
@Override
protected String getRequestAttributes()
{
String mimetypes = getMimetypes();
if (mimetypes != null)
{
try
{
return "mimetypes=" + URLEncoder.encode(mimetypes, "UTF-8");
}
catch (UnsupportedEncodingException e)
{
throw new AlfrescoRuntimeException("Unsupported encoding.", e);
}
}
else
{
return null;
}
}
// ------------------------------------------------------------------------------
// Strongly typed component property accessors
/**
* @return Returns the mimetypes to restrict the file list.
*/
public String getMimetypes()
{
ValueBinding vb = getValueBinding("mimetypes");
if (vb != null)
{
this.mimetypes = (String)vb.getValue(getFacesContext());
}
return this.mimetypes;
}
/**
* @param mimetypes The mimetypes restriction list to set.
*/
public void setMimetypes(String mimetypes)
{
this.mimetypes = mimetypes;
}
}

View File

@@ -25,6 +25,8 @@
package org.alfresco.web.ui.repo.component;
/**
* JSF Ajax object picker for navigating through and selecting folders.
*
* @author Kevin Roast
*/
public class UIAjaxFolderPicker extends BaseAjaxItemPicker