You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Wolfgang <wk...@ebi.ac.uk> on 2007/08/24 14:42:52 UTC

Link to a new site

Hi to all on this list,

I have just started to learn jsf and I managed to build a  menu with the 
tree2 component of Apache MyFaces.

The menu files are:
    menuEnVision.java (the code can be seen here: 
http://pastebin.parentnode.org/22482)
    menuEnVision.xhtml (http://pastebin.parentnode.org/22483)

What I didn't managed is, if one clicks on a menu point, the content of 
a new page should appear.
For example: statistics.xhtml or proteins.xhtml

If one clicks on a menu point, I have managed to identify which one it 
was, but how to use this
for opening the content of a  new site (e.g. statisitcs.xhtml)  I don't 
know .

Can anyone give me a short example how to do this?

Thanks for  your help!

Cheers Wolfgang



Re: Link to a new site

Posted by Bruno Aranda <br...@gmail.com>.
Welcome Wolfgang,

One of the features of the tree2 model is that you can extend its
model objects to accommodate the tree to your needs. For example, you
can have a specific extension of TreeNodeBase that contains an action
method for navigation:

public class TreeNodeNavigation extends TreeNodeBase {

    private String action;

    public TreeNodeNavigation(String type, String description, boolean
leaf, String action) {
        super(type, description, leaf);

        this.action = action;
    }

    public String navigate() {
        return action;
    }
}

As you can see, this kind of node contains an "action" method called
navigate() which returns the String for the action to be invoked.

For instance, you could create your tree in your backing bean using
code like this:

public class MyDemo {

    private TreeModelBase treeModel;

    public MyDemo(){
        TreeNodeBase root = new TreeNodeBase("simpleNode", "test", false);
        TreeNodeNavigation node= new TreeNodeNavigation("navNode",
"node1", true, "statistics");
        root.getChildren().add(node);

        treeModel = new TreeModelBase(root);
    }

    public TreeModelBase getTreeModel() {
        return treeModel;
    }

    public void setTreeModel(TreeModelBase treeModel) {
        this.treeModel = treeModel;
    }
}

As you can see in the previous snippet. One of the nodes is an
instance of TreeNodeNavigation and as an example I am passing the
action string "statistics", which you need to have configured in your
navigation-rules:

<faces-config>
...
 <managed-bean>
        <managed-bean-name>demo</managed-bean-name>
        <managed-bean-class>mycompany.MyDemo</managed-bean-class>
        <managed-bean-scope>session</managed-bean-scope>
    </managed-bean>

    <navigation-rule>
        <navigation-case>
            <from-outcome>statistics</from-outcome>
            <to-view-id>/statistics.xhtml</to-view-id>
        </navigation-case>
    </navigation-rule>

</faces-config>

So, whenver an action returns "statistics", it will navigate to the
statistics.xhtml view.

Finally, to use such a tree in your page, you could have something like this:

 <t:tree2 value="#{demo.treeModel}" var="node">
                <f:facet name="simpleNode">
                     <h:outputText value="#{node.description}"/>
                </f:facet>
                <f:facet name="navNode">
                    <h:panelGroup>
                        <h:commandLink value="#{node.description}"
action="#{node.navigate}" immediate="true"/>
                    </h:panelGroup>
                </f:facet>
            </t:tree2>

Where we have defined two kinds of node: simpleNode and navNode. The
latter uses the action from our node extended class.

Hope it helps!

Cheers ;-)

Bruno

On 24/08/07, Wolfgang <wk...@ebi.ac.uk> wrote:
> Hi to all on this list,
>
> I have just started to learn jsf and I managed to build a  menu with the
> tree2 component of Apache MyFaces.
>
> The menu files are:
>     menuEnVision.java (the code can be seen here:
> http://pastebin.parentnode.org/22482)
>     menuEnVision.xhtml (http://pastebin.parentnode.org/22483)
>
> What I didn't managed is, if one clicks on a menu point, the content of
> a new page should appear.
> For example: statistics.xhtml or proteins.xhtml
>
> If one clicks on a menu point, I have managed to identify which one it
> was, but how to use this
> for opening the content of a  new site (e.g. statisitcs.xhtml)  I don't
> know .
>
> Can anyone give me a short example how to do this?
>
> Thanks for  your help!
>
> Cheers Wolfgang
>
>
>