WebScript Runtime response/url model extended to support output of client-side webscript url generation function.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5902 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Kevin Roast
2007-06-09 17:03:11 +00:00
parent bb2536fcf5
commit a3c59244d1
18 changed files with 172 additions and 44 deletions

View File

@@ -105,11 +105,12 @@ public class WebScriptJSFResponse implements WebScriptResponse
return buf.toString();
}
/* (non-Javadoc)
/**
* @see org.alfresco.web.scripts.WebScriptResponse#reset()
*/
public void reset()
{
// nothing to do
}
/**
@@ -128,11 +129,12 @@ public class WebScriptJSFResponse implements WebScriptResponse
return fc.getResponseWriter();
}
/* (non-Javadoc)
/**
* @see org.alfresco.web.scripts.WebScriptResponse#setStatus(int)
*/
public void setStatus(int status)
{
// makes no sense in the JSF env
}
/**
@@ -142,5 +144,32 @@ public class WebScriptJSFResponse implements WebScriptResponse
{
// Alfresco JSF framework only supports the default of text-html
}
/* (non-Javadoc)
* @see org.alfresco.web.scripts.WebScriptResponse#getEncodeScriptUrlFunction(java.lang.String)
*/
public String getEncodeScriptUrlFunction(String name)
{
UIForm form = Utils.getParentForm(fc, component);
if (form == null)
{
throw new IllegalStateException("Must nest components inside UIForm to generate form submit!");
}
String fieldId = component.getClientId(fc);
String formClientId = form.getClientId(fc);
HtmlFormRendererBase.addHiddenCommandParameter(fc, form, fieldId);
String func = ENCODE_FUNCTION.replace("$name$", name);
func = func.replace("$formClientId$", formClientId);
func = func.replace("$fieldId$", fieldId);
return Utils.encodeJavascript(func);
}
private static final String ENCODE_FUNCTION =
"{ $name$: function(url) {" +
" var out = '';" +
" out += \"#\\\" onclick=\\\"document.forms['$formClientId$']['$fieldId$'].value='\";" +
" out += escape(url);" +
" out += \"';document.forms['$formClientId$'].submit();return false;\";" +
" return out; } }";
}