Re:Workflow control through button click

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2007 07:38 AM
I have a requirement, that whenever a content is created i should have a additional button like 'submit to worklfow'. When a user clicks on the button, the content should follow my workflow.
Help me how to implement this.
I intially had a 'execue script as a rule', this will send my doc to wf as soon as it is created in a space. But now i need to control it with a button in UI.
pls help out
Thanks,
Lakshmi.
- Labels:
-
Archive

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2007 01:03 AM
Let me put it in this way ,
I have a workflow.js:
var workflow = actions.create("start-workflow");
workflow.parameters.workflowName = "jbpm$wf:myWorkflow";
workflow.parameters["bpm:workflowDescription"] = document.name;
workflow.execute(document);
I set a rule 'Execute this script' in my space. Now my question is : Is it possible to execute the script on click of button in UI???
Thanks,
Lakshmi

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2007 04:23 AM
The reference to the ScriptService could be injected in Managed Bean which will implement Action listener method of your custom button
Kind regards,
Denis

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2007 06:30 AM
I will have to write a class that will implement the method in interface ScriptService, then in my jsp call this method thru actionlistener.
If so there are two arguments in executeScript() method. One is the scriptclasspath . Other is given as ''Object model to process script against"
What shud i pass for this argument.
Sorry am very new to alfresco and its sourde code.
Thanks,
Lakshmi

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2007 07:20 AM
<managed-bean> <description>Bean that provides information for the About page</description> <managed-bean-name>TestBean</managed-bean-name> <managed-bean-class>test.Bean</managed-bean-class> <managed-bean-scope>session</managed-bean-scope> <managed-property> <property-name>scriptService</property-name> <value>#{ScriptService}</value> </managed-property> </managed-bean>
In object model variable you have to pass references to all object you would like to have avaliable in javascript, have a look atorg.alfresco.repo.jscrip.RhinoScriptTest.java, testScriptActions() method for an example of usage
Kind regards,
Denis

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2007 08:37 AM
I wrote my class and here are my entries:
faces-config-bean.xml:
<managed-bean>
<managed-bean-name>testService</managed-bean-name>
<managed-bean-class>org.alfresco.repo.mytest.RhinoScriptTest</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<property-name>scriptService</property-name>
<value>#{ScriptService}</value>
</managed-property>
</managed-bean>
In my jsp i gave:
<h:commandButton id="workflow-button" styleClass="wizardButton"
value="Start Workflow"
action="#{testService.invokeScript}"/>
invokeScript () is my method in RhinoScriptTest class, that i wrote following the example testScriptActions() method you gave.
But i get his error when i click on the commandbutton:
17:55:45,234 ERROR [org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/alfresco].[Faces Servlet]] Servlet.service() for servlet Faces Servlet threw exception
javax.faces.FacesException: Error calling action method of component with id add-content-upload-end:workflow-button
at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:74)
at javax.faces.component.UICommand.broadcast(UICommand.java:106)
at javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:90)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:164)
at org.apache.myfaces.lifecycle.LifecycleImpl.invokeApplication(LifecycleImpl.java:316)
at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:86)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:105)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.alfresco.web.app.servlet.AuthenticationFilter.doFilter(AuthenticationFilter.java:81)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)
Caused by: javax.faces.el.EvaluationException: Exception while invoking expression #{testService.invokeScript}
at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:165)
at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:63)
… 23 more
Caused by: javax.faces.el.PropertyNotFoundException: Bean: org.alfresco.repo.mytest.RhinoScriptTest, property: scriptService
at org.apache.myfaces.el.PropertyResolverImpl.getPropertyDescriptor(PropertyResolverImpl.java:445)
at org.apache.myfaces.el.PropertyResolverImpl.getPropertyDescriptor(PropertyResolverImpl.java:416)
at org.apache.myfaces.el.PropertyResolverImpl.getType(PropertyResolverImpl.java:284)
at org.apache.myfaces.config.ManagedBeanBuilder.initializeProperties(ManagedBeanBuilder.java:164)
at org.apache.myfaces.config.ManagedBeanBuilder.buildManagedBean(ManagedBeanBuilder.java:55)
at org.apache.myfaces.el.VariableResolverImpl.resolveVariable(VariableResolverImpl.java:311)
at org.springframework.web.jsf.DelegatingVariableResolver.resolveVariable(DelegatingVariableResolver.java:110)
at org.alfresco.web.app.AlfrescoVariableResolver.resolveVariable(AlfrescoVariableResolver.java:91)
at org.apache.myfaces.el.ValueBindingImpl$ELVariableResolver.resolveVariable(ValueBindingImpl.java:569)
at org.apache.commons.el.NamedValue.evaluate(NamedValue.java:124)
at org.apache.myfaces.el.ValueBindingImpl.resolveToBaseAndProperty(ValueBindingImpl.java:450)
at org.apache.myfaces.el.MethodBindingImpl.resolveToBaseAndProperty(MethodBindingImpl.java:180)
at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:114)
… 24 more
Pls help out.
Thanks,
lakshmi.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2007 09:07 AM
Therefore you have to add this to your managed bean implementation
private ScriptService scriptService;public void setScripService(ScriptService scriptService){ this.scriptService=scriptService}
Hope this helps,
Kind regards,
Denis

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2007 09:44 AM
Thanks,
Kevin

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2007 10:39 AM

