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

  • SEARCH
  • Home
  • 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 8437121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:20:56+00:00 2026-06-10T07:20:56+00:00

I create a web application. Here I use prime-face tab and ajax. when I

  • 0

I create a web application. Here I use prime-face tab and ajax.
when I click on menu item on menu bar it open a new tab. but active the first opened tab. I want to active the last opened tab.
my code here:

for menubar and output Tab

<h:form id="menu">                
            <p:menubar autoDisplay="true">
               <p:submenu id="student" label="Student">       
                    <p:menuitem id="studentAdmission" value="Student Admission" action="#{ajaxBean.editAction}" ajax="true" update=":outputForm">
                        <f:setPropertyActionListener target="#{ajaxBean.action}" value="StudentAdmission" />
                    </p:menuitem>
                    <p:menuitem id="studentList" value="Student Profile" action="#{ajaxBean.editAction}" ajax="true" update=":outputForm">
                        <f:setPropertyActionListener target="#{ajaxBean.action}" value="StudentProfile" />
                    </p:menuitem>                        
                </p:submenu>
                <p:submenu id="registration" label="Registration">
                    <p:menuitem id="registrationAdd" value="Subject Registration" action="#{ajaxBean.editAction}" ajax="true"  update=":outputForm">
                        <f:setPropertyActionListener target="#{ajaxBean.action}" value="SubjectRegistration"/>                                 
                    </p:menuitem>
                    <p:menuitem id="registrationList" value="List of Registration" action="#{ajaxBean.editAction}" ajax="true" update=":outputForm">
                        <f:setPropertyActionListener target="#{ajaxBean.action}" value="RegistrationList" />
                    </p:menuitem>                        
                </p:submenu>
            </p:menubar>
        </h:form>       
        <h:form id="outputForm">
            <p:tabView id="outputTab">
                <p:ajax event="tabClose" listener="#{ajaxBean.closeTab}"/>
                <c:forEach items="#{ajaxBean.chcekItem}" var="item" varStatus="loop">
                    <p:tab id="#{item}" title="#{item}" closable="true">                            
                        <ui:include src="#{bundle[item]}"/>   

                    </p:tab>
                </c:forEach>
            </p:tabView>
        </h:form>

ajaxBean.java

package com.ajax;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import org.primefaces.event.TabCloseEvent;

/**
 *
 * @author DELL
 */
@ManagedBean(name = "ajaxBean")
@SessionScoped
public class AjaxBean implements Serializable {

public AjaxBean() {
}
private boolean input;
private List<String> chcekItem = new ArrayList<String>();

public void setAction(String action) {
    input = true;
    if (getChcekItem().isEmpty()) {
        getChcekItem().add(action);
        System.out.println("The item " + action + " is Successfully Added to array");
    } else {

        for (String abce : getChcekItem()) {
            if (abce.equals(action)) {
                System.out.println(abce + "=" + action);
                input = false;
                //We can jump out of the loop here since we already found a matching value
                break;
            }
        }

        if (input) {
            getChcekItem().add(action);
            System.out.println("The item " + action + " is Successfully Added to array");
        } else {
            System.out.println("The item " + action + " is Exist");
        }
    }


}
private String close;

public void closeTab(TabCloseEvent closeAction) {
    close = closeAction.getTab().getId();
    for (String abce : getChcekItem()) {
        if (abce.equals(close)) {
            System.out.println(close + " is remove from Array");
            getChcekItem().remove(abce);
            //We can jump out of the loop here since we already found a matching value
            break;
        }
    }
}

public String editAction() {
    return null;
}

/**
 * @return the arrJavaTechnologies
 */
/**
 * @return the chcekItem
 */
public List<String> getChcekItem() {
    return chcekItem;
}

/**
 * @param chcekItem the chcekItem to set
 */
public void setChcekItem(ArrayList<String> chcekItem) {
    this.chcekItem = chcekItem;
}

/**
 * @return the input
 */
public boolean isInput() {
    return input;
}

/**
 * @param input the input to set
 */
public void setInput(boolean input) {
    this.input = input;
}
 /**
 * @return the menuaction
 */

}

