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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:26:49+00:00 2026-06-04T13:26:49+00:00

I am writing java/spring webapp in which every user can have its own word

  • 0

I am writing java/spring webapp in which every user can have its own word list. Every time when user adds/removes a word then there is a ajax call which sends a JSON with this word to add/delete and when server side is done then there is returned current word list in JSON object to jQuery.

Everything is working ok. For small JSON word list adding and removing is very fast but when word list is getting bigger then ajax calls becomes slower. And adding/removing calls will be very frequent.

Example of JSON word list [polish words]:

 [{"word":"abrys","wordId":646},{"word":"acpan","wordId":647},
 {"word":"akrania","wordId":457},{"word":"akwawita","wordId":648},
 {"word":"amalgamat","wordId":399},{"word":"amurski","wordId":465},
 {"word":"amurskie","wordId":1030},{"word":"ananke","wordId":649},
 {"word":"androlog","wordId":650}]

jQuery [more or less]:

$("#add_word_submit").live("click", function(e) {
    e.preventDefault();
    var word = $('#add_word').serializeObject();
    $.postJSON("word.html", word, function(words) {
        showDividedAccountWords(words);     
    });
});

$(".delete_button").live("click", function(e) {
    e.preventDefault();
    if(confirm(Main.confirmWordDelete)) {
        var wordId = $(this).attr("id").substring("delete_".length);
        wordName["word"] = $(this).children("img").attr("alt");
        $.ajax({
            type: "DELETE",
            url: "word/" + wordId + ".html",
            success: function(words) {
                showDividedAccountWords(words);
            }
        }); 
    }
});

Java/Spring:

@RequestMapping(value="/word", method = RequestMethod.POST)
public @ResponseBody List<Word> addNewWord(@RequestBody Word word, Principal principal) {
    wordService.addNewWord(word, principal.getName());
    return getCurrentWords(principal.getName());
}

@RequestMapping(value="/word/{wordId}", method = RequestMethod.DELETE)
public @ResponseBody List<Word> deleteWord(@PathVariable Long wordId, Principal principal) {
    wordService.deleteWord(wordId, principal.getName());
    return getCurrentWords(principal.getName());
}

public List<Word> getCurrentWords(String username) {
    List<Word> accountWords = new ArrayList<Word>();
    accountWords.addAll(wordService.listUserWords(username));
    return accountWords;
}

Could you please give me some hints to refactor it? Maybe i shouldn’t return a current word list every time user add/removes word?

  • 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-04T13:26:51+00:00Added an answer on June 4, 2026 at 1:26 pm

    To incrementally add word objects to the list, pass the new word to the server and have it return just a single (word:wordid) object. You can then add it to the existing list and sort it as follows:

    var words=[{"word":"abrys","wordId":646},{"word":"acpan","wordId":647},
     {"word":"akrania","wordId":457},{"word":"akwawita","wordId":648},
     {"word":"amalgamat","wordId":399},{"word":"amurski","wordId":465},
     {"word":"amurskie","wordId":1030},{"word":"ananke","wordId":649},
     { "word": "androlog", "wordId": 650}];
    
    
    var result = { "word": "aklina", "wordid": "702" }; // returned by server from AJAX call
    words.push(result); 
    
    words.sort(
      function(a, b) {
        return a.word.localeCompare(b.word);
      }
     );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Java\Spring\Hibernate application - complete with domain classes which are basically Hibernate
I'm writing a small demo application in Java using Spring, that needs to have
I'm writing some simple DAOs in Java using JDBC (no Spring, Hibernate or anything
I am writing java code. which will work on windows and linux. some code
I am writing a Java EE application using Struts and Spring. In one of
I am writing a translator, and have quite a few java String literals that
I'm a C# programmer writing Java (for Android) and have a few technicalities of
I am writing Web app in java using Spring Web MVC framework. Somehow validation
I'm writing a Java program where I have to extract some data from a
I am writing web app for java learning. Using which users may compile their

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.