Kind regards,
Denis

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2007 09:39 AM
Giving a setter for scriptService worked. but now when i execute the script i get the following error:
18:05:57,359 INFO [repo.mytest.RhinoScriptTest] invokeScript
18:05:58,109 INFO [repo.mytest.RhinoScriptTest] after createNode
18:05:58,125 INFO [repo.mytest.RhinoScriptTest] Before executescript
org.alfresco.service.cmr.repository.ScriptException: Failed to execute script 'o
rg/alfresco/repo/mytest/workflow.js': Can't find method org.alfresco.repo.jscrip
t.ScriptAction.execute(org.mozilla.javascript.Undefined). (AlfrescoScript#3) at org.alfresco.repo.jscript.RhinoScriptService.executeScript(RhinoScrip
tService.java:118)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
……………….
My class for your ref:
public void invokeScript()
{
logger.info("invokeScript");
StoreRef store = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "rhino_" + System.currentTimeMillis());
NodeRef root = nodeService.getRootNode(store);
try
{
ChildAssociationRef childRef = nodeService.createNode(
root,
BaseNodeServiceTest.ASSOC_TYPE_QNAME_TEST_CHILDREN,
QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "script_content"),
ContentModel.TYPE_CONTENT,
null);
logger.info("after createNode");
TemplateNode concept
Map<String, Object> model = new HashMap<String, Object>();
model.put("doc", new Node(childRef.getChildRef(), serviceRegistry, null));
model.put("root", new Node(root, serviceRegistry, null));
logger.info("Before executescript");
Object result = scriptService.executeScript(TESTSCRIPT_CLASSPATH2, model);
System.out.println("Result from TESTSCRIPT_CLASSPATH2: " + result.toString());
}
catch (Throwable err)
{
err.printStackTrace();
}
}
private static final String TESTSCRIPT_CLASSPATH2 = "org/alfresco/repo/mytest/workflow.js";
I even packaged the class org.alfresco.repo.jscrip
t.ScriptAction along with my class. But it says 'cannot find method ', though the method is there.
I also dont know how to pass the parameters to my script. As my script is to execute workflow, i need to pass the current document reference.
I altered the container.jsp to add a button and call my action:
<tr>
<td align="center">
<h:commandButton id="workflow-button" styleClass="wizardButton"
value="Start Workflow"
action="#{testService.invokeScript}"
disabled="#{WizardManager.finishButtonDisabled}" />
</td>
</tr>
Pls help out.
