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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:51:14+00:00 2026-06-05T03:51:14+00:00

I added new tabs that contains input fields. However, for some reason, my managedbean

  • 0

I added new tabs that contains input fields. However, for some reason, my managedbean could only store the values of the latest tab (Example tab 3) that was added. If I were to switch to an earlier tab (Example tab 2), and try to save the values, the stored value always reverts to the input field values of the last tab. There are absolutely no clear solutions on this from searching in the forums, both stackoverflow and primefaces forum. To reiterate, here is a detailed walkthrough:

  1. TabView -> Add new tab (tab 1)
  2. Save t1, f1, c1 under tab 1 (Success)
  3. Add new tab (tab 2)
  4. Add new tab (tab 3)
  5. Save t3, f3, c3 under tab 3 (Success)
  6. Select tab 2
  7. Save t2, f2, c2 under tab 2 (Failed) -> Result: tab 2 values saved as tab 3 values (t3, f3, c3)

    <ui:composition template="/template/StakeholderTemplate.xhtml">
    
        <ui:define name="top">
            <h2>Customer Information Data Entry</h2>
        </ui:define>
    
        <ui:define name="contentInsert">
            <p:ajaxStatus onstart="statusDialog.show();" onsuccess="statusDialog.hide();"/>  
            <p:dialog modal="true" widgetVar="statusDialog" header="Status"   
                      draggable="false" closable="false" resizable="false">  
                <p:graphicImage value="/adminItem/images/ajaxloading.gif" /> 
            </p:dialog> 
    
            <h:form id="form">
    
                <p:growl showDetail="true" /> 
    
                <h:panelGrid columns="1">
    
                    <p:commandButton value="Add tab" process="@this" update="tw" actionListener="#{backMicroPortalMB.addTab}">
                    </p:commandButton>
                    <p:growl id="tabsave" showDetail="true" />
                    <p:tabView id="tw" style="width:100%" activeIndex="#{backMicroPortalMB.activeIndex}" value="#{backMicroPortalMB.unstructuredTabs}"  var="tab"  dynamic="true" cache="false">
                        <p:ajax event="tabChange" process=":form" listener="#{backMicroPortalMB.onTabChange}"/>
    
                        <p:tab title="#{tab.tabTitle}" closable="true">
    
                            <h:outputLabel for="tabTitle" value="Please key in tab title:" />
                            <h:inputText id="tabTitle" value="#{backMicroPortalMB.tab.tabTitle}"/>
                            <br/>
    
    
                            <h:outputLabel for="fieldTitle" value="Please key in field title:" />
                            <h:inputText id="fieldTitle" value="#{backMicroPortalMB.opt.fieldTitle}" /><br/>
    
                            <h:outputLabel for="contentTitle" value="Please key in content:" />
                            <p:editor id="contentTitle" value="#{backMicroPortalMB.opt.content}" width="600"/><br/>
    
                            <p:commandButton value="Save" update="@form" action="#{backMicroPortalMB.saveTab}" />
    
                        </p:tab>  
                    </p:tabView>
                    <p:commandButton id="panel" value="Add" action="#{backMicroPortalMB.createMicroPortal}"/>  
                </h:panelGrid>
            </h:form>
    
        </ui:define>
    
    </ui:composition>
    

Bean code:

@ManagedBean
@ViewScoped
public class BackMicroPortalMB {

public void addTab(ActionEvent action) {

        FacesContext ctx = FacesContext.getCurrentInstance();
        ExternalContext ectx = ctx.getExternalContext();

        String url = "A tab";

        TabView tw = (TabView) ctx.getViewRoot().findComponent("form2:tw");
        TempTab tab = new TempTab();
        tab.setTabIndex(unstructuredTabs.size());
        tab.setTabTitle("new Tab");    
        unstructuredTabs.add(tab);

    }//add new Tab

public void onTabChange(TabChangeEvent event) {

        FacesContext ctx = FacesContext.getCurrentInstance();
        ExternalContext ectx = ctx.getExternalContext();

        TempTab tab = this.unstructuredTabs.get(activeIndex);

        this.tab.setTabTitle(tab.getTabTitle());
        this.opt.setFieldTitle(tab.getOptField().iterator().next().getFieldTitle());
        this.opt.setContent(tab.getOptField().iterator().next().getContent());

        // FacesMessage msg = new FacesMessage("Tab Changed", "Active Tab: " + event.getTab() + this.selectedIndex);  

        // FacesContext.getCurrentInstance().addMessage(null, msg);  
    }

public void saveTab() {

        FacesContext ctx = FacesContext.getCurrentInstance();
        Long stakeholderId = (Long) ctx.getExternalContext().getSessionMap().get("stakeholderId");        
        TempTab currentTab = this.unstructuredTabs.get(activeIndex);
        currentTab.setTabTitle(this.tab.getTabTitle());
        Collection<OptionalField> optFieldList = new ArrayList<OptionalField>();        
        optFieldList.add(this.opt);
        currentTab.setOptField(optFieldList);

        FacesMessage msg = new FacesMessage(tab.getTabTitle() + " Saved!");

        ctx.addMessage(null, msg);
    }//add new Tab   
}

I’ve searched at the PrimeFaces form and the only helpful reply I have got was to google viewscoped and tabview. However, what exactly is the issue here? I’m really new to PrimeFaces and JSF and would really appreciate advice.

PrimeFaces 3.3
JSF 2.1
Glassfish 3.1.2

  • 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-05T03:51:16+00:00Added an answer on June 5, 2026 at 3:51 am

    You’re using a dynamic tabview with a collection of tabs as value and binding all input values of every tab to one and same bean property. During processing the inputs from all tabs, the input values of each tab would override each other in sequence until the last tab is reached and thus the bean ends up with only the values of the last tab.

    You need to bind tab-specific properties to the model object specific to the tab itself, not to a managed bean property which is shared between all tabs. In your case, it’s the #{tab} object. So your <p:tab> content should ultimately end up as

    <h:outputLabel for="tabTitle" value="Please key in tab title:" />
    <h:inputText id="tabTitle" value="#{tab.tabTitle}"/>
    
    <h:outputLabel for="fieldTitle" value="Please key in field title:" />
    <h:inputText id="fieldTitle" value="#{tab.fieldTitle}" /><br/>
    
    <h:outputLabel for="contentTitle" value="Please key in content:" />
    <p:editor id="contentTitle" value="#{tab.content}" width="600"/><br/>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a UITabBarController that has 3 tabs. Each tab contains a UITableViewController. When
I have an android application that currently has 9 tabs. Whenever a new tab
I have a TabControl in a windows form. I have pragmaticly added new tabs
I have a notebook that contains pages with tabs that have close buttons in
I removed my .gitconfig by accident. I added new identies by git add [file]
I added a new file F1 and made changes to another file F2 but
I added a new field to a stored procedure. How do I get it
I added a new subdir within my git respository: git add feeds Then commited
I added a new client-side JS lib (typeAheadDemo.js) to my theme recently, but the
I've accidentally added a new filter to my GAE application. The status of the

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.