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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T22:13:31+00:00 2026-05-20T22:13:31+00:00

I am trying to use the MVC design. In the model I wanted a

  • 0

I am trying to use the MVC design.

In the model I wanted a method like this

public boolean changeSomeData(...){
    boolean b;
    //create a dialog with an OK button
    return b;
}

I want the method to return TRUE if the changes were actually made. The changes are done inside the actionPerformed method of the OK button.

My problem is that I can’t write b=true; inside the actionPerform of the OK button, because I have to declare b as final in order to use it in the actionPerformed().

What I did is creating a class

private class MyBoolean {
    boolean b;
}

and then

public boolean changeSomeData(...){
    MyBoolean myBoolean;
    //create a dialog with an OK button
    actionPerformed(){
        //make changes in the data
        myBoolean.b=true;
    }
    boolean b = myBoolean.b;
    return b;
}

But I don’t feel good about this solution and I wanted to know if it is correct what I did and if there is a better solution.
Should I better throw an exception if the changes aren’t made? (for example, if the user clicks “cancel” instead of “ok”)

  • 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-20T22:13:31+00:00Added an answer on May 20, 2026 at 10:13 pm

    In the model I wanted a method like this … //create a dialog with an OK button

    I’d say this is a flaw already, since the model should not do anything with views directly.

    A better approach would be to open the dialog (using the controller), register the controller for the ActionEvent of “OK” (and thus actionPerformed) and then do whatever changes should be done in that method.

    Edit:

    You might want to consider the following rough approach:

    The views register themselves or associated classes to the model as listeners. Whenever the model is changed it fires events to notify the views of the change.

    The controller registers itself on the views and is notified when the views change. If a user changes data, the controller then might open the dialog and only commit the changes of the user signals “OK”. Thus the model has never to check itself if data needs to be changed. That is actually the controller’s task and if the controller passes changes to the model, it should apply them.

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

Sidebar

Related Questions

I'm trying to use the T4 templates in my MVC project. This screencast suggests
I am trying to create a web application using the MVC design pattern. For
I'm trying to use ASP MVC 4 and Entity Framework 4 to create pretty
This is probably a simple question, I am trying to use MVC to build
I'm trying to use the MVC design pattern for my project but I'm sort
I'm trying to use MVC for a new project after having been around the
I am trying got use spring-mvc tag inside java-script file, here is what i
I'm working on a PHP web app and I'm trying to use the MVC
I am trying for several days to find a reason to use MVC pattern
I was trying to use RoR or ASP.NET MVC but at my first impression

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.