Home : OpenEdit SDK : Programming OpenEdit : Actions and Programming
Actions and Programming
There any many built in capabilities in OpenEdit that you can tap into by specifying existing actions or you can write Java code and plug in your own actions.
What Do Actions Do?
An path-action can redirect a user to another page. Most actions are created to read properties from the WebPageRequest object and put variables into the request so the HTML can be rendered. An action can also throw an exception or modify the session.
We recommend you do not put business logic inside your actions. Instead the action can act like a controller and read data in then hand off the processing to a business object that is then placed into the session or the page request.
Specify An Action
Each openedit build includes a plugin.xml file within the openedit-editor-[version].jar file, that specifies what actions are available, like so:
<bean id="Admin" class="com.openedit.modules.admin.AdminModule"/>
<bean id="HtmlEditor" class="com.openedit.modules.html.HtmlEditorModule"/>
<bean id="RevisionEditor" class="com.openedit.modules.revisions.RevisionEditorModule"/>
Each bean is a plain old Java object. Put the corresponding compiled class files into WEB-INF/classes or into a jar in WEB-INF/lib. The only requirement for a method on the bean to be called as a path-action or page-action is that it must take a com.openedit.WebPageRequest parameter. So for example you might write the following Java class:
package com.foo;
class MyActions {
public void doSomethingUseful(com.openedit.WebPageRequest request) { ... }
}
You can add your java code into a jar file and add your own plugin.xml file to the root level of your jar. Here is an example xml syntax:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="MyActions" class="com.foo.MyActions"/>
</beans>
To apply the action to a page you would add to page.xconf:
<page-action name="MyActions.doSomethingUseful"/>
Or to apply an action to a whole directory, you would add to _site.xconf:
<path-action name="MyActions.doSomethingUseful"/>
For example, to auto login a visitor to OpenEdit based on a Cookie you would specify this action inside the /_site.xconf file.:
<path-action name="Admin.autoLogin" />
Or to try to process a username and password form you can specify this action inside the /openedit/authentication/login.xconf file:
<page-action name="Admin.login" />
JavaScript Actions
You can run any server side Javascript that you specify:
<path-action name="Script.run" >
<script>/replace/replaceform.js</script>
</path-action>
To see an example go here:
[http://www.openedit.org/replace/replaceform.js]
Viewing Existing Actions
You can see a listing of beans and actions by viewing the /openedit/update/java_object_list.html page. This also includes links to the JavaDoc for each action that comes with OpenEdit.
How Do I Test My Actions?
To test an action you can extend com.openedit.BaseTestCase. This will give you methods such as getBean(String) and getFixture().createPageRequest(String) that will allow you to execute your actions within JUnit without requiring a running web server.
Loading Variables
<path-action name="PageValue.loadPageVariable" bean="date2" class="java.util.Date"/>
This will create a new Date object each time the page is loaded. If you do not specify a class then the bean is loaded from the list of Spring beans. You can also load beans into the session:
<path-action name="SessionValue.loadSessionVariable" bean="date3" class="java.util.Date"/>
