MVC Help

Hi
I am new to designing, I am not able to confirm whether my design explained below is a valid or proper one, should I improve in any other place.
M - Stateless session bean having methods for insert, update, delete, view,
V - Jsps, html, js, images
C - A single servlet for a single JSP
Sample
addUserGroup.jsp on submit it redirects to UGACtrler populates javabean UsrGrp and instantiates UserGroupBean ejb and calls the corresponding method for inserting or updating.
updateUserGroup.jsp on submit it redirects to UGUCtrler populates javabean UsrGrp and instantiates UserGroupBean ejb and calls the corresponding method for inserting or updating.
and it goes for all database operations.
Please suggest me whether this is a proper way of doing it.
regards

Hi
In My design I used one jsp for one functionality and one servlet for each jsp as controller for that functionality and an EJB for all the functionalities. I saw more servlets coming into picture but I felt it will be easy to maintain and code also. I feel like if one servlet is used for all the functionalities, maintaining the code I felt it will be difficult.
addUser.jsp -> addUserServlet controller -> User EJB (create method)
viewUser.jsp -> ViewUserServlet controller -> User EJB (view method)
... etc
Any comments on this design is welcome. I will also learn something if this design in purely wrong.
regards

Similar Messages

  • Sun ClassDiagram

    Hi,
    In designing a class diagram, structural(abstract,façade,flyweight eg) and creational(builder, factory) design pattern are captured in class diagram right? then component diagram to capture behavioural(controller, dispatcher etc) design pattern?
    I read on one of the forums that class diagram are not mean to be technical but are suppose to capture Object relationship. eg, Class, students
    Then using the component diagram, we capture the design eg, mvc, helper etc
    Refering to the Mark Cade book for SCEA, the case study seem to imply that this is right.
    Please advice
    Thank you

    jduprez wrote:
    Based on your posting history, I would expect that in your company (I was about to say, in your projects, but that sounds too much like flattery), design documents are maintained and kept up-to-date.No idea what point you are attempting to make.Among the regulars on this forum you are the most constant, sincere, and I must admit, convincing, advocate of having good process control in software making. I therefore assume your company/entity is doing it right, and your posting suggest that the right approach is #3.
    I wish. I have never even interviewed nor talked to anyone that has worked at a company that did it correctly.
    I used to be a strong advocate and actively promoted but finally gave up after the company I was at was bought and the process control group was disbanded because process control 'confused' the developers at the company that bought us. That was the specific reason I was given for getting rid of the group.
    I was posting what the industry is like.I'm not in a position to know the industry as a whole, even limited to my region, but based on what I've seen I have no reason to disagree.
    Maybe I was incorrect to use the somewhat pretentious expression "industrial perspective": I wanted to oppose "UML diagrams showing how patterns work"and "UML diagrams showing how a certain program uses or will use patterns".
    As an "industrial" software engineer, and despite being in the wrong 999 out of 1000, I have used UML diagrams quite often. I acknowledge that they were often not maintained until the actual software release, and practically not maitained after the release. I'm still glad to have written or read them, as they provided value even at early stages.
    I use UML and I create formal designs as well. In something like the last four companies I have been at I am the only one to do so as far as I can recall.
    I was posting what the industry is like. Certainly in the US. The average developer is unlikely to ever be even close to a company that has stringent process control (...)which is actually meaningful (think CMM level 3 or higher.) The reason for that is because so few companies even attempt it in the world. Many companies don't do process control at all in any coherent manner. Quite few claim to follow a process but the practical reality is that they produce documents solely because it is required rather than to provide benefit.Now is my turn to wonder what your point is.
    I agree with the general idea that process control is undervalued and underused.
    Do you mean that without good process control, UML models will necessarily become inconsistent?
    Do you mean that the fact that they will eventually decay makes UML models useless altogether?After re-reading what I was really doing was generalizing too much from your comment. I probably saw the "industrial perspective" and drove (jumped wildly) right to process control.

  • MVC Design Help, Single Servlet, How do I access the Model and DB

    Hi all. New here and looking for some help.
    I am currently writing a website that allows the creation of users, that may upload articles and post comments on articles. Im trying to develop using MVC. I have a single controller servlet that processes POST actions throughout the site (eg. InsertArticle, DeleteArticle, ModifyArticle, etc..)
    Now my problem is, just how do I retrieve the articles from the database? .. for example, if I load up a page http://localhost/articles.jsp which should display all the articles currently in the site.. I would have a function say getAllArticles() which should return a collection of all the articles. I can then iterate through the articles in the jsp page.
    I am trying to use <jsp:useBean...etc.> BUT.. my articles bean constructor takes a databaseconnection object as a parameter. If I use useBean I cant pass the databaseconnection object to the bean and I get an error because it cannot create the bean.
    Any help on this would be appreciated as well as any tutorial links. I also looked at the petstore blueprint program on the sun website, but that program has me completely lost with all the xml. I would prefer not to use custom tags or struts for now. I would like to keep it simple with snippets of java code in the jsp pages for data retrieval and display while keeping all the business logic in the beans of the model. I would also like to keep this relatively secure. I am developing using Oracle Jdeveloper 10g.
    Thanks
    Jazz

    Hey steve, thanks for that.. but thats exactly what i
    dont want to do. I also realize that ive been writing
    the ejb's incorrectly to begin with and have begun to
    rewrite them. However maybe I can make it easier..
    what im trying to do is precisely what is in this
    diagram..
    http://gsraj.tripod.com/jsp/jsp.html
    the problem im having is where it passes data back to
    the jsp page.. entity beans cant (or shouldnt?) be
    accessed directly from jsp pages.. which means i
    create a session bean which interacts with the entity
    bean and can return information to the jsp page.. i
    understand what i have to do.. i just dont know how to
    do it.. been searching for google for tutorials and
    etc.. this site is the closest ive come but .. as you
    can see it says "more to come" ..
    thanks again guys really appreciate itAhhh. EJBs. Enterprise Java Beans and JavaBeans are two completely different beasts. I know nothing about EJBs, except:
    1) They are much harder to use (and serve a different purpose I assume) then JavaBeans
    2) Tomcat (the server I use) doesn't support them.
    Sorry I can't be of more help.

  • How to program navigation in a MVC application? (help please!!)

    Hi,
    I´m exploring how to develop a BSP application with MVC.
    SO far I have a ´page´ composed by a controller, 2 or more sub-controllers and their respective views.
    But I want an application consisting of many pages.. So here I am, in my DO_HANDLE_EVENT method wandering what to do when I want to redirect the user to a new page. I guess there´s two options here:
    1) change the subcontrollers/views for the new one. (using controller_set_active or controller_delete..?)
    2) redirecting to the new page with navigation->goto_page( 'page2.do' ).
    I like the second option, but there´s a problem: all my model instances die!! How can I keep them alive? How can I keep data (objects) alive from the moment a user opens the first page till he logs off the aplication??
    (I tried using the application class, but I just can´t access it using MVC, guess it´s only available from pages with flow logic)
    I truly need a hint on this! Any suggestions are most welcomed!

    Hi Mariana,
    I think the most important advice is to never jump
    directly via goto_page(). As you have noted, this way
    you lose your context. Myself I use the following
    approach:
    1) There is a strict controller hierarchy. The topmost
       controller holds your application data.
    2) In the view of the topmost controller its
       subcontrollers are called via
          <bsp:call url="sub.do" comp_id="yourchoicehere" >
                   <bsp:parameter name = "mode"
                                  value = "<%=mode%>" />
          </bsp:call>
       where "mode" is an attribute of the view which holds
       the information in which state of processing your
       application is.
    3) In the controllers in the DO_REQUEST methods
       you call its views by
       dispatch_input( ).
       l_main_view = create_view( view_name = 'main_view.htm' ).
      l_main_view->set_attribute( name = 'mode' value = mode ).
      call_view( l_main_view ).
      The dispatch_input method is only needed in the
      topmost controllers.
    4) Navigation is done by events which are passed
       automatically to the DO_HANDLE_EVENT method of
       the controller.
       IF htmlb_event IS BOUND.
          CASE htmlb_event->server_event.
            WHEN 'YOUREVENTHERE'.
    5) To understand how things work you should set
       breakpoints in all DO_HANDLE_EVENT and DO_REQUEST
       methods. You will see how events got passed upwards
       the controller hierarchy and how controllers call
       their subcontrollers.
    6) Further hint: Pass all parameters by controller
       and view attributes.
    Hope that helps.
    Joachim

  • F4 help... in MVC

    Hi,
    How to use F4 help in MVC architecture.
    Regards,
    Reema.

    Hve you tried Thomas Jung's weblog on (MVC based)
    <a href="/people/thomas.jung3/blog/2005/08/22/bsp-value-input-help-popups-version-30">BSP Value Input Help Popups Version 3.0</a>
    Regards
    Raja

  • Help on MVC programming model

    Hey,
    I've searched the web over and over on MVC models, and so far what I can find on MVC models is abstract texts without hands-on examples.
    Some do have examples, but they are scattered, and I get confused.
    I've looked over MVC on Java site, and kinda got the picture, yet also got overwhelmed by all the info.
    Is MVC something the programmer has to do, or is it more or less automated by an IDE ? As I understand so far MVC is a product of conscious programming, and there are no automated tools.., yet some websites sound that there are tools that help you build in MVC.
    Is there a hands-on tutorial or a simple example on what MVC actually is ?
    thanks !
    Dennis

    http://www.javaworld.com/javaworld/jw-04-1998/jw-04-howto.html

  • Please Help For the Spring MVC Framework

    Someone please give me some file that represent the example of implementation of Spring MVC Framework.

    User,
    I read your post and had one word pop to mind: "huh?"
    Perhaps [url http://catb.org/~esr/faqs/smart-questions.html]this and [url http://www.oracle.com/technology/products/jdev/howtos/1013/SpringwithJDev/index.html]this will be helpful to you.
    John

  • Help for F4 help using MVC

    Hello Friends,
         Can anyone help me to implement F4 Help for input field  Using MVC?   I have created 2 views , one for Input field and other for F4 Help Pop-up. This two Views has there respective controllers and one model class.
    can anybody provide some sample code?

    Hi vinay
    Search in sdn you can find solution.
    Check the following link
    [F4 help using MVC|https://help.sap.com/saphelp_sem320bw/helpdata/en/fb/fbb84c20df274aa52a0b0833769057/frameset.htm]
    Hope thi shelps you
    Regards,
    Rajani

  • Need routing Help in MVC urgent

    I have created a mvc application where i have addedd my deafult page in the application which is not in view foler.Now i want to make that as start up page .I can make that in visula studio but when i publish that in iis it doesnt work.It goes to
    global.asax and makes the routing to the deafult on 
     routes.MapRoute(
                   "Default", // Route name
                   "{controller}/{action}/{id}", // URL with parameters
                   new { controller = "Account", action = "LogOn", id = UrlParameter.Optional } // Parameter defaults
    But i want my start up page to be like this http://www.sn-infotech.com/default.aspx..
    I changed in web.config also like this 
     <authentication mode="Forms">
          <forms name="UrlDirect" defaultUrl="default.aspx" path="/">
          </forms>
          <!--<forms loginUrl="~/Account/LogOn" timeout="2880"/>-->
        </authentication>
    Still its not working...I cant find any solution to it.
    Woulkd anyone please help that would be really nice.
    Thanks
    Sam

    Hello,
    Specifically, this should be asked in the
    ASP.Net MVC forum on
    forums.asp.net.
    Karl
    When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer.
    My Blog: Unlock PowerShell
    My Book: Windows PowerShell 2.0 Bible
    My E-mail: -join ('6F6C646B61726C40686F746D61696C2E636F6D'-split'(?<=\G.{2})'|%{if($_){[char][int]"0x$_"}})

  • MVC DataSet to Model Help Needed

    Primary Question:  I need help to efficiently go from a dataset directly into a model (not a list).  
    I know the code for generating a list to model, but I can't find an efficient way to just input the first matching record into the model.  
    Any help is appreciated!
    Below is the code that works, but is very inefficient.  The inefficiency is causing problems because I need to program a lot of data retrieval while I'm rewriting the whole system.
    Bonus Question...  I can't get the list result to sort by UPPER(lastname).  It generates the error 
    Error [42S22] [Microsoft][ODBC Visual FoxPro Driver]SQL: Column " is not found.
    // CODE THAT WORKS BUT IS WAY TO INEFFICIENT
                Studrec model = new Studrec();
                DataSet dataset = new DataSet();
                string Path2File = "Provider=MSDASQL/SQLServer ODBC;Driver={Microsoft Visual FoxPro Driver};SourceType=DBF;Exclusive=No;Collate=Machine;NULL=NO;DELETED=YES;BACKGROUNDFETCH=NO;SourceDB=\\\\LocalServer\\Students\\DBFS";
                using (OdbcConnection cn = new OdbcConnection(Path2File))
                    var sql = "select studid, first, lastname,grade,homeschl,lastname,birthday,address,address2,program,city,state,zip,phone,sex,specneeds,allergies,medical,lifethreat,c1lastname,c1frstname,c1relat,c1hmphone,c1wkphone,c1cell,c1canpup,c2lastname,c2frstname,c2relat,c2hmphone,c2wkphone,c2cell,c2canpup,c3lastname,c3frstname,c3relat,c3hmphone,c3wkphone,c3cell,c3canpup,c4lastname,c4frstname,c4relat,c4hmphone,c4wkphone,c4cell,c4canpup,c5lastname,c5frstname,c5relat,c5hmphone,c5wkphone,c5cell,c5canpup
    from studrec.dbf order by lastname, first where studid like '%" + @studId.Trim() + "%'"; 
                    using (OdbcCommand cmd = new OdbcCommand(sql, cn))
                    cn.Open();               
                    OdbcDataAdapter DataAdapter = new OdbcDataAdapter(cmd);
                    DataAdapter.Fill(dataset); 
                        List<Studrec> student = dataset.Tables[0].AsEnumerable().
                              Select(dataRow => new Studrec()
                                  StudId = dataRow.Field<string>("studid"),
                                  First = dataRow.Field<string>("first"),
                                  LastName = dataRow.Field<string>("lastname"),
                                  Grade = dataRow.Field<string>("grade"),
                                  Homeschl = dataRow.Field<string>("homeschl"),
                                  Address = dataRow.Field<string>("address"),
                                  City = dataRow.Field<string>("city"),
                                  State = dataRow.Field<string>("state"),
                                  Zip = dataRow.Field<string>("zip"),
                                  Prog = dataRow.Field<string>("program"),
                                  Phone = dataRow.Field<string>("phone"),
                                  Sex = dataRow.Field<string>("sex"),
                                  Birthday = dataRow.Field<string>("birthday"),
                              }).ToList();
                              //}).FirstOrDefault();   // THIS DOESN'T WORK
    //THIS IS MY WORK AROUND
                        model.StudId= student.First().StudId;
                        model.First=student.First().First;
                        model.LastName=student.First().LastName;
                        model.School=student.First().School;
                        model.Grade=student.First().Grade;
                        model.Address = student.First().Address;
                        model.City = student.First().City;
                        model.State = student.First().State;
                        model.Phone = student.First().Phone;
                        model.Sex = student.First().Sex;
                        model.Birthday = student.First().Birthday;                

    Hello,
    Specifically, this should be asked in the
    ASP.Net MVC forum on forums.asp.net.
    Karl
    When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer.
    My Blog: Unlock PowerShell
    My Book: Windows PowerShell 2.0 Bible
    My E-mail: -join ('6F6C646B61726C40686F746D61696C2E636F6D'-split'(?<=\G.{2})'|%{if($_){[char][int]"0x$_"}})

  • Help on getting started with Spring MVC, WebFlow; Where can it be applied ?

    I'm an individual programmer, developer and I see a huge demand (at the corporate level) for the frameworks: Spring, Spring MVC, webflow, and Hibernate. Popular today: Spring MVC, webflow, GWT.
    I've been going through the tutorials, and the technology looks awesome ! What I would like to know, is.. It's used in corporate sites, why not for smaller sites. How can I apply these frameworks in building websites ?
    I can't imaging doing any kind of serious website building without a modern CMS or Portal framework (whether in Java/php-opensource), And yes, MVC gives you the validation and authentication hooks to be used.
    The spring framework, with it's extensive scope, is a bit overwhelming, and implies that there could be a significant amount of architecture, design and planning time needed before starting implementation on a project
    All the demo's on Spring, cover some elementary, contrived example.
    If I learn these technologies (and I'm well on my way), how do I put them into practice, and in what context (no pun intented) do I use them ? I don't want to rebuild a CMS system, but I'd like to employ these frameworks effectively.

    user1944443 wrote:
    The spring framework, with it's extensive scope, is a bit overwhelming, and implies that there could be a significant amount of architecture, design and planning time needed before starting implementation on a projectYes, usually there is. Unless you're using the frameworks to build a home page for your kittens. Then you usually don't need to put that much effort into it.
    All the demo's on Spring, cover some elementary, contrived example.I'm sure you realize that they have to. There's no "follow these examples and you'll become a competent programmer" method of learning invented yet and frameworks usually need to document the basic cases extensively.
    If I learn these technologies (and I'm well on my way), how do I put them into practice, and in what context (no pun intented) do I use them ? I don't want to rebuild a CMS system, but I'd like to employ these frameworks effectively.You'll just need to come up with a project you'll be interested in finishing or at least developing for a while.
    I'm not sure whether I managed to answer your question or not, but if anything was left unclear, just ask.

  • Can U help me change "Paint.java" to MVC model

    import java.awt.*;
    import java.applet.*;
    import java.awt.event.*;
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JScrollBar;
    import javax.swing.JTextField;
    import javax.swing.ImageIcon;
    public class Paint extends Applet implements ActionListener, AdjustmentListener, MouseListener, MouseMotionListener
    private static final long serialVersionUID = 1L;
    private final int NO_OP = 0;
    private final int PEN_OP = 1;
    private final int LINE_OP = 2;
    private final int ERASER_OP = 3;
    private final int CLEAR_OP = 4;
    private final int RECT_OP = 5;
    private final int OVAL_OP = 6;
    private final int FRECT_OP = 7;
    private final int FOVAL_OP = 8;
    private final int SPLINE_OP = 9;
    private final int POLY_OP = 10;
    private int mousex = 0;
    private int mousey = 0;
    private int prevx = 0;
    private int prevy = 0;
    private boolean initialPen = true;
    private boolean initialLine = true;
    private boolean initialEraser = true;
    private boolean initialRect = true;
    private boolean initialOval = true;
    private boolean initialFRect = true;
    private boolean initialFOval = true;
    private boolean initialPolygon = true;
    private boolean initialSpline = true;
    private int Orx = 0;
    private int Ory = 0;
    private int OrWidth = 0;
    private int OrHeight = 0;
    private int drawX = 0;
    private int drawY = 0;
    private int eraserLength = 5;
    private int udefRedValue = 255;
    private int udefGreenValue = 255;
    private int udefBlueValue = 255;
    private int opStatus = PEN_OP;
    private int colorStatus = 1;
    private Color mainColor = new Color(0,0,0);
    private Color xorColor = new Color(255,255,255);
    private Color statusBarColor = new Color(166,166,255);
    private Color userDefinedColor = new Color(udefRedValue,udefGreenValue,udefBlueValue);
    private JButton penButton           = new JButton(new ImageIcon(getClass().getResource("pen.gif")));
    private JButton lineButton           = new JButton(new ImageIcon(getClass().getResource("line.gif")));
    private JButton eraserButton           = new JButton(new ImageIcon(getClass().getResource("eraser.gif")));
    private JButton clearButton = new JButton("Clear");
    private JButton rectButton           = new JButton(new ImageIcon(getClass().getResource("rec.gif")));
    private JButton ovalButton           = new JButton(new ImageIcon(getClass().getResource("oval.gif")));
    private JButton fillRectButton      = new JButton(new ImageIcon(getClass().getResource("fillrec.gif")));
    private JButton fillOvalButton      = new JButton(new ImageIcon(getClass().getResource("filloval.gif")));
    private JButton splineButton = new JButton("Spline");
    private JButton polygonButton = new JButton("Polygon");
    private JButton blackButton = new JButton("Black");
    private JButton blueButton = new JButton("Blue");
    private JButton redButton = new JButton("Red");
    private JButton greenButton = new JButton("Green");
    private JButton purpleButton = new JButton("Purple");
    private JButton orangeButton = new JButton("Orange");
    private JButton pinkButton = new JButton("Pink");
    private JButton grayButton = new JButton("Gray");
    private JButton yellowButton = new JButton("Yellow");
    private JButton userDefButton = new JButton("User-Def");
    private JScrollBar redSlider = new JScrollBar(Scrollbar.HORIZONTAL, 0, 1, 0, 255);
    private JScrollBar blueSlider = new JScrollBar(Scrollbar.HORIZONTAL, 0, 1, 0, 255);
    private JScrollBar greenSlider = new JScrollBar(Scrollbar.HORIZONTAL, 0, 1, 0, 255);
    private JTextField colorStatusBar = new JTextField(20);
    private JTextField opStatusBar = new JTextField(20);
    private JTextField mouseStatusBar = new JTextField(10);
    private JTextField redValue = new JTextField(3);
    private JTextField greenValue = new JTextField(3);
    private JTextField blueValue = new JTextField(3);
    private JLabel operationLabel = new JLabel(" Tool mode:");
    private JLabel colorLabel = new JLabel(" Color mode:");
    private JLabel cursorLabel = new JLabel(" Cursor:");
    private JPanel ToolbarPanel = new JPanel(new GridLayout(11,2,0,0));
    private JPanel drawPanel = new JPanel();
    private JPanel statusPanel = new JPanel();
    private JPanel udefcolPanel = new JPanel(new GridLayout(3,3,0,0));
    private JPanel udefdemcolPanel = new JPanel();
    private JPanel PicPanel               = new JPanel();
    public void init()
    setLayout(new BorderLayout());
    ToolbarPanel.add(blackButton);
    ToolbarPanel.add(blueButton);
    ToolbarPanel.add(redButton);
    ToolbarPanel.add(greenButton);
    ToolbarPanel.add(purpleButton);
    ToolbarPanel.add(orangeButton);
    ToolbarPanel.add(pinkButton);
    ToolbarPanel.add(grayButton);
    ToolbarPanel.add(yellowButton);
    ToolbarPanel.add(userDefButton);
    blueButton.setBackground(Color.blue);
    redButton.setBackground(Color.red);
    greenButton.setBackground(Color.green);
    purpleButton.setBackground(Color.magenta);
    orangeButton.setBackground(Color.orange);
    pinkButton.setBackground(Color.pink);
    grayButton.setBackground(Color.gray);
    yellowButton.setBackground(Color.yellow);
    userDefButton.setBackground(userDefinedColor);
    ToolbarPanel.add(penButton);
    ToolbarPanel.add(lineButton);
    ToolbarPanel.add(eraserButton);
    ToolbarPanel.add(clearButton);
    ToolbarPanel.add(rectButton);
    ToolbarPanel.add(ovalButton);
    ToolbarPanel.add(fillRectButton);
    ToolbarPanel.add(fillOvalButton);
    ToolbarPanel.add(splineButton);
    ToolbarPanel.add(polygonButton);
    ToolbarPanel.setBounds(0,0,100,300);
    ToolbarPanel.add(udefcolPanel);
    ToolbarPanel.add(udefdemcolPanel);
    udefcolPanel.add(redValue);
    udefcolPanel.add(redSlider);
    udefcolPanel.add(greenValue);
    udefcolPanel.add(greenSlider);
    udefcolPanel.add(blueValue);
    udefcolPanel.add(blueSlider);
    statusPanel.add(colorLabel);
    statusPanel.add(colorStatusBar);
    statusPanel.add(operationLabel);
    statusPanel.add(opStatusBar);
    statusPanel.add(cursorLabel);
    statusPanel.add(mouseStatusBar);
    colorStatusBar.setEditable(false);
    opStatusBar.setEditable(false);
    mouseStatusBar.setEditable(false);
    statusPanel.setBackground(statusBarColor);
    ToolbarPanel.setBackground(Color.white);
    drawPanel.setBackground(Color.white);
    add(statusPanel, "North");
    add(ToolbarPanel, "West");
    add(drawPanel, "Center");
    penButton.addActionListener(this);
    lineButton.addActionListener(this);
    eraserButton.addActionListener(this);
    clearButton.addActionListener(this);
    rectButton.addActionListener(this);
    ovalButton.addActionListener(this);
    fillRectButton.addActionListener(this);
    fillOvalButton.addActionListener(this);
    splineButton.addActionListener(this);
    polygonButton.addActionListener(this);
    blackButton.addActionListener(this);
    blueButton.addActionListener(this);
    redButton.addActionListener(this);
    greenButton.addActionListener(this);
    purpleButton.addActionListener(this);
    orangeButton.addActionListener(this);
    pinkButton.addActionListener(this);
    grayButton.addActionListener(this);
    yellowButton.addActionListener(this);
    userDefButton.addActionListener(this);
    redSlider.addAdjustmentListener(this);
    blueSlider.addAdjustmentListener(this);
    greenSlider.addAdjustmentListener(this);
    drawPanel.addMouseMotionListener(this);
    drawPanel.addMouseListener(this);
    // this.addMouseListener(this);
    // this.addMouseMotionListener(this);
    updateRGBValues();
    opStatusBar.setText("Pen");
    colorStatusBar.setText("Black");
    public void actionPerformed(ActionEvent e)
         penButton.setActionCommand("Pen");
         lineButton.setActionCommand("Line");
         eraserButton.setActionCommand("Eraser");
         rectButton.setActionCommand("Rectangle");
         ovalButton.setActionCommand("Oval");
         fillRectButton.setActionCommand("Filled Rectangle");
         fillOvalButton.setActionCommand("Filled Oval");
         if (e.getActionCommand() == "Pen")
         opStatus = PEN_OP;
         else if (e.getActionCommand() == "Line")
         opStatus = LINE_OP;
         else if (e.getActionCommand() == "Eraser")
         opStatus = ERASER_OP;
         else if (e.getActionCommand() == "Clear")
         opStatus = CLEAR_OP;
         else if (e.getActionCommand() == "Rectangle")
         opStatus = RECT_OP;
         else if (e.getActionCommand() == "Oval")
         opStatus = OVAL_OP;
         else if (e.getActionCommand() == "Filled Rectangle")
         opStatus = FRECT_OP;
         else if (e.getActionCommand() == "Filled Oval")
         opStatus = FOVAL_OP;
         else if (e.getActionCommand() == "Polygon")
         opStatus = POLY_OP;
         else if (e.getActionCommand() == "Spline")
         opStatus = SPLINE_OP;
         else if (e.getActionCommand() == "Black")
         colorStatus = 1;
         else if (e.getActionCommand() == "Blue")
         colorStatus = 2;
         else if (e.getActionCommand() == "Green")
         colorStatus = 3;
         else if (e.getActionCommand() == "Red")
         colorStatus = 4;
         else if (e.getActionCommand() == "Purple")
         colorStatus = 5;
         else if (e.getActionCommand() == "Orange")
         colorStatus = 6;
         else if (e.getActionCommand() == "Pink")
         colorStatus = 7;
         else if (e.getActionCommand() == "Gray")
         colorStatus = 8;
         else if (e.getActionCommand() == "Yellow")
         colorStatus = 9;
         else if (e.getActionCommand() == "User-Def")
         colorStatus = 10;
    initialPolygon = true;
    initialSpline = true;
    switch (opStatus)
    case PEN_OP : opStatusBar.setText("Pen");
    break;
    case LINE_OP : opStatusBar.setText("Line");
    break;
    case ERASER_OP: opStatusBar.setText("Eraser");
    break;
    case CLEAR_OP : clearPanel(drawPanel);
    break;
    case RECT_OP : opStatusBar.setText("Rectangle");
    break;
    case OVAL_OP : opStatusBar.setText("Oval");
    break;
    case FRECT_OP : opStatusBar.setText("Fill-Rectangle");
    break;
    case FOVAL_OP : opStatusBar.setText("Fill-Oval");
    break;
    case POLY_OP : opStatusBar.setText("Polygon");
    break;
    case SPLINE_OP: opStatusBar.setText("Spline");
    break;
    switch (colorStatus)
    case 1: colorStatusBar.setText("Black");
    break;
    case 2: colorStatusBar.setText("Blue");
    break;
    case 3: colorStatusBar.setText("Green");
    break;
    case 4: colorStatusBar.setText("Red");
    break;
    case 5: colorStatusBar.setText("Purple");
    break;
    case 6: colorStatusBar.setText("Orange");
    break;
    case 7: colorStatusBar.setText("Pink");
    break;
    case 8: colorStatusBar.setText("Gray");
    break;
    case 9: colorStatusBar.setText("Yellow");
    break;
    case 10: colorStatusBar.setText("User Defined Color");
    break;
    setMainColor();
    updateRGBValues();
    public void adjustmentValueChanged(AdjustmentEvent e)
    updateRGBValues();
    public void clearPanel(JPanel drawPanel2)
    opStatusBar.setText("Clear");
    Graphics g = drawPanel2.getGraphics();
    g.setColor(drawPanel2.getBackground());
    g.fillRect(0,0,drawPanel2.getBounds().width,drawPanel2.getBounds().height);
    public void penOperation(MouseEvent e)
    Graphics g = drawPanel.getGraphics();
    g.setColor(mainColor);
    if (initialPen)
    setGraphicalDefaults(e);
    initialPen = false;
    g.drawLine(prevx,prevy,mousex,mousey);
    if (mouseHasMoved(e))
    mousex = e.getX();
    mousey = e.getY();
    g.drawLine(prevx,prevy,mousex,mousey);
    prevx = mousex;
    prevy = mousey;
    public void lineOperation(MouseEvent e)
    Graphics g = drawPanel.getGraphics();
    g.setColor(mainColor);
    if (initialLine)
    setGraphicalDefaults(e);
    g.setXORMode(xorColor);
    g.drawLine(Orx,Ory,mousex,mousey);
    initialLine=false;
    if (mouseHasMoved(e))
    g.setXORMode(xorColor);
    g.drawLine(Orx,Ory,mousex,mousey);
    mousex = e.getX();
    mousey = e.getY();
    g.drawLine(Orx,Ory,mousex,mousey);
    public void rectOperation(MouseEvent e)
    Graphics g = drawPanel.getGraphics();
    g.setColor(mainColor);
    if (initialRect)
    setGraphicalDefaults(e);
    initialRect = false;
    if (mouseHasMoved(e))
    g.setXORMode(drawPanel.getBackground());
    g.drawRect(drawX,drawY,OrWidth,OrHeight);
    mousex = e.getX();
    mousey = e.getY();
    setActualBoundry();
    g.drawRect(drawX,drawY,OrWidth,OrHeight);
    public void ovalOperation(MouseEvent e)
    Graphics g = drawPanel.getGraphics();
    g.setColor(mainColor);
    if (initialOval)
    setGraphicalDefaults(e);
    initialOval=false;
    if (mouseHasMoved(e))
    g.setXORMode(xorColor);
    g.drawOval(drawX,drawY,OrWidth,OrHeight);
    mousex = e.getX();
    mousey = e.getY();
    setActualBoundry();
    g.drawOval(drawX,drawY,OrWidth,OrHeight);
    public void frectOperation(MouseEvent e)
    Graphics g = drawPanel.getGraphics();
    g.setColor(mainColor);
    if (initialFRect)
    setGraphicalDefaults(e);
    initialFRect=false;
    if (mouseHasMoved(e))
    g.setXORMode(xorColor);
    g.drawRect(drawX,drawY,OrWidth-1,OrHeight-1);
    mousex = e.getX();
    mousey = e.getY();
    setActualBoundry();
    g.drawRect(drawX,drawY,OrWidth-1,OrHeight-1);
    public void fovalOperation(MouseEvent e)
    Graphics g = drawPanel.getGraphics();
    g.setColor(mainColor);
    if (initialFOval)
    setGraphicalDefaults(e);
    initialFOval = false;
    if (mouseHasMoved(e))
    g.setXORMode(xorColor);
    g.drawOval(drawX,drawY,OrWidth,OrHeight);
    mousex = e.getX();
    mousey = e.getY();
    setActualBoundry();
    g.drawOval(drawX,drawY,OrWidth,OrHeight);
    public void eraserOperation(MouseEvent e)
    Graphics g = drawPanel.getGraphics();
    if (initialEraser)
    setGraphicalDefaults(e);
    initialEraser = false;
    g.setColor(mainColor.white);
    g.fillRect(mousex-eraserLength, mousey-eraserLength,eraserLength*2,eraserLength*2);
    g.setColor(Color.black);
    g.drawRect(mousex-eraserLength,mousey-eraserLength,eraserLength*2,eraserLength*2);
    prevx = mousex;
    prevy = mousey;
    if (mouseHasMoved(e))
    g.setColor(mainColor.white);
    g.drawRect(prevx-eraserLength, prevy-eraserLength,eraserLength*2,eraserLength*2);
    mousex = e.getX();
    mousey = e.getY();
    g.setColor(mainColor.white);
    g.fillRect(mousex-eraserLength, mousey-eraserLength,eraserLength*2,eraserLength*2);
    g.setColor(Color.black);
    g.drawRect(mousex-eraserLength,mousey-eraserLength,eraserLength*2,eraserLength*2);
    prevx = mousex;
    prevy = mousey;
    public void polygonOperation(MouseEvent e)
    if (initialPolygon)
    prevx = e.getX();
    prevy = e.getY();
    initialPolygon = false;
    else
    mousex = e.getX();
    mousey = e.getY();
    Graphics g = drawPanel.getGraphics();
    g.setColor(mainColor);
    g.drawLine(prevx,prevy,mousex,mousey);
    prevx = mousex;
    prevy = mousey;
    public void splineOperation(MouseEvent e)
    if(initialSpline)
    initialSpline = false;
    public boolean mouseHasMoved(MouseEvent e)
    return (mousex != e.getX() || mousey != e.getY());
    public void setActualBoundry()
    if (mousex < Orx || mousey < Ory)
    if (mousex < Orx)
    OrWidth = Orx - mousex;
    drawX = Orx - OrWidth;
    else
    drawX = Orx;
    OrWidth = mousex - Orx;
    if (mousey < Ory)
    OrHeight = Ory - mousey;
    drawY = Ory - OrHeight;
    else
    drawY = Ory;
    OrHeight = mousey - Ory;
    else
    drawX = Orx;
    drawY = Ory;
    OrWidth = mousex - Orx;
    OrHeight = mousey - Ory;
    public void setGraphicalDefaults(MouseEvent e)
    mousex = e.getX();
    mousey = e.getY();
    prevx = e.getX();
    prevy = e.getY();
    Orx = e.getX();
    Ory = e.getY();
    drawX = e.getX();
    drawY = e.getY();
    OrWidth = 0;
    OrHeight = 0;
    public void mouseDragged(MouseEvent e)
    updateMouseCoordinates(e);
    switch (opStatus)
    case PEN_OP : penOperation(e);
    break;
    case LINE_OP : lineOperation(e);
    break;
    case RECT_OP : rectOperation(e);
    break;
    case OVAL_OP : ovalOperation(e);
    break;
    case FRECT_OP : frectOperation(e);
    break;
    case FOVAL_OP : fovalOperation(e);
    break;
    case ERASER_OP: eraserOperation(e);
    break;
    public void mouseReleased(MouseEvent e)
    updateMouseCoordinates(e);
    switch (opStatus)
    case PEN_OP : releasedPen();
    break;
    case LINE_OP : releasedLine();
    break;
    case RECT_OP : releasedRect();
    break;
    case OVAL_OP : releasedOval();
    break;
    case FRECT_OP : releasedFRect();
    break;
    case FOVAL_OP : releasedFOval();
    break;
    case ERASER_OP : releasedEraser();
    break;
    public void mouseEntered(MouseEvent e)
    updateMouseCoordinates(e);
    public void setMainColor()
    switch (colorStatus)
    case 1 : mainColor = Color.black;
    break;
    case 2: mainColor = Color.blue;
    break;
    case 3: mainColor = Color.green;
    break;
    case 4: mainColor = Color.red;
    break;
    case 5: mainColor = Color.magenta;
    break;
    case 6: mainColor = Color.orange;
    break;
    case 7: mainColor = Color.pink;
    break;
    case 8: mainColor = Color.gray;
    break;
    case 9: mainColor = Color.yellow;
    break;
    case 10: mainColor = userDefinedColor;
    break;
    public void releasedPen()
    initialPen = true;
    public void releasedLine()
    if ((Math.abs(Orx-mousex)+Math.abs(Ory-mousey)) != 0)
    // System.out.println("Line has been released....");
    initialLine = true;
    Graphics g = drawPanel.getGraphics();
    g.setColor(mainColor);
    g.drawLine(Orx,Ory,mousex,mousey);
    public void releasedEraser()
    initialEraser = true;
    Graphics g = drawPanel.getGraphics();
    g.setColor(mainColor.white);
    g.drawRect(mousex-eraserLength,mousey-eraserLength,eraserLength*2,eraserLength*2);
    public void releasedRect()
    initialRect = true;
    Graphics g = drawPanel.getGraphics();
    g.setColor(mainColor);
    g.drawRect(drawX,drawY,OrWidth,OrHeight);
    public void releasedOval()
    initialOval = true;
    Graphics g = drawPanel.getGraphics();
    g.setColor(mainColor);
    g.drawOval(drawX,drawY,OrWidth,OrHeight);
    public void releasedFRect()
    initialFRect = true;
    Graphics g = drawPanel.getGraphics();
    g.setColor(mainColor);
    g.fillRect(drawX,drawY,OrWidth,OrHeight);
    public void releasedFOval()
    initialFOval = true;
    Graphics g = drawPanel.getGraphics();
    g.setColor(mainColor);
    g.fillOval(drawX,drawY,OrWidth,OrHeight);
    public void updateMouseCoordinates(MouseEvent e)
    String xCoor ="";
    String yCoor ="";
    if (e.getX() < 0) xCoor = "0";
    else
    xCoor = String.valueOf(e.getX());
    if (e.getY() < 0) xCoor = "0";
    else
    yCoor = String.valueOf(e.getY());
    mouseStatusBar.setText("x:"+xCoor+" y:"+yCoor);
    public void updateRGBValues()
    udefRedValue = redSlider.getValue();
    udefGreenValue = greenSlider.getValue();
    udefBlueValue = blueSlider.getValue();
    if (udefRedValue > 255)
    udefRedValue = 255;
    if (udefRedValue < 0 )
    udefRedValue =0;
    if (udefGreenValue > 255)
    udefGreenValue = 255;
    if (udefGreenValue < 0 )
    udefGreenValue =0;
    if (udefBlueValue > 255)
    udefBlueValue = 255;
    if (udefBlueValue < 0 )
    udefBlueValue =0;
    redValue.setText(String.valueOf(udefRedValue));
    greenValue.setText(String.valueOf(udefGreenValue));
    blueValue.setText(String.valueOf(udefBlueValue));
    userDefinedColor = new Color(udefRedValue,udefGreenValue,udefBlueValue);
    userDefButton.setBackground(userDefinedColor);
    Graphics g = udefdemcolPanel.getGraphics();
    g.setColor(userDefinedColor);
    g.fillRect(0,0,800,800);
    public void mouseClicked(MouseEvent e)
    updateMouseCoordinates(e);
    switch (opStatus)
    case 9 : splineOperation(e);
    break;
    case 10 : polygonOperation(e);
    break;
    public void mouseExited(MouseEvent e)
    updateMouseCoordinates(e);
    public void mouseMoved(MouseEvent e)
    updateMouseCoordinates(e);
    public void mousePressed(MouseEvent e)
    updateMouseCoordinates(e);
    Edited by: eclipse on Feb 19, 2008 6:29 AM

    If you can't divide the class then you can't implement an MVC design methodology.
    This class is a giant mess and can be EASILY broken down into smaller classes. Seperate the visual components into their own classes. Create Model objects that contain the data behind your visual components.
    Split up your giant ActionListener into several smaller more specialized actionlisteners and create a Controller object that you can assign these listeners and models to. Allow the event handling to be done by the controller so it can propogate necessary data changes to the models, thus altering the Views.
    Thats it in a nutshell. It is not an easy answer.

  • Help with MVC plz!

    I'm attempting to use Swing components to implement a MVC GUI component.
    It's quite simple, a JFrame contains a Jtree and a JButton. When I click the button I want the model of the JTree to be changed in some way. The changing of the model would then force the view to update itself. I've been trying to get this to work for a day or two and have had no luck.
    Does anyone out there have any simple examples of a simple MVC component that I could see to get a better understanding of what's going on.
    Thx

    maybe this is relevant, in javadocs for AbstractTableModel,
    fireTableStructureChanged
    public void fireTableStructureChanged()
    Notifies all listeners that the table's structure has changed. The number of columns in the table, and the names
    and types of the new columns may be different from the previous state. If the JTable receives this event and its
    autoCreateColumnsFromModel flag is set it discards any table columns that it had and reallocates default
    columns in the order they appear in the model. This is the same as calling setModel(TableModel) on the
    JTable.
    See Also:
    TableModelEvent, EventListenerList

  • MVC 5 Database Help (calculations and input based on user input)

    Hello all! I am learning MVC 5 database interactions. I would like to fill in certain database columns based on a calculation done on columns the user inputs. I am not having trouble getting user inputs into the database. I am wondering
    about how to take 2 user input database values, make a calculation using them, and put the resulting number in its own column in the database.
    So: after the user inputs price and lot price, I want the application to figure out the margin (price / lot price) and then input margin into the database. Here is what I have, but the calculation doesn't seem to input the result into my database.
    Where am I going wrong? (margin is already a column in the database)
    Thanks in advance!
    publicActionResultCreate([Bind(Include
    = "ID,Name,Price,Location,Color,LotPrice")]
    Automobile automobile)
    if(ModelState.IsValid)
                    db.Automobile.Add(automobile);          
    automobile.Margin = automobile.Price / automobile.LotPrice;
                    db.SaveChanges();        
    returnRedirectToAction("Index");
    returnView(automobile);

    Hi Ruben,
    Please post your question to the MVC forum below for a better assistance on your issue:
    http://forums.asp.net/1146.aspx
    Regards,
    Fouad Roumieh

  • Help with MVC

    Hi,
    I am trying to understand the MVC pattern in particular the difference between the controller and the view. I was under the impression that the view was the GUI, but after researching it appears that the controller is the GUI as it makes changes to the model via buttons and textfields.
    Surely the GUI would be built in one class that implements Observer interface so am I correct in saying that in some cases the view and controller are in the same class?
    Thanks for your advice

    My understanding is that if an executive entity manipulates application logic that entity
    should be called controller. So,
    [Controller] e.g. event handler
    ^
    v
    [Model] e.g. TableModel
    ^
    v
    [View] e.g. JTable == event generator
    Some of Java documentation says that in Java V and C are in a sinble GUI entity.
    I somehow disagree becuase contorller, e.g. event handler, is pluggable on any
    GUI component.

Maybe you are looking for