You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by "tapestry.kung.fu" <ba...@gmail.com> on 2012/06/26 19:46:57 UTC
Tapestry Tree Links with parameter
I am having trouble passing parameters to page link while creating Tree with
click-able links. This is how my code look like.
1) I have Pojo ValueWrapper which has two member variables label and
pageName. Constructor of ValueWrapper takes label and pagename. I have one
RootNode with ValueWrapper("ROOT", null) and then i am appending many
children node which has clickable links. The Tree component I have created
using tapestry Tree component looks like this.
public class PortalAccessTree extends UserSessionManagement {
@InjectComponent
private Tree tree;
@SuppressWarnings("unused")
@Persist
@Property
private ValueWrapper valueWrapper;
@SetupRender
void initializeValue() throws VCloudException
{
if(getUser().getRootNode().getChildren().size() == 0) {
PortalHelperUtil.prepareAccessTree(getUser().getRootNode(),
getUser().getPrimaryUser().getCloudManagerUsers());
}
}
public TreeModel<ValueWrapper> getValueWrapperModel() {
ValueEncoder<ValueWrapper> encoder = new
ValueEncoder<ValueWrapper>() {
public String toClient(ValueWrapper value) {
return value.getUuid();
}
public ValueWrapper toValue(String clientValue) {
return getUser().getRootNode().seek(clientValue);
}
};
return new DefaultTreeModel<ValueWrapper>(encoder, new
ValueWrapperTreeModelAdapter(), getUser().getRootNode().getChildren());
}
/**
* Clear Action link on PortalAccessTree.tml invokes this method.
*/
void onActionFromClear() {
tree.clearExpansions();
}
}
2) I have 3 pages in code.
* OrganizationPage
* OrganizationUsagePage
* OrganizationReportPage
3) What I want to do is pass parameters to the page link which I tried by
doing this.
ValueWrapper("Manage Org", "OrganizationPage" + "?orgId=1");
When i start my application and try to expand tree. It immediately
gives me error message saying
page cannot be found with pageName "organizationpage?orgId=1".
If I do this ValueWrapper("Manage Org", "OrganizationPage"); that
works perfectly fine but then I don't know how to pass orgId to
OrganizationPage in that case.
4) My OrganizationPage contains proper definition to accept request
parameter.
@Property
@ActivationRequestParameter("orgId")
private String orgId;
I want to pass parameters to the clickable link which should take me to my
desired tapestry page with request parameter/value passed on it. Is it
possible to do so? I couldn't find a single example on Tapestry Tree which
does that.
--
View this message in context: http://tapestry.1045711.n5.nabble.com/Tapestry-Tree-Links-with-parameter-tp5714101.html
Sent from the Tapestry - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: Tapestry Tree Links with parameter
Posted by "tapestry.kung.fu" <ba...@gmail.com>.
Thank you. Yes I am newbie to Tapestry 5 and I made silly mistake. Solution
was in front of my eyes but I couldn't recognize it. My code is very
similar to example displayed on this URL
http://jumpstart.doublenegative.com.au/jumpstart/examples/component/treebrowsewith
minor modification.
This is what was happening.
My Old Code:
------------------
<t:tree t:id="tree" model="valueWrapperModel" value="valueWrapper"
label="block:renderTreeNodeLabel"/>
<t:block id="renderTreeNodeLabel">
<t:if test="valueWrapper.leaf">
<a href="#" t:type="PageLink"
t:page="${valueWrapper.pageName}">${valueWrapper.label}</a>
<p:else>
${valueWrapper.label}
</p:else>
</t:if>
</t:block>
While I was setting pageName value in ValueWrapper object i was storing it
in format like "pagename?parameter=value". Which is incorrect as above
snippet is trying to generate PageLink using pageName and not with full
url.
Solutions:
-------------
1) Fixing ValueWrapper
I have added private Map parameters; in ValueWrapper Object. I have also
added getter/setter for parameters variable.
Then i have modified Constructor to pass parameters in addition to label
and pageName.
I modified equal method to support map comparison too.
public boolean equals(Object obj) {
if(obj instanceof ValueWrapper) {
ValueWrapper passedObject = (ValueWrapper) obj;
String keyOfThisObject = this.getLabel() + "" +
this.getPageName();
String keyOfPassedObject = passedObject.getLabel() + "" +
passedObject.getPageName();
return keyOfThisObject.trim().equals(keyOfPassedObject.trim())
&& compareMaps(this.getParameters(), passedObject.getParameters());
}
return false;
}
public boolean compareMaps(Map<String, String> map1, Map<String,
String> map2) {
if(map1 == null && map2 == null) {
return true;
} else if(map1 != null && map2 != null) {
Set<String> keySet1 = map1.keySet();
Set<String> keySet2 = map2.keySet();
if(keySet1 != null && keySet2 != null &&
keySet1.equals(keySet2)) {
boolean flag = true;
CompareLoop:
for(String currentKey: keySet1) {
String value1 = map1.get(currentKey);
String value2 = map2.get(currentKey);
if( (value1 !=null && value2 ==null) ||
(value1 ==null && value2 !=null) ||
(!value1.equals(value2)) ) {
flag = false;
break CompareLoop;
}
}
return flag;
} else if(keySet1 == null && keySet2 == null) {
return true;
}
}
return false;
}
2) Fixing Template where PageLink is used to create label nodes (Notice
that i have added t:parameters to component now.
<t:tree t:id="tree" model="valueWrapperModel" value="valueWrapper"
label="block:renderTreeNodeLabel"/>
<t:block id="renderTreeNodeLabel">
<t:if test="valueWrapper.leaf">
<a href="#" t:type="PageLink"
t:page="${valueWrapper.pageName}"
t:parameters="valueWrapper.parameters">${valueWrapper.label}</a>
<p:else>
${valueWrapper.label}
</p:else>
</t:if>
</t:block>
On Tue, Jun 26, 2012 at 2:12 PM, Lance Java [via Tapestry] <
ml-node+s1045711n5714103h96@n5.nabble.com> wrote:
> I didn't take the time to fully understand your code but there's a fairly
> extensive tree example at jumpstart
>
> http://jumpstart.doublenegative.com.au/jumpstart/examples/ajax/treefromdatabasewithzones
>
> You can generate event links etc by setting the "label" block parameter of
> a tree
>
> ------------------------------
> If you reply to this email, your message will be added to the discussion
> below:
>
> http://tapestry.1045711.n5.nabble.com/Tapestry-Tree-Links-with-parameter-tp5714101p5714103.html
> To unsubscribe from Tapestry Tree Links with parameter, click here<http://tapestry.1045711.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5714101&code=YmFrdWwyMTA3N0BnbWFpbC5jb218NTcxNDEwMXwtMTc0NjczODU2Mw==>
> .
> NAML<http://tapestry.1045711.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>
--
View this message in context: http://tapestry.1045711.n5.nabble.com/Tapestry-Tree-Links-with-parameter-tp5714101p5714105.html
Sent from the Tapestry - User mailing list archive at Nabble.com.
Re: Tapestry Tree Links with parameter
Posted by Lance Java <la...@googlemail.com>.
I didn't take the time to fully understand your code but there's a fairly
extensive tree example at jumpstart
http://jumpstart.doublenegative.com.au/jumpstart/examples/ajax/treefromdatabasewithzones
You can generate event links etc by setting the "label" block parameter of a
tree
--
View this message in context: http://tapestry.1045711.n5.nabble.com/Tapestry-Tree-Links-with-parameter-tp5714101p5714103.html
Sent from the Tapestry - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org