I just needed to do something similar. Basically needed to normalize the
paginated (via database) output of a grid with slightly different queries
going into the db pagination call.
I know you asked this question a long long long time ago, but thought it'll
be here for the next guys looking for a solution.
The grid component takes an override parameter which is supplied via
coercion. The key is to provide a different object that will provide the
grid component with the right set of paramter blocks.
There are a few steps.
1. Create a ContainerPropertyOverrides object that contains both the current
container's ComponentResources and the grid component's
ComponentResources
Here is a sample of the internals
private final ComponentResources parent;
private final ComponentResources self;
private final Messages messages;
public ContainerPropertyOverrides(ComponentResources resources)
{
Component container = resources.getContainer();
if(container != null)
parent = container.getComponentResources();
else
parent = null;
self = resources;
messages = resources.getContainerMessages();
}
@Override
public Block getOverrideBlock(String name)
{
if(parent != null)
{
Block b = parent.getBlockParameter(name);
if(b != null)
return b;
}
return self.getBlockParameter(name);
}
2. contribute a coercion from ComponentResources to your newly created
object in step 1
here is what i have
public static void contributeTypeCoercer(ConfigurationCoercionTuple
configuration)
{
configuration.add(CoercionTuple.create(ComponentResources.class,
ContainerPropertyOverrides.class,
new CoercionComponentResources,
ContainerPropertyOverrides()
{
public ContainerPropertyOverrides
coerce(ComponentResources input)
{
return new ContainerPropertyOverrides(input);
}
}));
}
3. Setup your component to use all this properly
here is a snippet from my setup
public class MyGridWrapper
{
//this is just to make sure refactoring efforts in the future don't
break this
// functionality
private static final String GRID_ID=myGrid;
@Parameter(value=GRID_ID, allowNull=false)
@Property(write = false)
private ContainerPropertyOverrides overrides;
@Property
@Component(id=GRID_ID, parameters={overrides=overrides})
private Grid myGrid;
//stuff that sets up the source, etc etc
}
Knowing tapestry, there are probably a few other options you have to solving
the problem.
Last thing i'll mention is that you can do this without contributing a
coercion. Simply supply a default value for overrides and construct the
object yourself.
You can read about it here:
http://tapestry.apache.org/tapestry5.2-dev/guide/parameters.html
Good luck
--
View this message in context:
http://tapestry.1045711.n5.nabble.com/Wrapping-a-grid-tp2416039p3214873.html
Sent from the Tapestry - User mailing list archive at Nabble.com.
-
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org