cancel
Showing results for 
Search instead for 
Did you mean: 

FacesContext instance is null in webscript

jnjp28
Champ in-the-making
Champ in-the-making
Hi,

i have a problem with the use of FacesConext in a webscript (extends DeclarativeWebScript).
When i try to get an instance of FacesConext i have this error : "FacesContext must no be null"

This is the code :

FacesContext context = FacesContext.getCurrentInstance();
Config config = Application.getConfigService(context).getConfig(node);
ActionsConfigElement actionConfig = (ActionsConfigElement)config.getConfigElement(ActionsConfigElement.CONFIG_ELEMENT_ID);
ActionGroup actionGroup = actionConfig.getActionGroup("template");

Thanks for your replies

Best regards
5 REPLIES 5

openpj
Elite Collaborator
Elite Collaborator
But why you need to get the FacesContext?
The FacesContext is dedicated to the Alfresco Web Client, you don't need to get this context. And you can't I think…
What are the resources that you want to use for your case?

Maybe you want to get the Service Registry of Alfresco…

jnjp28
Champ in-the-making
Champ in-the-making
Thanks for your reply,

ConfigService is not a public service, and it's not in ServiceRegistry.

Moreover i tried to inject configService with Spring but i don't know what implementation i have to use

Regards

jnjp28
Champ in-the-making
Champ in-the-making
I will try the "webClientConfigService"

jnjp28
Champ in-the-making
Champ in-the-making
Hi,

i found my problem. The last developer wanted to create a dynamique action group with a webscript :


protected List<Map<String, String>> buildActionGroup(FacesContext context, ActionsConfigElement config, ActionGroup actionGroup, Node node) throws UnsupportedEncodingException {
     
     
      javax.faces.application.Application facesApp = context.getApplication();
      ResourceBundle messages = Application.getBundle(context);

      List<Map<String, String>> actions = new ArrayList<Map<String, String>>();
      for (String actionId : actionGroup)
       {
          if (logger.isDebugEnabled())
             logger.debug("—processing ActionDefinition: " + actionId);
         
          ActionDefinition actionDef = config.getActionDefinition(actionId);
          if (actionDef == null)
          {
             throw new AlfrescoRuntimeException("Unable to find configured ActionDefinition Id: " + actionId);
          }
         
          // build a permissions evaluator component to wrap the actionlink
          PermissionEvaluator permEval = null;
          List<String> allow = actionDef.getAllowPermissions();
          if (allow != null && allow.size() != 0)
          {
             // found some permissions to test
             permEval = (PermissionEvaluator)facesApp.createComponent(UIActions.COMPONENT_PERMISSIONEVAL);
             String condition = allow.get(0);
             if (allow.size() != 1)
             {
                for (int i=1; i<allow.size(); i++)
                {
                   condition += "," + allow.get(i);
                }
             }
             permEval.setAllow(condition);
          }
          List<String> deny = actionDef.getDenyPermissions();
          if (deny != null && deny.size() != 0)
          {
             if (permEval == null)
             {
                permEval = (PermissionEvaluator)facesApp.createComponent(UIActions.COMPONENT_PERMISSIONEVAL);
             }
             String condition = deny.get(0);
             if (deny.size() != 1)
             {
                for (int i=1; i<deny.size(); i++)
                {
                   condition += "," + deny.get(i);
                }
             }
             permEval.setDeny(condition);
          }

          // Evaluate permissions
          if (permEval != null) {
             // Set context node
             permEval.setValue(node);
             if (! permEval.evaluate()) {
                // Skip this action
                continue;
             }
          }

          // now prepare any code based evaluators that may be present
          if (actionDef.Evaluator != null)
          {
             ActionInstanceEvaluator evaluator = (ActionInstanceEvaluator)facesApp.createComponent(UIActions.COMPONENT_ACTIONEVAL);
             evaluator.setEvaluator(actionDef.Evaluator);
             // Set context node
            evaluator.setValue(node);
            
             if (! evaluator.evaluate()) {
                // Skip this action
                continue;
             }
          }
         
          Map<String, String> action = new HashMap<String, String>();

          // Build href
          StringBuilder scriptHref = new StringBuilder(100);
          scriptHref.append("/command/script/execute");
          if (actionDef.Script.charAt(0) == '/') {
             // found a Path - encode it as a URL argument
             scriptHref.append("?scriptPath=");
             scriptHref.append(Utils.replace(URLEncoder.encode(actionDef.Script, "UTF-8"), "+", "%20"));
          }
          action.put("href", scriptHref.toString());
          action.put("target", actionDef.Target);
          action.put("image", actionDef.Image);
          if (actionDef.TooltipMsg != null) {
             action.put("tooltip", Application.getMessage(context, actionDef.TooltipMsg));
          } else if (actionDef.Tooltip != null) {
             action.put("tooltip", actionDef.Tooltip);
          }
          if (actionDef.LabelMsg != null) {
             action.put("label", Application.getMessage(context, actionDef.LabelMsg));
          } else if (actionDef.Label != null) {
             action.put("label", actionDef.Label);
          }
         
          actions.add(action);
       }
     
      return actions;
   }

To create an action group we must have a FacesContext. What is the bestPractice to create an action group with a webscript ?

Regards

daave
Champ in-the-making
Champ in-the-making
I just wanted to know if your problem was solved or not……?
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.