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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:43:27+00:00 2026-05-27T16:43:27+00:00

I am writing a simple app to enter a user into database & display

  • 0

I am writing a simple app to enter a user into database & display list of users using GWT RPC, Hibernate in Eclipse. The problem I am getting is that the list of users is printed twice.

Here is my code where I call insert user & display users list methods.

package rpctest.client;

import java.util.ArrayList;

import rpctest.shared.User;
import rpctest.shared.FieldVerifier;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.dom.client.KeyPressEvent;
import com.google.gwt.event.dom.client.KeyUpEvent;
import com.google.gwt.event.dom.client.KeyUpHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;

import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.dom.client.KeyPressEvent;
import com.google.gwt.event.dom.client.KeyPressHandler;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class Rpctest implements EntryPoint {

    final TextBox firstName = new TextBox();
    final TextBox lastName = new TextBox();
    final Button ans = new Button("Add User");
    //final Label label1 = new Label("First Name");
    //final Label label2 = new Label("Last Name");
    private FlexTable userFlexTable = new FlexTable();
    //final Label errorLabel = new Label();

    private VerticalPanel mainpanel = new VerticalPanel();
    private HorizontalPanel addpanel1 = new HorizontalPanel();
    private HorizontalPanel addpanel2 = new HorizontalPanel();
    private final RpctestServiceAsync callService = GWT
            .create(RpctestService.class);

    /**
     * This is the entry point method.
     */
    public void onModuleLoad() {

        userFlexTable.setText(0, 0, "User ID");
        userFlexTable.setText(0, 1, "First Name");
        userFlexTable.setText(0, 2, "Second Name");
        userFlexTable.setText(0, 3, "Remove");

        //add input boxes to panel
        addpanel1.add(firstName);
        addpanel1.add(lastName);

        firstName.setFocus(true);

        //add input/result panels 
        mainpanel.add(userFlexTable);
        mainpanel.add(addpanel1);
        addpanel1.add(ans);

        ans.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                        addStock();                 
            }
        });

        lastName.addKeyPressHandler(new KeyPressHandler() {
              public void onKeyPress(KeyPressEvent event) {
                  if (event.getCharCode() == KeyCodes.KEY_ENTER) {
                      addStock();
                  }
                }
              });

        RootPanel.get().add(mainpanel);
        getUser();
    }

private void addStock(){

        String name1 = firstName.getValue();
        // Stock code must be between 1 and 10 chars that are numbers, letters, or dots.
        /*if (!name1.matches("^[0-9A-Z\\.]{1,10}$")) {
          Window.alert("'" + name1 + "' is not a valid name.");
          firstName.selectAll();
          return;
        }*/
         firstName.setValue("");

        String name2 = lastName.getValue();
        /*if (!name2.matches("^[0-9A-Z\\.]{1,10}$")) {
              Window.alert("'" + name1 + "' is not a valid name.");
              lastName.selectAll();
              return;
            }*/
        lastName.setValue("");
        firstName.setFocus(true);

        callService.addUser(name1,name2,
            new AsyncCallback<String>() {
            public void onFailure(Throwable caught) {
                // Show the RPC error message to the user
                    Window.alert("check your inputs");
                }

            @Override
            public void onSuccess(String result) {
            // TODO Auto-generated method stub
                // Add the user to the table.
              //  int row = userFlexTable.getRowCount();
              //  userFlexTable.setText(row, 1, result);
               getUser();
            }
        });
    }

private void getUser(){

    callService.getUser(new AsyncCallback<User[]>() {
            public void onFailure(Throwable caught) {
                // Show the RPC error message to the user
                    Window.alert("Problem in database connection");
                }

            @Override
            public void onSuccess(User[] result) {
                // TODO Auto-generated method stub
                for(int i = 0; i < result.length; i ++)
                    {
                     //String s = result[i].getFirstName();               
                     int row = userFlexTable.getRowCount();
                     userFlexTable.setText(row, 0, result[i].getId().toString());
                     userFlexTable.setText(row, 1, result[i].getFirstName());
                     userFlexTable.setText(row, 2, result[i].getLastName());
                        }                       

            }
        });

      }
}
  • 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-27T16:43:28+00:00Added an answer on May 27, 2026 at 4:43 pm

    getUser is called on every new entry & all data is entered again into table.

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

Sidebar

Related Questions

I'm writing a simple app which allows a user to enter their income and
I'm writing a simple app with AppEngine, using Python. After a successful insert by
I am writing a simple web app using Linq to Sql as my datalayer
I'm writing a simple iPhone app which lets a user access a series of
I'm writing a very simple flash app (AS 2) to sign users up to
I'm looking into writing a simple synchronization ability into my app and one of
I'm writing a simple console client-server app using MSMQ. I'm attempting to run it
I'm writing a simple downloader app which has two activities: SearchActivity: shows a list
I'm writing a very simple CRUD app that takes user stories and stores them
I'm writing a simple app. I need to block user from a page if

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.