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

  • Home
  • SEARCH
  • 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 805959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:10:08+00:00 2026-05-15T00:10:08+00:00

I’m trying to make this 2-player web game application using Spring MVC. I have

  • 0

I’m trying to make this 2-player web game application using Spring MVC. I have session-scoped beans Player and application-scoped bean GameList, which creates and stores Game instances and passes them to Players. On player creates a game and gets its ID from GameList and other player sends ID to GameList and gets Game instance.
The Game instance has its players as attributes. Problem is that each player sees only himself instead of the other one.

Example of what each player sees:

  1. First player (Alice) creates a game: Creator: Alice, Joiner: Empty
  2. Second player (Bob) joins the game: Creator: Bob, Joiner: Bob
  3. First player refreshes her browser Creator: Alice, Joiner: Alice

What I want them to see is Creator: Alice, Joiner: Bob. Easy way to achieve this is saving information about players instead of references to players, but the game object needs to call methods on its player objects, so this is not a solution.

I think it’s because of aop:scoped-proxy of session-scoped Player bean. If I understand this, the Game object has reference to proxy, which refers to Player object of current session. Can Game instance save/access the other Player objects somehow?

beans in dispatcher-servlet.xml:

<bean id="userDao" class="authorization.UserDaoFakeImpl"  />
<bean id="gameList" class="model.GameList" />
<bean name="/init/*" class="controller.InitController" >
     <property name="gameList" ref="gameList" />
     <property name="game" ref="game" />
     <property name="player" ref="player" />
</bean>
<bean id="game" class="model.GameContainer" scope="session">
      <aop:scoped-proxy/>
</bean>
<bean id="player" class="beans.Player" scope="session">
      <aop:scoped-proxy/>
</bean>

methods in controller.InitController

private GameList gameList;
private GameContainer game;
private Player player;
public ModelAndView create(HttpServletRequest request,
        HttpServletResponse response) throws Exception {        
    game.setGame(gameList.create(player));        
    return new ModelAndView("redirect:game");
}
public ModelAndView join(HttpServletRequest request,
        HttpServletResponse response, GameId gameId) throws Exception {
    game.setGame(gameList.join(player, gameId.getId()));       
    return new ModelAndView("redirect:game");
}

called methods in model.gameList

public Game create(Player creator) {        
    Integer code = generateCode();        
    Game game = new Game(creator, code);
    games.put(code, game);
    return game;
}
public Game join(Player joiner, Integer code) {
    Game game = games.get(code);
    if (game!=null) {
        game.setJoiner(joiner);           
    }
    return game;
}
  • 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-15T00:10:09+00:00Added an answer on May 15, 2026 at 12:10 am

    I believe you are right about the proxy being why you see only yourself. Any reference to the proxy will apply to only the object in your session.

    Do you need to have the game and
    player as session scoped? The fact
    that you are trying to use them
    across sessions indicates
    that they are not session scoped data. You could just create them from a factory and store their references in a session scoped bean.

    Alternatively, if you do want the player to be session scoped, you could wrap a reference to a prototype in a session bean. You can then use the prototype reference for your cross session data, and the session bean for any session specific local data.

    There are several ways to resolve this, but in essence you need to move your cross session data out of the session scoped beans and into an application scope bean which can be shared.

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

Sidebar

Ask A Question

Stats

  • Questions 449k
  • Answers 449k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It happens to be the hex representation of the initials… May 15, 2026 at 8:14 pm
  • Editorial Team
    Editorial Team added an answer You can use the setId() method that will allow you… May 15, 2026 at 8:14 pm
  • Editorial Team
    Editorial Team added an answer dialog() moves the element you're passing to it, so that… May 15, 2026 at 8:14 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.