Ah, that's what I was looking for! And we can do it one simpler still
by eliminating the register() method:
public class SomethingAdaptor implements ISqueezeAdaptor
{
public void setDataSqueezer(DataSqueezer dataSqueezer) {
register(dataSqueezer);
}
public void register(DataSqueezer squeezer) {
squeezer.register(PREFIX, Something.class, this);
}
// ...
}
<service-point id="SomethingAdaptor"
interface="com.acme.SomethingAdaptor">
<invoke-factory>
<construct class="com.acme.SomethingAdaptor">
<set-service property="dataSqueezer"
service-id="tapestry.data.DataSqueezer"/>
</construct>
</invoke-factory>
</service-point>
<contribution configuration-id="hivemind.EagerLoad">
<load service-id="SomethingAdaptor"/>
</contribution>
That *definitely* should be in the 4.0 docs. It would have taken me
ages to figure that out on my own.
Cheers,
Paul
On Aug 8, 2005, at 12:02 PM, Raphaël Jean wrote:
Actually you can do simpler:
SomethingAdaptor.java:
public class SomethingAdaptor implements ISqueezeAdaptor
{
private DataSqueezer dataSqueezer;
private static final String PREFIX = "I";
public void setDataSqueezer(DataSqueezer dataSqueezer) {
this.dataSqueezer = dataSqueezer;
}
public void register() {
register(dataSqueezer);
}
public void register(DataSqueezer squeezer) {
squeezer.register(PREFIX, Something.class, this);
}
public String squeeze(DataSqueezer squeezer, Object data)
throws IOException
{
// ...
}
public Object unsqueeze(DataSqueezer squeezer, String string)
throws IOException
{
// ...
}
}
hivemodule.xml:
<service-point id="SomethingAdaptor"
interface="com.acme.SomethingAdaptor">
<invoke-factory>
<construct class="com.acme.SomethingAdaptor"
initialize-method="register">
<set-service property="dataSqueezer"
service-id="tapestry.data.DataSqueezer"/>
</construct>
</invoke-factory>
</service-point>
<contribution configuration-id="hivemind.EagerLoad">
<load service-id="SomethingAdaptor"/>
</contribution>
-----Original Message-----
From: Paul Cantrell [mailto:[EMAIL PROTECTED]
Sent: Monday, August 08, 2005 6:25 PM
To: Tapestry users
Subject: Re: Registering a custom ISqueezeAdaptor (was: What is a
"strategy," and how do I write one?)
That works, thanks!
It would be nice if I could do it just with hivemodule.xml alone,
without the need for MyDataSqueezerImpl, but I admit this is pretty
painless.
Maybe this example code should be in the docs? (Or is it and I missed
it?)
Cheers,
Paul
On Aug 8, 2005, at 2:43 AM, Raphaël Jean wrote:
Paul,
You can replace the original DataSqueezer service by your own
implementation, which will register your custom squeeze adaptor.
public class MyDataSqueezerImpl extends
org.apache.tapestry.util.io.DataSqueezerImpl {
public MyDataSqueezerImpl(ClassResolver resolver) {
super(resolver);
new CustomSqueezeAdaptor().register(this);
}
}
Then in your hivemodule.xml:
<module>
<!-- Replacement for the DataSqueezer service -->
<implementation service-id="tapestry.data.DataSqueezer">
<invoke-factory>
<construct class="com.acme.MyDataSqueezerImpl">
<class-resolver/>
</construct>
</invoke-factory>
</implementation>
</module>
No need to register your custom squeeze adaptor in your pages
anymore.
Hope this helps,
Raphael
-----Original Message-----
From: Paul Cantrell [mailto:[EMAIL PROTECTED]
Sent: Monday, August 08, 2005 5:53 AM
To: Tapestry users
Subject: Registering a custom ISqueezeAdaptor (was: What is a
"strategy,"
and how do I write one?)
OK, I've managed to register my own CustomSqueezeAdaptor by
implementing PageAttachListener and using the following code:
private static boolean squeezerRegistered;
@InjectObject("service:tapestry.data.DataSqueezer")
public abstract DataSqueezer getDataSqueezer();
public void pageAttached(PageEvent event)
{
synchronized(InnigBasePage.class)
{
if(!squeezerRegistered)
{
new CustomSqueezeAdaptor().register
(getDataSqueezer());
squeezerRegistered = true;
}
}
}
It works, but it's pretty crummy. Surely there is -- or should
be --
a way to do this entirely from my hivemodule.xml?
Cheers,
Paul
On Aug 7, 2005, at 1:16 PM, Norbert Sándor wrote:
Probably it talks about a data squeezer adaptor.
You should create a custom squeezer adaptor or eg. make
CustomClass
implement Serializable.
BR,
Norbi
----- Original Message ----- From: "Paul Cantrell"
<[EMAIL PROTECTED]>
To: "Tapestry users" <[email protected]>
Sent: Sunday, August 07, 2005 8:09 PM
Subject: What is a "strategy," and how do I write one?
I notice that if I do this...
<a href="#" jwcid="@DirectLink" listener="listener:doStuff"
parameters="ognl:value">
...with this backing code:
public abstract CustomClass getValue();
public void doStuff(CustomClass value) { ... }
...it doesn't work (which I would expect), but I get this error
message:
Could not find a strategy instance for class CustomClass
...which suggests that this *could* work if only I registered a
"strategy" with Tapestry, whatever that means. I looked through
the docs and a did a quick web search on this, without luck --
though I'm sure good information is out there somewhere.
Anybody on this list know how it's done? I'm using 4.0 beta 3.
Cheers,
Paul
_________________________________________________________________
"Nationalism is an infantile disease. It is the measles of mankind."
-- Albert Einstein
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]