Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8714433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:35:43+00:00 2026-06-13T05:35:43+00:00

in a first form i ve a primefaces multiple selection tree(populated from LDAP) and

  • 0

in a first form i ve a primefaces multiple selection tree(populated from LDAP) and in another form i ve a selectOneMenu primefaces component. i would like to make the default selectOneMenu value(the first displayed on this menu) to be the value of the tree selected node. i ve tryed to use f:ajax.. but it doesnt work as these elements doesnt belong to the same form (the selectOneMenu name in the render attribute was unknown..)

here is my index.xhtml which contain all these elements :

 <?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui"
    xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
    <title>Insert title here</title>
    <script src="JS/general.js" type="text/javascript"></script>
    <link rel="stylesheet" type="text/css" href="CSS/general.css" />
    <script src="clean/clean-ajax-all.js"></script>
    <script>
        var crudmenu = "crudmenu";
        var adduserform = "adduserform";
    </script>
</h:head>
<body>

    <h:form id="form">

        <p:growl id="messages" showDetail="true" escape="false" />

        <p:tree value="#{treeBean.root}" var="node"
            onNodeClick="this.form.submit();" selectionMode="multiple"
            selection="#{treeBean.selectedNodes}" id="treeMultiple">

            <p:treeNode>
                <h:outputText value="#{node}" />
            </p:treeNode>
        </p:tree>


        <p:commandButton value="Display Selected" update="messages"
            actionListener="#{treeBean.displaySelectedMultiple}" id="btnDisplay" rendered="false"/>  

    </h:form>


    <div id="adduserform" name="adduserform"
        style="text-align: center; overflow: hidden; height: 0px; width: 270px; border: #040600 1px;">


        <h:form>
            <h:panelGrid border="1" columns="2">
            ID :  <p:selectOneMenu value="" panelStyle="width:150px"
                    effect="fade" var="p" style="width:160px" filter="true"
                    filterMatchMode="startsWith">
                    <f:selectItem itemLabel="#{treeBean.selectedNodeValue}"
                        itemValue="" />

                </p:selectOneMenu> 


    objectClass : <p:selectOneMenu value="" panelStyle="width:150px"
                    effect="fade" var="p" style="width:160px" filter="true"
                    filterMatchMode="startsWith">
                    <f:selectItem itemLabel="Select One" itemValue="" />

                </p:selectOneMenu>


            </h:panelGrid>
        </h:form>
    </div>



</body>
</html>

and here is my managed bean :

package org.primefaces.examples.view;

import java.io.Serializable;

import javax.faces.application.FacesMessage;
//other imports..

@ManagedBean(name = "treeBean")
public class TreeBean implements Serializable {


    private TreeNode root;

    private TreeNode[] selectedNodes;

    private String selectedNodeValue;


    public TreeBean() {

        populateTreeFromLdap();

    }


    public String getSelectedNodeValue() {
        if (selectedNodes != null && selectedNodes.length == 1)
            for (TreeNode node : selectedNodes)
            selectedNodeValue = node.getData().toString(); 
        return selectedNodeValue;
    }


    public void setSelectedNodeValue(String selectedNodeValue) {
        this.selectedNodeValue = selectedNodeValue;
    }


    public void populateTreeFromLdap(){
     //code to get entries from LDAP..
            }               


    }

    public TreeNode getRoot() {
        return root;
    }

    public TreeNode[] getSelectedNodes() {
        return selectedNodes;
    }

    public void setSelectedNodes(TreeNode[] selectedNodes) {
        this.selectedNodes = selectedNodes;
    }

    public void displaySelectedMultiple(ActionEvent event) {
        if (selectedNodes != null && selectedNodes.length > 0) {
            StringBuilder builder = new StringBuilder();

            for (TreeNode node : selectedNodes) {
                builder.append(node.getData().toString());
                builder.append("<br />");
            }

            FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO,
                    "Selected", builder.toString());

            FacesContext.getCurrentInstance().addMessage(null, message);
        }
    }
}

The problem is how to refresh the “#{treeBean.selectedNodeValue}” of the selectOneMenu ‘s itemLabel after the tree node selection happen..

By the way, i m new in jsf and i m really upset that the traditional ajax use for loading
a content in a div from another page doesnt work anymore in jsf..i used that in some previous jsp/servlet applications and it work fine..

thnx for help !!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T05:35:44+00:00Added an answer on June 13, 2026 at 5:35 am

    If I understand what you are trying to do, I would next bind the selectOneMenu to a value on the backing bean. In your getSelectedNodeValue() I would set that value. The final piece to make this work is to use an listener events as shown here: primefaces.org/showcase-labs/ui/treeEvents.jsf.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a FormWizard where I need data from the first form to pass
How can we hide all list element from first form in following html structure
how would this code be modified so it does not .focus() the first form
I'm able to get my first form, titled FieldReprogrammingSoftware to close and another form
I have two windows forms. The first form shows list of records from sql.
I have an sqlConnection on my first form and wondered if I could make
I have a 2 forms setup my first form will call another form with
I like having log data in a last-first form (the same way most blogs
I have a MOSS workflow where on the first form, the user can choose
Basically I just need the id of the record on the first form so

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.