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

The Archive Base Latest Questions

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

A psuedo controller method @RequestMapping(/foo) public String getFoo(Model model) { model.add(foo, repo.findFoo()); model.add(bar, repo.findBar());

  • 0

A psuedo controller method

@RequestMapping("/foo")
public String getFoo(Model model) {
   model.add("foo", repo.findFoo());
   model.add("bar", repo.findBar());
   model.add("barOptions", repo.findBarOptions(bar));
   return "fooView";
}

Let’s say the client uses Expression language to render foo and bar; but we use JavaScript to render barOptions.

<html>
    <script>
    var options = <mytag:toJSON object="${barOptions}"/>;
    $("#options").renderOptions( options );
    </script>
    <body>
        <mytag:renderFoo foo="${foo}"/>
        <mytag:renderBar foo="${bar}"/>
        <ul id="options"></ul>
    </body>
</html>

Common conventions tells me this is bad. But the essence of MVC, where the controller sends data and the view determines how to use it, tells me this is good. Is there a better way to do the same thing? Is there any reason why this isn’t commonly done? I could request the JSON using a separate call, but then I have to make more requests for the page to load, and there may be logic to determine barOptions in the controller method getFoo() based on other input at the time of the page load.

  • 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-27T10:46:43+00:00Added an answer on May 27, 2026 at 10:46 am

    At first glance I can not say that I see anything blatantly wrong with approach. The only aspect that initially took me off guard was your need to convert data in the model object to json.

    For me, JSON usually implies that there is some sort of server side object that needs to be converted so that a client side javascript can access or manipulate its structure in a javascript way. I guess without knowing more of the purpose of the options list, I can’t see a reason why json serialization is required here.

    By using a Tag to convert a model object to JSON, we avoid an
    additional request made by the client

    But if we assume that JSON is a requirement (perhaps for some third party jquery plugin), then I absolutely do not see anything wrong with approach.

    What is special or different about the barOptions unordered list, why does it have be rendered with json? Why not just use a for loop to build the list items? Or you can have a custom tag that builds out the ul entirely.

    Aside from that, I missing the point as how one may perceive this as being bad code.

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

Sidebar

Related Questions

In a controller I have two values: public List<String> StringValue {get; set;} public List<String>
Environment: ASP.NET MVC3 C# Say I have some repository (semi-psuedo): public interface IRepository {
I would like to be able to do something like (psuedo-code): if (classAvailable) {
I've been refactoring my horrible mess of C++ type-safe psuedo-enums to the new C++0x
in writing a scripting engine, I have functions like (psuedo-code) function is_whitespace?(char c){ return
Pseudo-code: for each x in someArray { // possibly add an element to someArray
I'm wondering if it's possible to conditionally add a parameter in a call to
Can anyone psuedo a solution to my problem, or just give discussion to help
Here's my wild and whacky psuedo-code. Anyone know how to make this real? Background:
I have the following situation: From within a view controller, I go about creating

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.