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 7011323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:06:44+00:00 2026-05-27T22:06:44+00:00

Primefaces tabView activeIndex property is always getting null. My view.jsf: <h:form> <p:growl id=growl showDetail=true

  • 0

Primefaces tabView activeIndex property is always getting null.

My view.jsf:

<h:form>
<p:growl id="growl" showDetail="true" />
<p:tabView >
<p:ajax event="myForm" listener="#{employeeEdit.onTabChange}" /> 
<p:tab id="basic" title="Login">
</p:tab>
<p:tab id="personal" title="Personal">
</p:tab>
<p:tab id="contact" title="Contact">
</p:tab>
</p:tabView>

My edit.jsf:

<h:form prependId="false" >
<p:tabView id="myid" activeIndex="#{employeeEdit.tabIndex}" >
<p:tab id="basic" title="Login">
</p:tab>
<p:tab id="personal" title="Personal">
</p:tab>
<p:tab id="contact" title="Contact">
</p:tab>
</p:tabView>

Backing bean:
EmployeeEdit.java:

@Component("employeeEdit")
@ViewScoped
@Repository
public class EmployeeEdit implements Serializable{

    /**
     * 
     */
    private static final long serialVersionUID = -2784529548783517864L;
    private EmployeeDTO employeeDTO = new EmployeeDTO();
    public static HibernateTemplate hibernateTemplate;
    private int tabIndex;   

    @Autowired
    public void setSessionFactory(SessionFactory sessionFactory)
    {
        System.out.println("in SessionFactory" +sessionFactory);
        this.hibernateTemplate = new HibernateTemplate(sessionFactory);
        System.out.println("in SessionFactory" +hibernateTemplate);

    }


    public int onTabChange(TabChangeEvent event) {   

        System.out.println("tab id = " + event.getTab().getId()+event.getTab().getTitle());
        if(event.getTab().getId().equals("personal"))
        {
            tabIndex =0;
        }
        else if(event.getTab().getId().equals("address"))
        {
            tabIndex =1;
        }
        else
        {
            tabIndex =2;
        }
        System.out.println("tabIndex = "+tabIndex);
        return tabIndex;
    }



    public void edit() throws IOException
    {

        FacesContext.getCurrentInstance().getExternalContext().redirect("/employeeedit.jsf");
    }



    public void cancel() throws IOException
    {
        FacesContext.getCurrentInstance().getExternalContext().redirect("/employeelist.jsf");
    }

    public EmployeeDTO getEmployeeDTO() {
        return employeeDTO;
    }

    public void setEmployeeDTO(EmployeeDTO employeeDTO) {
        this.employeeDTO = employeeDTO;
    }

    public int getTabIndex() {
        return tabIndex;
    }

    public void setTabIndex(int tabIndex) {
        this.tabIndex = tabIndex;
    }
}

But always getting tabIndex=0; Why this happening? The AJAX is working fine. But on clicking the Edit button in the view page tabIndex is getting null.
in view.jsf, my command button is

<p:commandButton value="Edit" actionListener="#{employeeEdit.edit}" />

My primefaces version is: primefaces-3.0.M3 with Google Cloud SQL

  • 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-05-27T22:06:45+00:00Added an answer on May 27, 2026 at 10:06 pm
    public void edit() throws IOException {
        FacesContext.getCurrentInstance().getExternalContext().redirect("/employeeedit.jsf");
    }
    

    Your edit method above, redirects to a new view, that’s when your @ViewScoped managed bean EmployeeEdit is destroyed. So, when it is instantiated again, the tabIndex is initialized to 0 (since 0 is the default value for ints in Java.)

    As the name suggests @ViewScoped is good for one view, when want to some PPR on the same view. So, it is destroyed when you redirect to some other view.

    In such a case, you can use @SessionScoped, which lasts as long as the session lasts.

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

Sidebar

Related Questions

I'm working with JSF and PrimeFaces and I am using Facelets as view technology.
I'm using JSF Primefaces 3.0.M3. When I submit (Save) a form some of the
I'm using primefaces 3.1 Tabview with dynamic = true is not working with viewscope.
I am using PrimeFaces <p:dataTable> with pagination. I use <h:selectBooleancheckbox> with a Map property
I am working in primefaces 3.3 and jsf 2.0. I have problem in deleting
I am doing a project where I am using JSF 2.0 & Primefaces UI
In my JSF 2 - Primefaces 3 web application, I am using <p:panelGrid> and
I am using Primefaces 3.3 with JSF 2.0 and I tried to include Jquery
I need to use jQuery and jQuery UI in JSF template pages, however, Primefaces
I have a primefaces datatable: <p:dataTable id=idCrawledDataTable var=crawledData value=#{crawlerCorpusTreatmentBean.crawledDataModel} rowKey=#{crawledData.id} rows=10 scrollable=true scrollHeight=300 selection=#{crawlerCorpusTreatmentBean.crawledData}

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.