Can a User Action, Custom EL expression handle a compound Boolean of more than two clauses?

I have the following custom EL expression in a user Action:

${layoutValue.currentLifeCycleState != 'SupRequest1' && layoutValue.currentLifeCycleState != 'SupRequest2' && layoutValue.currentLifeCycleState != 'Pause'}

I have two documents one in the SupRequest1 state and one in the Start state.

The button associated with this user action is enabled in both documents. Expected result is: Button is missing from document in SupRequest1 state and present in document in Start state.

Am I missing a logic error?

Will the above expression be completely parsed by Nuxeo?

BTW a compound boolean expression in another user action with only two clauses seems to work correctly!

Also if I use parentheses, to enclose each clause, in the expression the Nuxeo parser get very upset and cannot find the first && (AND) operator.

See Entry entitled: User Action: Current document has life cycle ……NOT!? as a reference.

0 votes

3 answers

3097 views

ANSWER



In a user action, you do not have access to the layout context as it's unrelated. So layoutValue variable will always resolve to null here.

You can however use EL expressions using “document” or “currentDocument” (this one since 5.5), other variables available in the context are “principal” or “currentUser” (this one also since 5.5).

You can also call a custom method from a Seam component, but the Seam component has to be the first item of the expression to be resolved correctly, so something like #{clipboardActions.canPasteFromClipboard} will work, but not something like #{clipboardActions.canPasteFromClipboard and clipboardActions.canDoOtherStuff}.

We do know that this can be confusing for users, hopefully we'll improve that in the future…

1 votes



Here is an example:

In the Nuxeo IDE I created a Seam Controller Bean named enables using class EnablesBean. The bean has many methods each returning a boolean after it tests what ever I need to test. Most of the code below is automatically generated by the IDE. A sample method is show below, make as many methods as you need for various enables. I changed the Scope to Event which helped with some issues I had, change Scope as required to make it work appropriately for your code..

Start Code ***

package org.nuxeo.zaxis.bes;

import java.io.Serializable; import java.text.SimpleDateFormat; import java.util.GregorianCalendar; import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jboss.seam.ScopeType; import org.jboss.seam.annotations.Factory; import org.jboss.seam.annotations.In; import org.jboss.seam.annotations.Name; import org.jboss.seam.annotations.Scope; import org.nuxeo.ecm.core.api.ClientException; import org.nuxeo.ecm.core.api.CoreSession; import org.nuxeo.ecm.core.api.DocumentModel; import org.nuxeo.ecm.core.api.DocumentModelList; import org.nuxeo.ecm.core.api.NuxeoPrincipal; import org.nuxeo.ecm.core.api.model.PropertyException; import org.nuxeo.ecm.platform.ui.web.invalidations.AutomaticDocumentBasedInvalidation; import org.nuxeo.ecm.platform.ui.web.invalidations.DocumentContextBoundActionBean; import org.nuxeo.ecm.webapp.documentsLists.DocumentsListsManager;

/**

  • Code skeleton for a Bean that is controlling
  • a new Tab like action (a xhtml fragment) *
  • This can be used :
    • to display additional informations about a document
    • to provide a screen that allow to update the document *
  • The bean is by default Conversation scoped
  • so that :
    • if you have expensive computation it will be run only when needed
    • you can manage view/update/view cycle *
  • All state should be managed as member variables of the beans.
  • The default invalidation policy is to reset the state when
  • the currentDocument changes. * */

//The Bean is registered here! //This was automatically generated by the Nuxeo IDE

@Name(“enables”) @Scope(ScopeType.EVENT) @AutomaticDocumentBasedInvalidation public class EnablesBean extends DocumentContextBoundActionBean implements Serializable {

private static final long serialVersionUID = 1L;

private static final Log log = LogFactory.getLog(besEnablesBean.class);

public boolean sampleTest(){
    boolean result = false;

// DO your check here and set result variable as required. You can // make the check as simple or as complicated as you'd like.

    return result;
}

}

End Code*

Add a EL expression in the filter in the Action, Content View, etc, like below (I use Studio but I'm sure it will work in .XML):

${enables.sampleTest()}

That's about it.

Karl

0 votes



Thanks a lot its working :D
11/26/2012


For my solution I have written a custom boolean Seam method which contains all the logic needed. The method returns a boolean so I can use a single EL expression eg. #{mymethod}, this seems to work.

0 votes



I followed your steps and created a seam controller bean with a method which returns a boolean. Now how do invoke this method from a custom EL.? Where do i register this seam bean?
11/26/2012