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

      Werner Punz created issue -
      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!
      Werner Punz made changes -
      Field Original Value New Value
      Comment [ Ok the base mechanism is fine but generally within our code structures this does not entirely work out.

      What has to be chained is
      chain(userEvent, behaviors, rendererEvent)

      we have to integrate deeper, unfortunately, and also if no behaviors are attached it would make sense to use the chaining.


      ]
      Leonardo Uribe made changes -
      Component/s JSR-314 [ 12312453 ]
      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
      Leonardo Uribe made changes -
      Status Open [ 1 ] Resolved [ 5 ]
      Assignee Leonardo Uribe [ lu4242 ]
      Fix Version/s 2.0.0 [ 12314890 ]
      Resolution Fixed [ 1 ]
      Leonardo Uribe made changes -
      Status Resolved [ 5 ] Closed [ 6 ]

        People

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

          Dates

          • Created:
            Updated:
            Resolved:

            Development