You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Boris Horvat <ho...@gmail.com> on 2014/04/13 13:45:29 UTC
Passing null value into context
Hi everyone
I have a code that generates page links based on the specified names in a
list. That block of code looks like this
<t:pagelink t:page="${subPage.firstValue}"
t:context="[subPage.secondValue]">
${pageName}
<t:if t:test="pageNotNum">
<span
class='badge'>${pageNotNum}</span>
</t:if>
</t:pagelink>
The subPage.secondValue on occasions has an id that should be used on other
occasions it doesn't (i.e. some pages require context and others dont). Due
to this I am seeing ugly URLs like
http://localhost:8080/todolist/$N
Is it possible to somehow omit $N value?
The only thing I can think if is to have 2 blocks of code with only
differences in the context parameter. However that would be redundant in my
mind and I would like to avoid it if possible.
So is it?
Thanks
--
Sincerely
*Boris Horvat*
Re: Passing null value into context
Posted by Lance Java <la...@googlemail.com>.
No, you can generate the context as normal. Just use EventContext in the
event to support a dynamic number of context values (ie 0 or 1 values).
Eg:
<t:eventlink event="myEvent" context="prop:myContext">...</t:eventlink>
public Object getMyContext() {
if (someObject == null) return Collections.emptyList();
return someObject;
}
void onMyEvent(EventContext ec) {
if (ec.getCount() == 0)
// no context
else if (ec.getCount() == 1) {
// context provided
Foo myFoo = ec.get(Foo.class, 0);
doStuff(foo);
} else {
throw new Exception();
}
}
Re: Passing null value into context
Posted by Boris Horvat <ho...@gmail.com>.
Ny server side event tyoe do you mean that I have to create link in java? I
cant just pass EventContext to context parameter of pagelink.
I tried that at it was take as a string of the EventContext toString method
On 13 Apr 2014 15:48, "Lance Java" <la...@googlemail.com> wrote:
> This can be done using EventContext as the serverside event's argument
> type. I assume using an empty list / array to represent your null case will
> achieve the desired result.
>
Re: Passing null value into context
Posted by Lance Java <la...@googlemail.com>.
This can be done using EventContext as the serverside event's argument
type. I assume using an empty list / array to represent your null case will
achieve the desired result.