Skip to content
This repository has been archived by the owner on Jan 10, 2019. It is now read-only.

Commit

Permalink
Component to String converter
Browse files Browse the repository at this point in the history
Useful for the linkpage component
  • Loading branch information
trsvax committed Sep 22, 2011
1 parent 5b9c1d7 commit f480145
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/main/java/com/trsvax/tapestry/misc/services/MiscModule.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package com.trsvax.tapestry.misc.services;

import org.apache.tapestry5.ioc.Configuration;
import org.apache.tapestry5.ioc.OrderedConfiguration;
import org.apache.tapestry5.ioc.ServiceBinder;
import org.apache.tapestry5.ioc.annotations.Contribute;
import org.apache.tapestry5.ioc.services.Coercion;
import org.apache.tapestry5.ioc.services.CoercionTuple;
import org.apache.tapestry5.runtime.Component;
import org.apache.tapestry5.services.ComponentClassTransformWorker;

/**
Expand All @@ -27,5 +31,20 @@ public static void provideWorkers(OrderedConfiguration<ComponentClassTransformW
}


public static void contributeTypeCoercer(Configuration<CoercionTuple> configuration)
{
Coercion<Component, String> coercion = new Coercion<Component, String>()
{
public String coerce(Component input)
{
return input.getComponentResources().getPageName();
}
};

configuration.add(new CoercionTuple<Component, String>(Component.class, String.class, coercion));
}




}
12 changes: 12 additions & 0 deletions src/test/java/com/trsvax/tapestry/misc/pages/CoerceComponent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.trsvax.tapestry.misc.pages;

import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.Property;

public class CoerceComponent {

@Property
@InjectPage
private LinkPage page1;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<html t:type="layout"
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd"
xmlns:p="tapestry:parameter">

<t:pagelink page="prop:page1">page1 link</t:pagelink>

</html>

0 comments on commit f480145

Please sign in to comment.