I don't use AJAX (yet) so can't comment on that part of the code, but
in your Counter WOComponent, try:
return null;
instead of
return(this);
.neilmac
I have the following HTML template in my Main component:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title>AJAX Counter</title>
<script src="/HelloComponentAJAX/js/prototype.js" type="text/
javascript"></script>
<script type="text/javascript">
function request(anURL) {
new Ajax.Updater('counter', anURL, { method:
'get' });
}
</script>
</head>
<body>
<div id="counter">
<wo:Counter></wo:Counter>
</div>
</body>
</html>
Here's the contents of my Counter component template:
<wo:SimpleAJAXHyperlink action="[incrementCounter]"></
wo:SimpleAJAXHyperlink>
<wo:WOString value = "[count]"></wo:WOString>
And the Counter.java:
import com.webobjects.appserver.WOComponent;
import com.webobjects.appserver.WOContext;
@SuppressWarnings("serial")
public class Counter extends WOComponent {
public int count = 0;
public Counter(WOContext context) {
super(context);
}
public WOComponent incrementCounter() {
count++;
return(this);
}
}
And finally, here's my SimpleAJAXHyperlink dynamic element:
import com.webobjects.appserver.WOActionResults;
import com.webobjects.appserver.WOApplication;
import com.webobjects.appserver.WOAssociation;
import com.webobjects.appserver.WOContext;
import com.webobjects.appserver.WODynamicElement;
import com.webobjects.appserver.WOElement;
import com.webobjects.appserver.WORequest;
import com.webobjects.appserver.WOResponse;
import com.webobjects.foundation.NSDictionary;
public class SimpleAJAXHyperlink extends WODynamicElement {
private WOAssociation _action;
public SimpleAJAXHyperlink(String name, NSDictionary<String,
WOAssociation> associations, WOElement template) {
super(name, associations, template);
_action = (WOAssociation) associations.objectForKey("action");
}
public void appendToResponse(WOResponse response, WOContext
context) {
response.appendContentString("<div onClick=\"request('" +
context
.componentActionURL
(WOApplication.application().ajaxRequestHandlerKey()) + "');
\">click</
div>");
}
public WOActionResults invokeAction(WORequest aRequest, WOContext
aContext) {
WOActionResults results = null;
if(aContext.elementID().equals(aContext.senderID())) {
results = (WOActionResults)
_action.valueInComponent(aContext.component());
}
return (WOActionResults) (results);
}
}
When I run my application it kind of works (once). If I click on my
SimpleAJAXHyperlink it executes the component action, increments the
counter and updates the div with the new result. However, when I click
a second time I get the "You backtracked too far" page. So - what am I
doing wrong?
Regards,
Jake
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com
This email sent to [EMAIL PROTECTED]