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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:20:58+00:00 2026-05-25T23:20:58+00:00

I am using: JSF 2.0, GlassFish Server 3.0. The backing bean: @ManagedBean(name = Users)

  • 0

I am using: JSF 2.0, GlassFish Server 3.0.

The backing bean:

@ManagedBean(name = "Users")
@ViewScoped
public class ModelUsers {

    /** Creates a new instance of ModelUsers */
    public ModelUsers() {
        System.out.println("-----------------------------");
        System.out.println("Invoked Contructor !");
        System.out.println("Page = " + page);
        System.out.println("Item per page = " + itemPerPage);
    }

    // ... Getter/setter...    

    public void actionReload(ActionEvent action) {
        System.out.println("Clicked !");
        loadData();
    }

    public void actionChangePage(ActionEvent action) {
        System.out.println("Clicked !");
        boolean isLoad = false;
        int p = 0;
        try {
            p = Integer.parseInt(Until.getActionAttribute(action, "page").toString());
        } catch (Exception ex) {
        }
        int i = 0;
        try {
            i = Integer.parseInt(Until.getActionAttribute(action, "itemPerPage").toString());
        } catch (Exception ex) {
        }
        if (p != 0 && p != page) {
            isLoad = true;
            page = p;
        }
        if (i != 0 && i != itemPerPage) {
            isLoad = true;
            itemPerPage = i;
        }
        if (isLoad) {
            System.out.println("Load by change page or number of items");
            loadData();
        }
    }
    /** Parameter here */
    private int page = 1;
    private int totalCount = 1;
    private int itemPerPage = 10;
    private boolean isLoaded = false;
    private List<User> listUsers = null;

    private void loadData() {
        isLoaded = true;
        System.out.println("Loading Data with : page = " + page + " and " + itemPerPage + " record(s)");
// Load Data from DataBase ...//

        System.out.println("Load done!");
    }
}

The Until class:

public static String getRequestParameter(String key) {
        return FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get(key);
    }

The view:

<h:form id="pannel">         
    <h:panelGroup id ="controlPannel">
            Page:  <h:outputLabel id="page" value="${Users.page}"/><br/>                                
                Item per page: <h:inputText id ="item" value="#{Users.itemPerPage}" />
                Page: <h:inputText value="#{Users.page}" />
                <h:commandButton actionListener="#{Users.actionReload}" value="Go">
                    <f:ajax  render="pannel" execute="page item"/>
        </h:commandButton> <br/>
        <h:commandButton actionListener="#{Users.actionChangePage}" value="Previous">
            <f:ajax render="pannel"/>
                        <f:attribute name="itemPerPage" value="${Users.itemPerPage}"/>
                        <f:attribute name="page" value="${Users.page-1}"/>
        </h:commandButton>
                <h:commandButton actionListener="#{Users.actionChangePage}" value="Next" >
            <f:ajax render="pannel"/>
                        <f:attribute name="page" value="${Users.page+1}"/>
                        <f:attribute name="itemPerPage" value="${Users.itemPerPage}"/>
        </h:commandButton>
    </h:panelGroup>
    <table>
        <c:forEach items="${Users.usersList}" var="item">
            <tr>
                    <td>${item.UId}</td>
                        <td>${item.UName}</td>
                </tr>
    </c:forEach>
    </table>
</h:form>

I want the Model should load the #{Users.usersList} the first time only. Now, when my app runs and with someone click to change pages or something else, it prints as follows:

// After change the value in text box to 1 and 112, i got this:
INFO: -----------------------------
INFO: Invoked Contructor !
**INFO: Page = 1
INFO: Item per page = 10
INFO: Load data by get list user...
INFO: Loading Data with : page = 1 and 10 record(s)**
INFO: Load done!
INFO: Clicked !
INFO: Page = 1
INFO: Item per page = 112
INFO: Loading Data with : page = 1 and 112 record(s)
INFO: Load done!

How can I load the data without loading the initial page 1 with 10 records?

  • 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-25T23:20:59+00:00Added an answer on May 25, 2026 at 11:20 pm

    The view scoped bean constructor should not be invoked whenever you submit a form in the same view. The all initial properties should be retained in a view scoped bean. Your view scoped bean is recreated on every request because you’re binding a <c:forEach> attribute to it. The <c:forEach> is a tag handler, not a real JSF component like <h:dataTable>.

    Replace it accordingly:

    <h:dataTable value="#{Users.usersList}" var="user">
        <h:column>#{user.UId}</h:column>
        <h:column>#{user.UName}</h:column>
    </h:dataTable>
    

    See also:

    • @ViewScoped fails in tag handlers
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using JSF 2.0 with GlassFish 3.0. I have the following Managed Bean: @ManagedBean
I'm using JSF 2.0 with Facelets in a Java EE 6 application server (GlassFish
I'm using Glassfish 3.1.1 and JSF 2.0: I have the following code: public String
I'm using JSF 2.0 and EJB 3.1 in the Glassfish v3 app server. And
I'm developing a web application using JSF 2.0, NetBeans 6.9.1, GlassFish Server 3.1, mojarra
I have a Java application runnning on a Glassfish server using JSF 2.0.2. at
I'm using JSF 2.0 and it's new (actually old, but now incorporated in JSF)
How do I connect to the database(MYSQL) in connection bean using JSF to retrieve
I want to dynamically create controls in my bean. I am using JSF 2.0
My server is glassfish v3, my browser is firefox 3.6.3 and i am using

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.