Uploaded image for project: 'Nuxeo Platform'
  1. Nuxeo Platform
  2. NXP-10566

Handle standard JSF expressions in actions

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 5.7.3
    • Component/s: Seam / JSF UI, Web Common
    • Tags:
    • Backlog priority:
      600
    • Impact type:
      API change
    • Upgrade notes:
      Hide

      ActionContext class depending on jexl was changed into an interface.
      A basic ELActionContext implementation with a set of default resolvers is now available for action filter resolution outside of a JSF/Seam context, another JSFActionContext implementation is also available inside a JSF/Seam context.
      Both need an ELContext and ExpressionFactory implementations, provided by the caller.

      Also the reference EL API is now org.apache.tomcat/tomcat-el-api instead of javax.el/el-api and the reference EL implementation is now org.jboss.el/jboss-el instead of others (commons-el, juel-impl, etc...) as jboss-el is the more expressive implementation.

      Sample JSF/Seam usage:

      public ActionContext createActionContext() {
          FacesContext faces = FacesContext.getCurrentInstance();
          if (faces == null) {
              throw new IllegalArgumentException("Faces context is null");
          }
          ActionContext ctx = new JSFActionContext(faces.getELContext(),
                  faces.getApplication().getExpressionFactory());
          ctx.setCurrentDocument(navigationContext.getCurrentDocument());
          ctx.setDocumentManager(documentManager);
          ctx.setCurrentPrincipal(currentNuxeoPrincipal);
          ctx.putLocalVariable("SeamContext", new SeamContextHelper());
          return ctx;
      }
      

      Alternative sample JSF/Seam usage:

      <nxu:set var="actionContext" value="#{actionContextProvider.createActionContext()}" cache="true">
      <nxu:set var="foo" value="#{actionContext.putLocalVariable('contentView', contentView)}" cache="true" />
      <nxu:set var="foo" value="#{actionContext.putLocalVariable('selectedDocuments', documentsListsManager.getWorkingList(contentView.selectionListName))}" cache="true" />
      <nxu:set var="actions" value="#{webActions.getUnfiltredActionsList(actionCategory, actionContext)}" cache="true">
        <c:if test="#{not status.first and not empty actions}">
          <br />
        </c:if>
        <nxl:widgetType name="actions"
          mode="#{widget.mode}"
          widgetName="cvButton"
          label=""
          actions="#{actions}"
          overallDisplay="horizontal_block"
          actionsDisplay="buttons"
          ignoreTemplateProperty="true"
          addForm="true" />
      </nxu:set>
      </nxu:set>
      

      Sample EL usage:

      protected ActionContext getActionContext(DocumentModel currentDocument)
              throws Exception {
          ActionContext actionContext = new ELActionContext(
                  new ExpressionContext(), new ExpressionFactoryImpl());
          actionContext.setDocumentManager(session);
          actionContext.setCurrentPrincipal((NuxeoPrincipal) session.getPrincipal());
          if (currentDocument != null) {
              actionContext.setCurrentDocument(currentDocument);
          } else {
              actionContext.setCurrentDocument(getCurrentDocumentFromContext());
          }
          actionContext.putAllLocalVariables(ctx);
          return actionContext;
      }
      
      Show
      ActionContext class depending on jexl was changed into an interface. A basic ELActionContext implementation with a set of default resolvers is now available for action filter resolution outside of a JSF/Seam context, another JSFActionContext implementation is also available inside a JSF/Seam context. Both need an ELContext and ExpressionFactory implementations, provided by the caller. Also the reference EL API is now org.apache.tomcat/tomcat-el-api instead of javax.el/el-api and the reference EL implementation is now org.jboss.el/jboss-el instead of others (commons-el, juel-impl, etc...) as jboss-el is the more expressive implementation. Sample JSF/Seam usage: public ActionContext createActionContext() { FacesContext faces = FacesContext.getCurrentInstance(); if (faces == null ) { throw new IllegalArgumentException( "Faces context is null " ); } ActionContext ctx = new JSFActionContext(faces.getELContext(), faces.getApplication().getExpressionFactory()); ctx.setCurrentDocument(navigationContext.getCurrentDocument()); ctx.setDocumentManager(documentManager); ctx.setCurrentPrincipal(currentNuxeoPrincipal); ctx.putLocalVariable( "SeamContext" , new SeamContextHelper()); return ctx; } Alternative sample JSF/Seam usage: <nxu:set var = "actionContext" value= "#{actionContextProvider.createActionContext()}" cache= " true " > <nxu:set var = "foo" value= "#{actionContext.putLocalVariable( 'contentView' , contentView)}" cache= " true " /> <nxu:set var = "foo" value= "#{actionContext.putLocalVariable( 'selectedDocuments' , documentsListsManager.getWorkingList(contentView.selectionListName))}" cache= " true " /> <nxu:set var = "actions" value= "#{webActions.getUnfiltredActionsList(actionCategory, actionContext)}" cache= " true " > <c: if test= "#{not status.first and not empty actions}" > <br /> </c: if > <nxl:widgetType name= "actions" mode= "#{widget.mode}" widgetName= "cvButton" label="" actions= "#{actions}" overallDisplay= "horizontal_block" actionsDisplay= "buttons" ignoreTemplateProperty= " true " addForm= " true " /> </nxu:set> </nxu:set> Sample EL usage: protected ActionContext getActionContext(DocumentModel currentDocument) throws Exception { ActionContext actionContext = new ELActionContext( new ExpressionContext(), new ExpressionFactoryImpl()); actionContext.setDocumentManager(session); actionContext.setCurrentPrincipal((NuxeoPrincipal) session.getPrincipal()); if (currentDocument != null ) { actionContext.setCurrentDocument(currentDocument); } else { actionContext.setCurrentDocument(getCurrentDocumentFromContext()); } actionContext.putAllLocalVariables(ctx); return actionContext; }

      Description

      Currently a hack makes it possible to access to the Seam context from actions, but it does not make it possible to use standard JSF EL expressions.

      A first fix would be to move the conditions resolution from the filter to the context, so that the context can be adapted depending on the caller (JSF context when actions retrieved from JSF, and compat JEXL context for others, or when expression is pure JEXL).

      Also this would be an opportunity to generate a different context depending on if actions are resolved against current document, or document in a list for instance (so that we can have toolbars in content views listings)

        Attachments

          Issue Links

          There are no Sub-Tasks for this issue.

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - 3 days
                  3d
                  Remaining:
                  Remaining Estimate - 3 days
                  3d
                  Logged:
                  Time Spent - Not Specified
                  Not Specified