JSF MVC Architecture Question
There seem to be two distinct schools of thought on this.
1 group defines it as such:
Model = Data
View = HTML
Controller = Business Logic and everything else.
The other group defines it at as:
Model = Data / Application Logic
View = HTML
Controller = accepts user input and instructs model and view to perform actions based on that input, ie. maps end-user action to application response.
In the case of a JSF application specifically this would mean:
.xhtml files = View
POJO backing bean (containing application logic + Faces Servlet) = Controller
POJO backing bean (containing data) = Model
OR
.xhtml files = View
FacesServlet (the view handler, which processes requests / responses etc) = Controller
POJO backing bean(s) (containing the data / application logic) = Model
Any insight provided into this would be greatly appreciated.
That's pretty interesting topic for me as a beginner and I'll try to talk about that at work and get deeper insight. If I learn something about it, I'll post it here. However I'd like to hear a bit from JSF gurus on that one :)
Similar Messages
-
Database access in a MVC architecture
Hi!
I'm a bit confused with regards to where the database access code should be put in a MVC architecture. From reading various articles and posts on this forum, there seem to be a lot of different opinions.
Some seem to put the database access code in the controller servlet(or JSP), while some seem to use helper classes from the JavaBeans, while a few people even seem to access the database directly from the JavaBean.
My questions is: What is the best place to put the database stuff in a MVC architecture? An explanation as to why a particular solution is the best would be great..
Thanks!
regards,
VidarLet's say I have a class called Department that contains methods like getName(), getId(), setName(), etc... The Department class is my business object. To save and load Departments from a database, I have a class called DepartmentManager. The DepartmentManager saves and loads the departments to the database, and has methods like saveDepartment(), saveDepartments(), loadDepartment(), getDepartments(), etc... In some cases, my manager classes also caches the results so they don't have to load from the database each time. Often times, the manager class is a singleton. My Department class has no idea how it is persisted, or that it is part of a cache. It just knows about itself. The DepartmentManager is resonsible for managing all the persistance and lookup functionality for Departments.
Therefore, if I have a JSP page that needs to display Departments, my code might look like:
DepartmentManager dm = DepartmentManager.getManager();
ArrayList listDepartments = dm.getDepartmentList();
for (int i = 0; listDepartments != null && i < listDepartments.size(); i++) {
Department dept = (Department)listDepartments.get(i);
out.println("<option value=\"" + dept.getId() + "\">" + dept.getName());
}If I had a specific Department I needed, I would get it as follows:
DepartmentManager dm = DepartmentManager.getManager();
Department dept = dm.getDepartment(nId); -
Collections in MVC architecture
My question concerns the use of collections of entities in a database-access MVC architecture. An example similar to my situation would be a Corporation, which (among other attributes) has a collection of Departments, which (among other attributes) has a collection of Projects, which (among other attributes) has a collection of Employees.
Sometimes, I may want information such as all the Employees in the corporation, which would necessarily involve retrieving all the entities from the database. Other times, I may only want the employees in a certain Department, in which case I wouldn't want to waste the time population all the Department beans with Project and Employee information.
Basically, I'm not sure how to best go about populating Javabeans that contain other Javabeans containing other Javabeans. Obviously, when I go to retrieve a Corporation bean, I don't always want all the Departments, Projects, and Employees. However, it seems like it would be using a lot of redundant code to have one factory that returns just the Department base information (without it's Employees), one factory that returns all the Departments and their Projects (but not the Employees), one factory that returns all the Employees for a given Project (but not ALL the Projects and their Employees), and so on.
I've read plenty of MVC tutorials (and even taken a course in it), but I've never really seen a basic situation such as this addressed. What is the best way to go at this situation? Does anyone know of any tutorials/examples that are similar to this situation?First let's say your post reminded me my previouse Project where i faced exactly this topic.( not a problem may say ) :)
That's it orr94 ! No MVC related topic, says about these. this may be referenced in your experience of Programming and System Design, with the knowledge of OOP, implementing DBs, Performance issues, and so on...
Simply i can tell you, by my experience, try to feel ( and then find ) what your system is supposed to do? and how it does that?
In a situation when you should give many reports, collecting your information, and the main part is GIVING THE LISTS OF REPORTS, just try to load all of your data. ( here first time spends much time, but after that no time is needed for DB operations. you every time read from your objects ( makin' them Updatable )
But if number of the times you should gather this information, is such small that it dosn't actualy needed to read more than wanted.
So see that there is NO GENERAL ANSWER to this question. ( i found it on that project, spending a month to find any answers. )
YOU SHOULD FIND YOUR ANSWER. try feeling your system by real-time TESTS, that would make you sure about a solution.
P.S. Now as a tip
Create a Database Logic Bean which all related methods go in for CRUD operations on entities, then as friends said, try puttin some flags for reading entities ( e.g in your constructors which use DB bean methods )
and then try different approaches readin the data, see which makes sense to your system.
As the last point, what chintat said ( A Getter() which reads the from db that lists ) is not a good solution, where each call to that getter(), where it'd be many calles, attemps to access db!!! you should read once, then getter() returns a reference ( maybe readonly ) to that list.
I think the question is when to read, where YOU SHOUD FIND THE ANSWER. ;)
nice post, i hope it helps. ;)
Behrad -
i dont know how to use a MVC architecture,what are the files has to be needed to create a MVC architecture,right now iam using jsp file and a java file .in jsp file i just use the usebean tag
http://www.javaworld.com/javaworld/jw-12-1999/jw-12-ssj-jspmvc.html
-
Hi
Building a web application based on MVC architecture. I am new at this so my implementation may not be correct. My Javabeans are representations of SQL DB tables. So, e.g. I have a Customer table in my SQL database, I would have a CustomerBean to represent this table.
My problem is that Javabeans can only have empty constructors. So how can I get a single record from my customer table? Currently, I am using a method to get this record.
E.g.
CustomerBean customer = new CustomerBeanImpl();
customer.setRecord(primaryKeyOfCustomerTable);
In setRecord(int PK) method, I execute a SQL query to retrieve the record with that primary key and set all the instance variables for that object.
I find that this method "not elegant".
However, if I break the requirements of Javabeans, i.e to implement non-empty constructors, i.e.
Customer customer1 = new Customer(primaryKey1);
this would be better. In this case, my class is not a JavaBean anymore.Thanks. So, I conclude from your reply that Javabeans
must have empty constructors. That's what I thought
too. Until I was looking at an example from "Core
servlets and JSPs" and came across an example where
the class used (if anyone is interested, it is
"TravelCustomer.class" in page 365 of the book) is not
an Javabean per se, as it did not have a empty
constructor but was used in the <jsp:useBean> tag like
any other Javabean!
That got me confused. Anyone care to explain this?As you know, <jsp:useBean> first checks whether a reference to the specified class exists as an attribute under the specifed id and scope.
If the reference is found, then the scripting variable is set to that reference. If not found, then <jsp:useBean> checks whether the class can be instantiated and has a no-args constructor. If yes, an object of that class is instantiated (in Tomcat using Beans.instantiate) and the reference is stored as an attribute in the specified scope as well as in the scripting variable.
In the "Core Servlets..." example, the TravelCustomer object is always instantiated in a servlet and its reference saved as a session attribute with id = "customer". The servlet then forwards to a JSP that includes:
<jsp:useBean id="customer" class="coreservlets.TravelCustomer" scope="session" />Since the "customer" attribute is always present, the useBean never has to instantiate a TravelCustomer object and so the lack of a no-args constructor does not come into play.
I'm not sure if this is good or bad practice, but that's why it works. -
Oracle VM Server for SPARC - network multipathing architecture question
This is a general architecture question about how to best setup network multipathing
I am reading the "Oracle VM Server for SPARC 2.2 Administration Guide" but I can't find what I am looking for.
From reading the document is appears it is possible to:
(a) Configure IPMP in the Service Domain (pg. 155)
- This protects against link level failure but won't protect against the failure of an entire Service LDOM?
(b) Configure IPMP in the Guest Domain (pg. 154)
- This will protect against Service LDOM failure but moves the complexity to the Guest Domain
- This means the there are two (2) VNICs in the guest though?
In AIX, "Shared Ethernet Adapter (SEA) Failover" it presents a single NIC to the guest but can tolerate failure of a single VIOS (~Service LDOM) as well as link level failure in each VIO Server.
https://www.ibm.com/developerworks/mydeveloperworks/blogs/aixpert/entry/shared_ethernet_adapter_sea_failover_with_load_balancing198?lang=en
Is there not a way to do something similar in Oracle VM Server for SPARC that provides the following:
(1) Two (2) Service Domains
(2) Network Redundancy within the Service Domain
(3) Service Domain Redundancy
(4) Simplify the Guest Domain (ie single virtual NIC) with no IPMP in the Guest
Virtual Disk Multipathing appears to work as one would expect (at least according the the documentation, pg. 120). I don't need to setup mpxio in the guest. So I'm not sure why I would need to setup IPMP in the guest.
Edited by: 905243 on Aug 23, 2012 1:27 PMHi,
there's link-based and probe-based IPMP. We use link-based IPMP (in the primary domain and in the guest LDOMs).
For the guest LDOMs you have to set the phys-state linkprop on the vnets if you want to use link-based IPMP:
ldm set-vnet linkprop=phys-state vnetX ldom-name
If you want to use IPMP with vsw interfaces in the primary domain, you have to set the phys-state linkprop in the vswitch:
ldm set-vswitch linkprop=phys-state net-dev=<phys_iface_e.g._igb0> <vswitch-name>
Bye,
Alexander. -
Architecture question, global VDI deployment
I have an architecture question regarding the use of VDI in a global organization.
We have a pilot VDI Core w/remote mysql setup with 2 hypervisor hosts. We want to bring up 2 more Hypervisor hosts (and VDI Secondaries) in another geographic location, where the local employees would need to connect desktops hosted from their physical location. What we don't want is to need to manage multiple VDI Cores. Ideally we would manage the entire VDI implementation from one pane of glass, having multiple Desktop Provider groups to represent the geographical locations.
Is it possible to just setup VDI Additional Secondaries in the remote locations? What are the pros and cons of that?
ThanksYes, simply bind individual interfaces for each domain on your web server,
one for each.
Ensure the appropriate web servers are listening on the appropriate
interfaces and it will work fine.
"Paul S." <[email protected]> wrote in message
news:407c68a1$[email protected]..
>
Hi,
We want to host several applications which will be accessed as:
www.oursite.com/app1 www.oursite.com/app2 (all using port 80 or 443)
Is it possible to have a separate Weblogic domain for each application,all listening
to ports 80 and 443?
Thanks,
Paul -
Sap XI application can be developed based on the MVC architecture in java?
MVC architecture
Jsp-->servlet--
>database.
<--<<--
(front-end) (business logic) (data)
Can anyone explain one process flow in sap xi with java.
I would be most thankful to you if you answer me.
Thanks in advance
JeevanHi jeevan
SAP XI pretty much mimics MVC
For eg, you create the design objects in IR (View)
the controller is the J2ee engine of the (WAS server) (controller)
The model is the database underneath
regards
krishna -
Running MII on a Wintel virtual environment + hybrid architecture questions
Hi, I have two MII Technical Architecture questions (MII 12.0.4).
Question1: Does anyone know of MII limitations around running production MII in a Wintel virtualized environment (under VMware)?
Question 2: We're currently running MII centrally on Wintel but considering to move it to Solaris. Our current plan is to run centrally but in the future we may want to install local instances local instances of MII in some of our plants which require more horsepower. While we have a preference for Solaris UNIX based technologies in our main data center where our central MII instance will run, in our plants the preference seems to be for Wintel technologies. Does anybody know of any caveats, watch outs or else around running MII in a hybrid architecture with a Solarix Unix based head of the hybrid architecture and the legs being run on Wintel?
Thanks for your help
MichelThis is a great source for the ins/outs of SAP Virtualization: https://www.sdn.sap.com/irj/sdn/virtualization
-
Suggest some docs to do design my Webdynpro-MVC architecture Project
Hi,
I am doing design for my project.I'd like to know what are all the steps I have to follow & kept in mind before starting design.could anyone give the link to go thro before start design.I should follow MVC Architecture.
ie. I should have 4 DC's---(a)UI (b)Service (c)DAI (d)DAM_R3
Regards,
Karthick.K.EHello Karthick,
Hope this document helps you to design WD application
The title from the document is
Designing Web Dynpro Applications
http://help.sap.com/saphelp_nw04/helpdata/en/b1/d1e4f7c633fb47ac8b115087d5f2b6/frameset.htm
The above link takes you to somehow to wrong title being Example: Using a Foreign Web Dynpro Component
If you scroll up you find the topic that I mentioned above.
Good Luck
Regards,
Dharmi
Message was edited by: Dharmi Tanna -
Little architectural question: why is all the stuff that is needed to render a page put into the constructor of a backing bean? Why is there no beforeRender method, analogous to the afterRenderResponse method? That method can then be called if and only if a page has to be rendered. It seems to me that an awful lot of resources are waisted this way.
Reason I bring up this question is that I have to do a query in the constructor in a page backing bean. Every time the backing bean is created the query is executed, including when the page will not be rendered in the browser...Little architectural question: why is all the stuff
that is needed to render a page put into the
constructor of a backing bean? Why is there no
beforeRender method, analogous to the
afterRenderResponse method? That method
can then be called if and only if a page has to be
rendered. It seems to me that an awful lot of
resources are waisted this way.There actually is such a method ... if you look at the FacesBean base class, there is a beforeRenderResponse() method that is called before the corresponding page is actually rendered.
>
Reason I bring up this question is that I have to do
a query in the constructor in a page backing bean.
Every time the backing bean is created the query is
executed, including when the page will not be
rendered in the browser...This is definitely a valid concern. In Creator releases prior to Update 6 of the Reef release, however, there were use cases when the beforeRenderResponse method would not actually get called (the most important one being when you navigated to a new page, which is a VERY common use case :-).
If you are using Update 6 or later, as a side effect of other bug fixes that were included, the beforeRenderResponse method is reliably called every time, so you can put your pre-rendering logic in this method instead of in the constructor. However, there is still a wrinkle to be aware of -- if you navigate from one page to another, the beforeRenderResponse of both the "from" and "to" pages will be executed. You will need to add some conditional logic to ensure that you only perform your setup work if this is the page that is actually going to be rendered (hint: call FacesContext.getCurrentInstance().getViewRoot().getViewId() to get the context relative path to the page that will actually be displayed).
One might argue, of course, that this is the sort of detail that an application should not need to worry about, and one would be absolutely correct. This usability issue will be dealt with in an upcoming Creator release.
Craig McClanahan -
BPEL/ESB - Architecture question
Folks,
I would like to ask a simple architecture question;
We have to invoke a partner web services which are rpc/encoded from SOA suite 10.1.3.3. Here the role of SOA suite is simply to facilitate communication between an internal application and partner services. As a result SOA suite doesn't have any processing logic. The flow is simply:
1) Internal application invokes SOA suite service (wrapper around partner service) and result is processed.
2) SOA suite translates the incoming message and communicates with partner service and returns response to internal application.
Please note that at this point there is no plan to move all processing logic from internal application to SOA suite. Based on the above details I would like get some recommedation on what technology/solution from SOA suite is more efficient to facilate this communication.
Thanks in advance,
RanjithYou can go through the design pattern called Channel Adapter.
Here is how you should design - Processing logic remains in the application.. however, you have to design and build a channel adapter as a BPEL process. The channel adapter does the transformation of your input into the web services specific format and invoke the endpoint. You need this channel adapter if your internal application doesn't have the capability to make webservice calls.
Hope this helps. -
MVC architecture - how it can be applied to swings
hi
I have created a program that gets data from an MS access database and displays it in Swings JFrame, with view, next, previous buttions to traverse through records
I want to write my program in the MVC architecture model. Though i have read details about it, i am unable to apply it on new programs.
Any one please help me with an instance of a program or modify the below program to suit the MVC architecture
thank u
import java.awt.*;
import javax.swing.*;
import java.sql.*;
import java.awt.event.*;
class display extends JFrame implements ActionListener
ResultSet rs;
Statement st;
JTextField tf;
JLabel l;
Button b0,b1,b2;
ResultSetMetaData rsmd;
display()throws Exception
tf = new JTextField(10);
l = new JLabel("Empno: ");
b2 = new Button("Previous");
b1 = new Button("Next");
b0 = new Button("View");
connection con = new connection();
Container c = getContentPane();
c.setLayout(new FlowLayout());
setSize(300,300);
c.add(l);
c.add(tf);
c.add(b0);
c.add(b1);
c.add(b2);
setVisible(true);
l.setBounds(20, 10,70,35);
tf.setBounds(20,50, 70,35);
b0.setBounds(20,90, 70,35);
b1.setBounds(90,90, 70,35);
b2.setBounds(170,90, 70,35);
b0.addActionListener(this);
b1.addActionListener(this);
b2.addActionListener(this);
public void actionPerformed(ActionEvent ae)
if(ae.getActionCommand().equals("View"))
try{
rs.close();
rs = st.executeQuery("select * from emp");
if(rs.next())
tf.setText(rs.getString(1));
catch(Exception e)
{System.out.println(e);}
if(ae.getActionCommand().equals("Next"))
try
if(rs.next())
{tf.setText(rs.getString(1));b2.setEnabled(true);}
else
{b1.setEnabled(false);b2.setEnabled(true);}
catch(Exception e)
{System.out.println(e);}
if(ae.getActionCommand().equals("Previous"))
try
if(rs.previous())
{ tf.setText(rs.getString(1)); b1.setEnabled(true);}
else
{b2.setEnabled(false);b1.setEnabled(true);}
catch(Exception e)
{System.out.println(e);}
class connection
connection()throws SQLException, ClassNotFoundException
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:dsn1");
/*st = con.createStatement();
rs = st.executeQuery("select * from emp");*/
st = con.createStatement( ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
rs = st.executeQuery("select * from emp");
} // connection constructor
} // end of connection
}//end of display
class records
public static void main(String args[])throws Exception
display d = new display();
}help full hint use code formating tags
David -
Architecture Question...brain teasing !
Hi,
I have a architecture question in grid control. So far Oracle Support hasnt been able to figure out.
I have two management servers M1 and M2.
two VIP's(Virtual IP's) V1 and V2
two Agents A1 and A2
the scenerio
M1 ----> M2
| |
V1 V2
| |
A1 A2
Repository at M1 is configured as Primary and sends archive logs to M2. On the failover, I have it setup to make M2 as primary repository and all works well !
Under normal conditions, A1 talks to M1 thru V1 and A2 talks to M2 thru V2. No problem so far !
If M1 dies, and V1 forwards A1 to M2 or
if M2 dies, V2 forwards A2 to M1
How woudl this work.
I think (havent tried it yet) but what if i configure the oms'es with same username and registration passwords and copy all the wallets from M1 to M2
and A1 to A2 and just change V1 to V2. Would this work ????
please advice!!SLB is not an option for us here !
Can we just repoint all A1 to M2 using DNS CNAME change ?? -
Inheritance architecture question
Hello,
I've an architecture question.
We have different types of users in our system, normal users, company "users", and some others.
In theory they all extend the normal user. But I've read alot about performance issues using join based inheritance mapping.
How would you suggest to design this?
Expected are around 15k normal users, a few hundred company users, and even a few hundred of each other user type.
Inheritance mapping? Which type?
No inheritance and append all attributes to one class (and leave these not used by the user-type null)?
Other ways?
thanks
Dirksorry dude, but there is only one way you are going to answer your question: research it. And that means try it out. Create a simple prototype setup where you have your inheritance structure and generate 15k of user data in it - then see what the performance is like with some simple test cases. Your prototype could be promoted to be the basis of the end product if the results or satisfying. If you know what you are doing this should only be a couple of hours of work - very much worth your time because it is going to potentially save you many refactoring hours later on.
You may also want to experiment with different persistence providers by the way (Hibernate, Toplink, Eclipselink, etc.) - each have their own way to implement the same spec, it may well be that one is more optimal than the other for your specific problem domain.
Remember: you are looking for a solution where the performance is acceptable - don't waste your time trying to find the solution that has the BEST performance.
Maybe you are looking for
-
I keep on getting message that my start up disk is full. How do i resolve this?
i keep on getting message that my start up disk is full. How do i resolve this?
-
My computer has been crashing over the past two days when I launch Photoshop CS 2. I have tried to resolve the issue by disabling my twain pluggins, I have deleted my CS2 Presets/preferences, and I have uninstalled and reinstalled the program. The sp
-
Integrate my Muse site in Business Catalyst
Hello, I am considering hosting my website to BC. I created my website with Muse and I would like to use the BC's CMS features on it. Do I have to recreate the whole website with BC or I can "import" my Muse's website into BC's template ? Thanks Esth
-
'phantom' fields appearing several edits down the line...
I've been transferring stuff from PAL composite video via a Canopus ADVC300: http://desktop.grassvalley.com/products/ADVC300/index.php It creates huge AVI files which I then convert to a size I want to work with. I've been working on something that w
-
Transaction iView issue: Table Can't Support multi-cell copy pase
Hey guys: I have a big problem. The transaction iview's content is a ABAP application, and it cannot support mulit-cell copy-pase when user try to pase their data from Excel. It only allow single cell copy-pase each time, and that means