[
https://issues.apache.org/jira/browse/MYFACES-2352?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12754953#action_12754953
]
Werner Punz edited comment on MYFACES-2352 at 9/14/09 6:22 AM:
---------------------------------------------------------------
Ok here we have following to do, we have to add a method which resolved the
attached behaviors in a chain,
similar to that one (please review first, I dont want to do an integration
before having everything reviewed)
/**
* builds the chained behavior script which then can be reused
* in following order by the other script building parts
*
* user defined event handling script
* behavior script
* renderer default script
*
* @param eventName event name ("onclick" etc...)
* @param uiComponent the component which has the attachement (or
should have)
* @param facesContext the facesContext
* @param params params map of params which have to be dragged into
the request
* @return a string representation of the javascripts for the attached
event behavior, an empty string if none is present
*/
public static String getClientBehaviorScript(String eventName,
UIComponent uiComponent, FacesContext facesContext, Map<String, String>
params) {
if (!(uiComponent instanceof ClientBehaviorHolder)) {
return "";
}
Map<String, List<ClientBehavior>> clientBehaviors = null;
if (uiComponent instanceof ClientBehaviorHolder) {
clientBehaviors = ((ClientBehaviorHolder)
uiComponent).getClientBehaviors();
}
ExternalContext externalContext = facesContext.getExternalContext();
boolean renderClientBehavior =
JavascriptUtils.isJavascriptAllowed(externalContext) && clientBehaviors != null
&& clientBehaviors.size() > 0;
if (!renderClientBehavior) {
return "";
}
List<ClientBehavior> attachedEventBehaviors =
clientBehaviors.get(eventName);
if (attachedEventBehaviors == null || attachedEventBehaviors.size()
== 0) {
return "";
}
List<ClientBehaviorContext.Parameter> paramList = new
ArrayList<ClientBehaviorContext.Parameter>(params.size());
for (Map.Entry<String, String> paramEntry : params.entrySet()) {
paramList.add(new
ClientBehaviorContext.Parameter(paramEntry.getKey(), paramEntry.getValue()));
}
ClientBehaviorContext context =
ClientBehaviorContext.createClientBehaviorContext(facesContext, uiComponent,
eventName, uiComponent.getClientId(facesContext), paramList);
StringBuilder behaviorHandlers = new
StringBuilder(attachedEventBehaviors.size() * 20);
Iterator<ClientBehavior> clientIterator =
attachedEventBehaviors.iterator();
while (clientIterator.hasNext()) {
//either strings or functions, but I assume string is more
appropriate since it allows access to the
//origin as this!
behaviorHandlers.append("'" +
clientIterator.next().getScript(context).replaceAll("'", "\\'") + "'");
if (clientIterator.hasNext()) {
behaviorHandlers.append(", ");
}
}
return behaviorHandlers.toString();
}
public static String getChain(String eventName, UIComponent uiComponent,
FacesContext facesContext, String userEventCode, String serverEventCode,
Map<String, String> params) {
ExternalContext externalContext = facesContext.getExternalContext();
boolean renderCode =
JavascriptUtils.isJavascriptAllowed(externalContext);
if(!renderCode) {
return "";
}
List <String> finalParams = new ArrayList<String>(3);
if(userEventCode != null && !userEventCode.trim().equals("")) {
finalParams.add(userEventCode);
}
String behaviorCode =
getClientBehaviorScript(eventName,uiComponent,facesContext,params);
if(behaviorCode != null && !behaviorCode.trim().equals("")) {
finalParams.add(behaviorCode);
}
if(serverEventCode != null && !serverEventCode.trim().equals("")) {
finalParams.add(userEventCode);
}
Iterator<String> it = finalParams.iterator();
StringBuilder retVal = new StringBuilder();
retVal.append("jsf.util.chain(document.getElementById('"+uiComponent.getClientId(facesContext)
+"'), event,");
while(it.hasNext()) {
retVal.append(it.next());
while(it.hasNext()) {
retVal.append(", ");
}
}
retVal.append(");");
return retVal.toString();
}
Then in our HTMLRenderingUtils class we have to add this function to the
attribute rendering mechanism and in case of the HTMLCommandButton
base class we also have to add it to the createSubmit part!
was (Author: werpu):
Ok here we have following to do, we have to add a method which resolved the
attached behaviors in a chain,
similar to that one (please review first, I dont want to do an integration
before having everything reviewed)
/**
* builds the chained behavior script which then can be reused
* in following order by the other script building parts
*
* user defined event handling script
* behavior script
* renderer default script
*
* @param eventName event name ("onclick" etc...)
* @param uiComponent the component which has the attachement (or
should have)
* @param facesContext the facesContext
* @param params params map of params which have to be dragged into
the request
* @return a string representation of the javascripts for the attached
event behavior, an empty string if none is present
*/
public static String getClientBehaviorScript(String eventName,
UIComponent uiComponent, FacesContext facesContext, Map<String, String> params)
{
if (!(uiComponent instanceof ClientBehaviorHolder)) {
return "";
}
Map<String, List<ClientBehavior>> clientBehaviors = null;
if (uiComponent instanceof ClientBehaviorHolder) {
clientBehaviors = ((ClientBehaviorHolder)
uiComponent).getClientBehaviors();
}
ExternalContext externalContext = facesContext.getExternalContext();
boolean renderClientBehavior =
JavascriptUtils.isJavascriptAllowed(externalContext) && clientBehaviors != null
&& clientBehaviors.size() > 0;
if (!renderClientBehavior) {
return "";
}
List<ClientBehavior> attachedEventBehaviors =
clientBehaviors.get(eventName);
if (attachedEventBehaviors == null || attachedEventBehaviors.size()
== 0) {
return "";
}
List<ClientBehaviorContext.Parameter> paramList = new
ArrayList<ClientBehaviorContext.Parameter>(params.size());
for (Map.Entry<String, String> paramEntry : params.entrySet()) {
paramList.add(new
ClientBehaviorContext.Parameter(paramEntry.getKey(), paramEntry.getValue()));
}
ClientBehaviorContext context =
ClientBehaviorContext.createClientBehaviorContext(facesContext, uiComponent,
eventName, uiComponent.getClientId(facesContext), paramList);
//todo try to enforce an introspection call here, because we cannot
really only rely on the attributes
//what if the event name is set dynamically from the outside via set?
String userEvent = (String)
uiComponent.getAttributes().get(eventName);
StringBuilder behaviorHandlers = new
StringBuilder(attachedEventBehaviors.size() * 20);
behaviorHandlers.append("jsf.util.chain(");
behaviorHandlers.append("this, event");
behaviorHandlers.append(", ");
if (userEvent != null && !userEvent.trim().equals("")) {
//user event first
behaviorHandlers.append("'" + userEvent.replaceAll("'", "\\'") +
"'");
}
Iterator<ClientBehavior> clientIterator =
attachedEventBehaviors.iterator();
while (clientIterator.hasNext()) {
if (clientIterator.hasNext()) {
behaviorHandlers.append(", ");
}
//either strings or functions, but I assume string is more
appropriate since it allows access to the
//origin as this!
behaviorHandlers.append("'" +
clientIterator.next().getScript(context).replaceAll("'", "\\'") + "'");
}
behaviorHandlers.append(");");
return behaviorHandlers.toString();
}
Then in our HTMLRenderingUtils class we have to add this function to the
attribute rendering mechanism and in case of the HTMLCommandButton
base class we also have to add it to the createSubmit part!
> Add the parameter handling for UICommand
> ----------------------------------------
>
> Key: MYFACES-2352
> URL: https://issues.apache.org/jira/browse/MYFACES-2352
> Project: MyFaces Core
> Issue Type: Sub-task
> Reporter: Werner Punz
>
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.