item.java

package com.ajax;


public class Item {

public Item() {
}
private String value;

public Item(String value) {
    this.value = value;
}

public void setValue(String value) {
    this.value = value;
}

public String getValue() {
    return value;
}
}

MenuManagedBean.java

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
  */
package com.ajax;

import java.util.ArrayList;
import java.util.Iterator;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

/**
 *
 * @author DELL
 */
@ManagedBean(name = "menuManagedBean")
@SessionScoped
public class MenuManagedBean {

/** Creates a new instance of MenuManagedBean */
public MenuManagedBean() {
}

private String menuItems;
private ArrayList<String> menuId=new ArrayList<String>();

public void tabGenerate(String event){
    this.menuItems=event;
    getMenuId().add(event);

    Iterator iterator=getMenuId().iterator();
    while(iterator.hasNext()){
        System.out.println("Items : " +iterator.next());
    }
}

/**
 * @return the menuId
 */
public ArrayList<String> getMenuId() {
    return menuId;
}

/**
 * @param menuId the menuId to set
 */
public void setMenuId(ArrayList<String> menuId) {
    this.menuId = menuId;
}
}

Please help me on this topics.

  • 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-10T07:20:56+00:00Added an answer on June 10, 2026 at 7:20 am

    You add flowing command in jsf page:

      <p:tabView id="outputTab" activeIndex="#{ajaxBean.count}">
    

    Change of ajaxBean.java flowing :

      @ManagedBean(name = "ajaxBean")
      @SessionScoped
      public class AjaxBean implements Serializable {
    
      public AjaxBean() {
      }
      private boolean input;
      private List<String> chcekItem = new ArrayList<String>();
      private int count;
    
      public void setAction(String action) {
      input = true;
      if (getChcekItem().isEmpty()) {
        count++;
        getChcekItem().add(action);
        System.out.println("The item " + action + " is Successfully Added to array");
      } else {
    
        for (String abce : getChcekItem()) {
            if (abce.equals(action)) {
                System.out.println(abce + "=" + action);
                input = false;
                //We can jump out of the loop here since we already found a matching value
                break;
            }
        }
    
        if (input) {
            count++;
            getChcekItem().add(action);
            System.out.println("The item " + action + " is Successfully Added to array");
        } else {
            System.out.println("The item " + action + " is Exist");
        }
        }
    
    
       }
        private String close;
    
       public void closeTab(TabCloseEvent closeAction) {
      close = closeAction.getTab().getId();
      for (String abce : getChcekItem()) {
        if (abce.equals(close)) {
            count--;
            System.out.println(close + " is remove from Array");
            getChcekItem().remove(abce);
    
            //We can jump out of the loop here since we already found a matching value
            break;
          }
          }  
          }
    
         public String editAction() {
               return null;
                        }
    
    
            public List<String> getChcekItem() {
               return chcekItem;
               }
    
    
           public void setChcekItem(ArrayList<String> chcekItem) {
               this.chcekItem = chcekItem;
              }
    
    
           public boolean isInput() {
                return input;
              }
    
           public void setInput(boolean input) {
                    this.input = input;
             }
    
           public int getCount() {
               return count-1;
            }
    
    
          public void setCount(int count) {
           this.count = count;
          }
    
         }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a web application project template for everyone to use here
Basically my intention is to create web application. I have to use js, ajax,
I am creating a web application using zend, here I create an interface from
I'm using asp.net membership in my web application. I use website->ASP.net Configuration to create
Create a new ASP.NET MVC Web Application Create an ASP.NET App_Code Folder Inside the
I would like to use Cache for my web application. Here is the question
New ROR programmer here. I'm trying to build a web application that allows a
I'm trying to use EXT JS to create a web application. I followed this
I want to create a web application that allows users to sign up, register
I need to create a web application using php, I had many users having

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.