Re: Generating URL dynamically
Re: Generating URL dynamically
- Subject: Re: Generating URL dynamically
- From: Jonathan Rochkind <email@hidden>
- Date: Wed, 4 Feb 2004 15:20:00 -0600
There is no way to create a URL purely in Java
code that will trigger a component action.
Because of the way WO's request handling works,
because of the way that WO figures out what
action to call for a given URL, _something_ must
be in the .html corresponding to the action you
want.
However.... because it's an interesting problem,
I'll throw together a little reuseable component
that may be useful to you. Warning, I have not
tested this extensively, I just coded it just
now, but it appears to work. You may want to find
another way to do what you need to do. But... Put
an instance of this reuseable component near the
top of your page---when the page is generated,
and WO gets to the ComponentActionURLGenerator in
the page, a URL will be generated, and handed
back to your Java code through the actionURL
binding, for subsequent use in Java code.
There should be a way to get the
"ComponentActionURLGenerator" to refrain from
actually generating anything in your generated
HTML, but I couldn't figure out a way to do that.
So instead it will put an HTML comment in your
generated HTML code, oh well.
==========
ComponentActionURLGenerator.java
==========
//
// ComponentActionURLGenerator.java: Class file
for WO Component 'ComponentActionURLGenerator'
// Project TestMac
//
// Created by jrochkind on Wed Feb 04 2004
//
import com.webobjects.foundation.*;
import com.webobjects.appserver.*;
import com.webobjects.eocontrol.*;
import com.webobjects.eoaccess.*;
public class ComponentActionURLGenerator extends WOComponent {
public ComponentActionURLGenerator(WOContext context) {
super(context);
}
public boolean synchronizesVariablesWithBindings() {
return false;
}
public void setActionURL(String url) {
setValueForBinding(url, "actionURL");
}
public WOActionResults myInvokeAction()
{
return (WOActionResults) valueForBinding("action");
}
public String appendingToResponseHook()
{
setActionURL( context().componentActionURL() );
return "placeholder for action URL---";
}
}
==========
ComponentActionURLGenerator.html
==========
<WEBOBJECT NAME="GenericElement1"></WEBOBJECT>
==========
ComponentActionURLGenerator.wod
==========
GenericElement1: WOGenericElement {
otherTagString = appendingToResponseHook;
elementName = "!---";
invokeAction = myInvokeAction;
}
=========
ComponentActionURLGenerator.api
=========
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<wodefinitions>
<wo class="ComponentActionURLGenerator" wocomponentcontent="false">
<binding name="action"/>
<binding name="actionURL"/>
<validation message="'action' is a required binding">
<unbound name="action"/>
</validation>
<validation
message="'actionURL' is a required
binding">
<unbound name="actionURL"/>
</validation>
<validation
message="'actionURL' must be bound to a
settable value">
<unsettable name="actionURL"/>
</validation>
</wo>
</wodefinitions>
At 3:29 PM -0500 2/4/04, Jacky Gagnon wrote:
Hi, Jonathan
I already looked for WOActionURL; but it's
essential that I create the URL in the java code
(I must insert some URLs in a String and return
it for display, and the URL must launch a
component action). WOActionURL don't seem to be
useful in my case or I'm missing somethings...
Thanks!
J. Gagnon
Le Mercredi, 4 fivr 2004, ` 14:51
America/Montreal, Jonathan Rochkind a icrit :
The WOActionURL dynamic element is probably
what you are looking for. There is a thread on
this topic on the list right now. You may want
to review it.
At 1:49 PM -0500 2/4/04, Jacky Gagnon wrote:
Hi,
I must generate some HTML code dynamically and
insert it into some strings, who are displayed
with one WOString. I want to insert some URL
who can point to a particular component action.
How can I generate this URL without using a
WoComponent ? I found in WOContext,
directActionURLForActionNamed, but its for
direct action.
Thanks
J. Gagnon
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.