Reputation: 20404
I'm struggling with the Object datasource in an XPage:
<xp:this.data>
<xe:objectData var="demo" ignoreRequestParams="true"
readonly="false" scope="view"
createObject="#{javascript:return new demo.SampleBean();}">
</xe:objectData>
</xp:this.data>
When I execute save();
on the XPage in SSJS I get the error:
Error saving data source demo The save method has not been implemented in the data source
The class is rather simple:
package demo;
import java.io.Serializable;
public class SampleBean implements Serializable {
private static final long serialVersionUID = 1L;
private String name;
private String job;
public String getName() {
return this.name;
}
public String getJob() {
return this.job;
}
public void setName(final String name) {
this.name = name;
}
public void setJob(final String job) {
this.job = job;
}
public void dummyAction() {
System.out.println("Here shall be logic");
}
}
I tried to add a public void save();
method to the class, but that doesn't do the trick.
So I'm looking for a sample of an Object datasource
Upvotes: 1
Views: 1511
Reputation: 8086
You've defined the createObject
attribute for the data source, but you haven't specified the saveObject
attribute... that's what the error message you're getting ("save method has not been implemented") is referring to.
So, for example, if you want your dummyAction()
method to run when a save is triggered, try this:
<xp:this.data>
<xe:objectData var="demo" ignoreRequestParams="true"
readonly="false" scope="view"
createObject="#{javascript:return new demo.SampleBean();}"
saveObject="#{javascript:return value.dummyAction();}">
</xe:objectData>
</xp:this.data>
When the saveObject
attribute is specified as a SSJS method binding, the variable value
is bound to the data object, and then the method binding is invoked. So you can either pass value
to some other object to handle the business logic of saving the object, or you can use a syntax of value.anyMethod()
to keep the business logic of object serialization internal to the object itself.
NOTE: whatever logic you do use in this method, you'll want to return a boolean (not void
), so that a return value of false
can be treated as a cancellation, just like the standard Domino document data source does.
Upvotes: 5