Hi Ken,
Thanks for fixing the bug. The childCommands get invoked as expected now.
And with $this{component}, i don't even need to write a handler to
generate the url to navigate to.
<!childCommand
setAttribute(key="clickid" value="$this{clientId}");
setAttribute(key="click" value="$this{component}");
navigate(page="webApplicationEdit.jsf?webApp=#{click.text}" );
println(value=" navigate to:
webApplicationEdit.jsf?webApp=#{click.text}" );
/>
println showed that i am passing in the webApp name correctly. And if i
open up another browser with the url as
http://localhost:8080/admin-jsf/webApplicationEdit.jsf?webApp=admingui
webApplicationEdit.jsf shows correctly the request parameter.
But if i click on the node on the tree, ie admingui ,
webApplicationEdit.jsf can't show me the webApp parameter even though
println showed the correct url.
I have attached webApplicationEdit.jsf which just shows the request
parameter.
Please let me know if you have any idea.
Thanks for your help.
Anissa.
Ken Paulsen wrote:
>
> Hi Anissa,
>
> There was a bug (not sure how I missed it before). The required
> actionListener was not being registered because the factory doesn't
> know about the "command" events. These events get added after the
> factory is done processing... normally this would happen in the
> factory. So I added the code to add the required ActionListener that
> will dispatch the command events:
>
> ((ActionSource) link).addActionListener(
> CommandActionListener.getInstance());
>
> See below for more of your answers...
>
>
> Anissa Lam wrote:
>>
>> My goal is that when a user clicks on a dynamic tree node, it will
>> navigate to a page depending on the display name of this dynamic
>> node. eg. If the web application node has a display name being
>> 'hello', i would like to navigate to a page
>> "applications/webAppEdit.jsf?webapp=hello"
>> I was thinking to write a handler that will go through the UI
>> components and get the name of this dynamic tree node, ie, 'hello'.
>> The handler will then output the url of the page to navigate to.
>>
>> Is this a right approach to do the task ?
> Yes, I think something along these lines will work very well.
>> My problem is that the handler was never called, am i using the
>> correct syntax ? I thought the <!childCommand> shouldn't be inside
>> an <event> tag.
> The <event> tag isn't useful for !command events (for now). Command
> events are only applicable to ActionSource components and at this time
> <event> is not one. The problem was what I described above... not
> your fault.
>> Also, if you can show me the code segment to get the display name of
>> the selected dynamic tree code, that will help a lot.
> This is one area where the JSFTemplating project really shines! The
> $this{component} will give you the component that you clicked on. You
> can combine this with JSF's EL to walk the component attributes to get
> any information you want on the component. Here's an example:
>
> <!childCommand
> setAttribute(key="clickid" value="$this{clientId}");
> setAttribute(key="click" value="$this{component}");
> println(value="Clicked Component ID: #{clickid}");
> println(value="Clicked Component: #{click}");
> println(value="Clicked Component id: #{click.parent.id}");
> />
>
> The first setAttribute() demonstrates $this{clientId} which is a quick
> way to directly get the clientId. You can do this same for
> $this{id}. The 2nd setAttribute() shows how to get the UIComponent
> that was clicked on: $this{component}. The println's are for
> debugging purposes showing how you can access these values and pass
> them to handlers for further processing. Notice that I use JSF EL to
> walk the UIComponent to get its parent and then get its parent ID. In
> this case, this is similar to what you might want to do.
>
> Now, if you'd prefer not to search the log file for you debugging
> information, here's how I often do the debugging:
>
> <staticText value="Clicked Component ID: #{clickid} <br />" />
> <staticText value="Clicked Component: #{click} <br />" />
> <staticText value="Clicked Component id: #{click.parent.id}
> <br />" />
>
> This is the same information as the println()'s except that it is
> shown in the browser. I put this right after the tree. I've attached
> my test file for you to try out.
>
> I hope this helps!!
>
> Ken
>> Here is how my .jsf file looks like:
>>
>> <dynamicTreeNode id="webApplications"
>>
>> treeAdaptorClass="com.sun.enterprise.tools.admingui.tree.MBeanTreeAdaptor"
>>
>>
>> objectName="com.sun.appserv:type=applications,category=config"
>> methodName="getAllDeployedWebModules"
>> text="$resource{i18n.tree.WebApps}"
>> url="../admingui/webApplications"
>> imageURL="images/folder.gif"
>> target="main"
>> expanded="$boolean{false}"
>> attributeName="name"
>> childImageURL="images/webModule.gif"
>> childTarget="main"
>> childExpanded="$boolean{false}"
>> >
>> *<!childCommand
>> println(value="!!! childCommand !!!");
>> getNavigateURL(editPage="applications/webAppEdit",
>> url=>$attribute(url));
>> navigate(page=$attribute(url));
>> />*
>> <!filterTree filterSystemApps() />
>> </dynamicTreeNode>
>>
>>
>> Thanks
>> Anissa.
> ------------------------------------------------------------------------
>
> <sun:page id="page">
> <!beforeCreate
> setResourceBundle(key="i18n" bundle="com.sun.enterprise.tools.admingui.resources.Strings")
> />
> <sun:html id="html">
> <sun:head id="head" title="$resource{i18n.peTree}" />
> <sun:body>
> <sun:form id="form">
> <sun:tree id="tree"
> text="$resource{i18n.tree.commonTasks}"
> url="commonTask.jsf"
> imageURL="images/common_task.gif"
> target="main"
> clientSide="#{true}">
> <!afterCreate
> getUIComponent(clientId="form:tree", component=>$attribute{treeComp});
> setUIComponentProperty(component="$attribute{treeComp}", property="selected", value="form:tree:applicationServer:selectMe");
> />
>
> <!-- ===================================== Application Server ====================== -->
> <sun:treeNode id="applicationServer"
> text="$resource{i18n.tree.appServer}"
> url="appServer/serverInstGeneralPe.jsf"
> imageURL="images/instance.gif"
> target="main"
> expanded="$boolean{true}"
> >
> <sun:treeNode id="selectMe" text="Select Me" />
> <sun:treeNode id="notMe" text="Not Me" />
> <sun:treeNode id="orMe" text="Or Me" />
> <dynamicTreeNode id="webApplications"
> treeAdaptorClass="com.sun.enterprise.tools.admingui.tree.MBeanTreeAdaptor"
> expanded="$boolean{true}"
> objectName="com.sun.appserv:type=applications,category=config"
> methodName="getAllDeployedWebModules"
> text="$resource{i18n.tree.WebApps}"
> url="../admingui/webApplications"
> imageURL="images/folder.gif"
> attributeName="name"
> childURL="../admingui/webApplicationsEdit"
> childImageURL="images/webModule.gif"
> childExpanded="$boolean{false}"
> >
> <!filterTree
> //filterSystemApps();
> println(value="FILTER... HELLO WORLD!");
> />
> <!childCommand
> setAttribute(key="clickid" value="$this{clientId}");
> setAttribute(key="click" value="$this{component}");
> println(value="Clicked Component ID: #{clickid}");
> println(value="Clicked Component: #{click}");
> println(value="Clicked Component id: #{click.parent.id}");
> />
> </dynamicTreeNode>
> </sun:treeNode>
> </sun:tree>
>
> <staticText value="Clicked Component ID: #{clickid} <br />" />
> <staticText value="Clicked Component: #{click} <br />" />
> <staticText value="Clicked Component id: #{click.parent.id} <br />" />
>
> </sun:form>
> </sun:body>
> </sun:html>
> </sun:page>
>