Details

    • Type: Sub-task Sub-task
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.0.0
    • Component/s: JSR-314
    • Labels:
      None

      Activity

      Hide
      Werner Punz added a comment - - edited

      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!

      Show
      Werner Punz added a comment - - edited 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!
      Hide
      Leonardo Uribe added a comment -

      This was also solved on a previous commit on MYFACES-2350

      Show
      Leonardo Uribe added a comment - This was also solved on a previous commit on MYFACES-2350

        People

        • Assignee:
          Leonardo Uribe
          Reporter:
          Werner Punz
        • Votes:
          0 Vote for this issue
          Watchers:
          0 Start watching this issue

          Dates

          • Created:
            Updated:
            Resolved:

            Development