Stupid me, it seems that PageRenderLinkSource by default does what I'm
trying to achieve. It automaticaly adds activation context to render request
URL if no context specified.
I guess the thing works in such way that when during some request one asks
for some page via @InjectPage annotation, then this instance is also
thread-bound for all further possible fetching specified with same page name
(or class) during this request. So, when page with same name is specified as
parameter to PageRenderLinkSource methods, then tih service fetches this
same page instance and reads its activation context via "passivate" event.
Anyway, for anyone interested, tihs new type-safe version of PageLink is
trivial now:
public class SafePageLink extends AbstractLink {
@Parameter(required = true, allowNull = false)
private Object page;
@Inject
private PageRenderLinkSource pageRenderLinkSource;
void beginRender(MarkupWriter writer) {
if (isDisabled()) {
return;
}
Link link =
pageRenderLinkSource.createPageRenderLink(page.getClass());
writeLink(writer, link);
}
void afterRender(MarkupWriter writer) {
if (isDisabled()) {
return;
}
writer.end(); // <a>
}
}
And now you can have page links without worrying about page name or its
context values. Just use for eg:
@InjectPage
private EditUser editUser;
public EditUserPage getEditUserPage() {
return editUserPage.configured(user.getId());
}
...and in template:
<t:safepagelink t:page="editUserPage">Edit</t:safepagelink>
...instead of shorter, but type-nonsafe:
<t:pagelink t:page="admin/user/edituserpage"
context="user.id">Edit</t:pagelink>
Cheers,
Vjeran
----- Original Message -----
From: "Vjeran Marcinko" <vjeran.marci...@email.t-com.hr>
To: "Tapestry users" <users@tapestry.apache.org>
Sent: Sunday, June 21, 2009 1:14 PM
Subject: Re: Type-safe PageLink version
Your example captures somewhat my idea, but not quite...
Most importantly context values are not type-safe in your example because
they are given via String value without being ever sure that
EditEmployeePage requires only one context value and of what type it is.
When calling method onActivate(..) or some other for purpose of
configuring
it, then compiler takes care that everything is correct.
My whole intention is to make PageLink's render request type-safe exactly
in
the same way when one returns configured target page from action event
handler (ActionLink) that will serve for redirect response URL generation
(render request).
Actually, I tried to develop my own SafePageLink component, but I lack the
way of resolving context from page instance:
public class SafePageLink extends AbstractLink {
@Parameter(required = true, allowNull = false)
private Object page;
@Inject
private PageRenderLinkSource pageRenderLinkSource;
void beginRender(MarkupWriter writer) {
Object[] context = ?????
Link link =
pageRenderLinkSource.createPageRenderLinkWithContext(page.getClass(),
context);
writeLink(writer, link);
}
....
And then one just needs to have:
<t:safepagelink t:page="editEmployeePage">Create</t:safepagelink>
in template, and in page class:
@InjectPage
private EditEmployeePage editEmployeePage;
public Object getEditEmployeePageInstance() {
// configuring EditEmployeePage page instance via onActivate let's say
return editEmployeePage;
}
It's exactly the same way as I'm returning configured target page inside
action event handler. Maybe I should dig into ActionLink sorce to see how
it
fetches activation context (via "passivate" event somehow).
-Vjeran
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org