0

i want to validate multiple tasks in Alfresco share. I have added a checkbox per line in the task interface and a button to validate. As it can take a while to validate my tasks i would like to put a progress bar to inform how many tasks have been validated yet.

I made a web script to maintain a kind of counter, so that i can update my progress bar every x second. What would be the best solution to store that information to retrieve it in alfresco share ? I tried to store my variable in session but i didn't succeed.

Can someone tell me how to do ?

Thx in advance

EDIT here is what i've tried

public class HttpSessionHelper extends BaseScopableProcessorExtension {

public void setInSession(String paramName, String paramValue) {
    HttpSession session = ServletUtil.getSession();
    session.setAttribute(paramName, paramValue);
}

public String getFromSession(String paramName) {
    HttpSession session = ServletUtil.getSession();

    Object paramValue = session.getAttribute(paramName);
    if (paramValue != null) {
        return paramValue.toString();
    } else {
        return null;
    }
}
}

Bean definition

<bean id="tasksProgression" parent="baseJavaScriptExtension" class="com.test.HttpSessionHelper">
  <property name="extensionName">
     <value>tasksProgression</value>
  </property>
</bean>

Alfresco web script : validation-state.lib.js

function getValidationState(){  
tasksProgression.setInSession("test",5);
return tasksProgression.getFromSession();
}

when i get into setInSession, ServletUtil.getSession() returns null

isy
  • 531
  • 1
  • 12
  • 27
  • It's a bit unclear. What do you mean by multiple task? do you mean multiple check boxes in one task or you want to get the result from other tasks in one progress task? – Tahir Malik Jun 30 '13 at 16:52
  • I would like to allow the user to complete several tasks. There is one check box for each task. When he clicks on the button to validate, all the "checked" tasks have to be completed programatically. So i want to get the result from other tasks in on progress bar. – isy Jun 30 '13 at 18:34

3 Answers3

1

Either store it in a Session scoped Spring bean or use the raw HttpSession to store your state.

 session.addAttribute(Name, ObjectToStore)
 session.getAttribute(Name)

This fairly simple in a Java Backed webscript. If your are dealing the the JS webscripts, then you got to make the session available via a JavaScript root object see Alfresco - HTTP Sessions

Community
  • 1
  • 1
Thomas
  • 1,302
  • 9
  • 16
  • Thank you for your answer. I have already tried this solution but `HttpSession session = ServletUtil.getSession();` returns null – isy Jul 01 '13 at 07:31
  • From within a java backed DeclarativeWebScript or a BaseProcessorExtension? – Thomas Jul 01 '13 at 08:22
  • I have updated my post to show what i've tried. This is from within a BaseScopableProcessorExtension – isy Jul 01 '13 at 08:36
1

The solution was to use a java backed web script :

public class GetValidationProgressionBean extends DeclarativeWebScript {

@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
    String sessionVar = "progressionState"; 

    WebScriptSession session = req.getRuntime().getSession();
    Integer counter = (Integer) session.getValue(sessionVar);



    session.setValue(sessionVar, Integer.valueOf(counter.intValue() + 1));
    counter = (Integer) session.getValue(sessionVar);

    //put all the objects that you need in renditions to the model map
    Map<String, Object> model = new HashMap<String, Object>();
    model.put(sessionVar, counter);
    return model;
}


}
isy
  • 531
  • 1
  • 12
  • 27
0

An alternative way is to manage the progress at client side. e.g. by using Alfresco.util.setVar("your var", "your value") in your browser JS. But This will only work if the user stays in the same tab/window

alfrescian
  • 4,079
  • 1
  • 18
  • 20
  • This is not exactly what I want because I would like to set the session variable at server side when a task has been updated programmatically, and get the variable value at client side – isy Jul 04 '13 at 11:34