• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Any tutorials on using direct actions and/or component actions with AJAX
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Any tutorials on using direct actions and/or component actions with AJAX


  • Subject: Re: Any tutorials on using direct actions and/or component actions with AJAX
  • From: Neil MacLennan <email@hidden>
  • Date: Sun, 6 Jan 2008 01:58:09 +0000

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="" 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=""></ 
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 +  
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@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: Re: JDBCAdaptor@b447de failed to provide new primary keys
  • Next by Date: Re: JDBCAdaptor@b447de failed to provide new primary keys
  • Previous by thread: Re: JDBCAdaptor@b447de failed to provide new primary keys
  • Next by thread: Not updating appropriately
  • Index(es):
    • Date
    • Thread