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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:08:23+00:00 2026-05-30T01:08:23+00:00

I am creating a webapp in Spring and I faced a problem which is

  • 0

I am creating a webapp in Spring and I faced a problem which is very difficult for me. In my controller I have methods:

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

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

which return JSON object structured like this [this is an example]:

[
 {"word":"battle","wordId":165},
 {"word":"better","wordId":161},
 {"word":"bread","wordId":167},
 {"word":"cool","wordId":158},
 {"word":"fight","wordId":166},
 {"word":"forest","wordId":163},
 {"word":"list","wordId":160},
 {"word":"roll","wordId":164},
 {"word":"semicolon","wordId":168},
 {"word":"super","wordId":139},
 {"word":"thing","wordId":162},
 {"word":"word","wordId":159}
]

and in my jquery file I have a code:

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

function showDividedAccountWords(words) {

var accountWords = new Object();
accountWords.words = words;

wordListTemplate = 
"{{#words}}" +
  "<ul class='word_list'>" +
    "<li class='word'>" +
        "<strong>{{wordId}}: </strong>" +
        "<span>{{word}}</span>" +
    "</li>" +
  "</ul>";
"{{/words}}" +


var accountWordsHTML = Mustache.to_html(wordListTemplate, accountWords);
$("#words").html(accountWordsHTML);
}

When I submit my form by clicking #add_word_submit, jquery sends JSON object [new Word Object] to Spring controller which in return gets current user word list. That current word list is returned as JSON Object [which I pasted above] and next it is used in my mustache.js template.

In general I want to get thorugh ajax automatically refreshed user word list when i add a new word. Until now everything is ok and works very well but I would like to have slightly different output. Now I am getting one ul list:

<ul class="word_list">
  <li class="word"><span>1: Word</span></li> [1]
  <li class="word"><span>1: Word</span></li> [2]
  <li class="word"><span>1: Word</span></li> [3]
  ...
  <li class="word"><span>1: Word</span></li> [13]
</ul>

but I would like have an output that when I get current word list via JSON [like above] I would like to divide it into many ul lists in which there will be only max 10 words. So if I have JSON worlist like above [13 words] I would like to have one list with 10 words and next list with 3 words and so on when there will be more words.

<ul class="word_list">
  <li class="word"><span>1: Word</span></li> [1]
  <li class="word"><span>1: Word</span></li> [2]
  <li class="word"><span>1: Word</span></li> [3]
  ...
  <li class="word"><span>1: Word</span></li> [10]
</ul>

<ul class="word_list">
  <li class="word"><span>1: Word</span></li> [1]
  <li class="word"><span>1: Word</span></li> [2]
  <li class="word"><span>1: Word</span></li> [3]
</ul>

I do not know where is the best way to do it [in Controller or maybe just in jQuery] and how to do it? I would really appreciate some help!

  • 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-30T01:08:24+00:00Added an answer on May 30, 2026 at 1:08 am

    Try this:

    function showDividedAccountWords(words) {
        var wordListTemplate = 
        "{{#words}}" +
          "<ul class='word_list'>" +
            "<li class='word'>" +
                "<strong>{{wordId}}: </strong>" +
                "<span>{{word}}</span>" +
            "</li>" +
          "</ul>" +
        "{{/words}}";
    
        // Take 10 words at a time, until there are no words.
        for(var w = words.splice(0, 10); w.length > 0; w = words.splice(0, 10)) {
            var accountWordsHTML = Mustache.to_html(wordListTemplate, {words: w});
            $("#words").append(accountWordsHTML);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been busy in my project creating a webapp (in struts) that manages
i'm creating a very simple (hello World quality) web application using spring mvc 3.0.
I am using Spring+Hibernate for an operation which requires creating and updating literally hundreds
My Spring-3.0.5/Hibernate-3.3.0 webapp does not store collections. When creating a new persitent object with
I have a Java webapp creating a pdf and streaming it back to the
I have a webapp in which I define the basic dispatcher-servlet context in web.xml
I have very similar spring-security beans configuation to this example . The @Secured annotation
I tried creating a small example using Spring, rest, Hibernate. In order to have
I'm creating a webapp where upon connecting to my server, you will have one
I am creating web app with spring-mvc [Layers: Controller -> Service -> DAO ->

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.