MVC without servlet+jsp ?
Hello
I'm looking for an example (or ideas...) of the MVC paradigm but
without the web part (with only fat Java clients).
I haven't take a look at the proxy class in Java. Is it possible to
use proxies to access the front controller session bean (which is normally
accessed by a main servlet to process http requests) to act as the controller ?
Thanks a lot.
A beginner with the MVC paradigm.
Nicolas
Why ?This violates the principal of a single responsibility, a corner stone of OO. It requires all classes should have one and only one responsibility. I would suggest you keep a seperate controller and link it to your proxy via an association.
Hello Martin
Actually, i was asking myself how to simulate the MVC paradigm in a distributed environment (servers+client) but without servlets. Sun and oracle provide source samples to see how to implement this (jsp=view, 1 servlet for the controller, EJBs for the model). OK but what if i have only remote clients and EJBs.
I think one approach is to design server side classes to generate events which will be received by all the clients that use the modified data.
This way, the remote client can be seen like 'viewer AND controller'.
I would like to know how to isolate controller from the view and if it is a good idea.
Nicolas
> Actually, i was asking myself how to simulate the MVC
> paradigm in a distributed environment (servers+client)
> but without servlets. Sun and oracle provide source
> samples to see how to implement this (jsp=view, 1
> servlet for the controller, EJBs for the model). OK
> but what if i have only remote clients and EJBs.
If you implement the mvc you still need a controller in this scenario. The controller is probably a session bean. I usually use the Command Pattern to implement my controller.
The model is the your Entity Beans, that the session beans access. I usually use the a fascade to implement my session beans services. However a proxy is equally valid though slightly less efficient, to the benefit of flexibility.
The response is the view, depending on how you encapsulate it this is likely to be the Value Objects you return.
> I think one approach is to design server side classes
> to generate events which will be received by all the
> clients that use the modified data.
This sounds more like a 'push' application rather than pull. Have you considered a multicaster ?
> This way, the remote client can be seen like 'viewer
> AND controller'.
Your UI in a rich client almost certainly contains a seperate MVC.
> I would like to know how to isolate controller from
> the view and if it is a good idea.
Yes it is a good idea. Consider the Controller to be the request handler and the view to be the encapsulted response.
> Nicolas
Thanks a lot MartinDo you know where could I find mulicast code samples (working with EJB) ?Do you know where could I find code samples which illustrate the Command pattern ?Yes i want all, already done :-)Nicolas
> Thanks a lot Martin
>
> Do you know where could I find mulicast code samples
> (working with EJB) ?
[code]
/**
* Receiving from a Multicast Group
*Once you've created a multicast socket and joined the group,
*all datagrams sent to its corresponding multicast address
*will be available to be read from the socket. You can read
*from the socket just like you would from a unicast socket.
*/
public void read( MulticastSocket msocket, byte[] inbuf)
{
try
{
DatagramPacket packet = new DatagramPacket(inbuf, inbuf.length) ;
// Wait for packet
msocket.receive( packet ) ;
// Data is now in inbuf
int numBytesReceived = packet.getLength();
}
catch (IOException e)
{
}
}
/**
* Sending to a Multicast Group
* You can send to a multicast socket using either a DatagramSocket or a MulticastSocket. What makes it multicast is the address that is in the datagram. If the address is a multicast address, the datagram will reach the multicast members in the group. You only need to use MulticastSocket if you want to control the time-to-live of the datagram.
*/
byte[] outbuf = new byte[1024];
String group = "228.1.2.3" ;
int port = 1234;
try
{
DatagramSocket socket = new DatagramSocket() ;
InetAddress groupAddr = InetAddress.getByName( group ) ;
DatagramPacket packet = new DatagramPacket(outbuf, outbuf.length, groupAddr, port) ;
socket.send(packet) ;
}
catch (SocketException e)
{
}
catch (IOException e)
{
}
[code]
> Do you know where could I find code samples which
> illustrate the Command pattern ?
The command pattern is basically a collection of polymorphic commands with an execute method.
http://www.javaworld.com/javatips/jw-javatip68_p.html
> Yes i want all, already done :-)
Here are some more pattern sites.
http://directory.google.com/Top/Computers/Programming/Methodologies/Patterns_and_Anti-Patterns/
> Nicolas
> Do you know where could I find mulicast code samples> (working with EJB) ?java.net.MulticastSocket: http://java.sun.com/j2se/1.4/docs/api/java/net/MulticastSocket.htmlHere is the Multicast RFC: http://www.ietf.org/rfc/rfc2365.txt
OKFor now, trying to implement the MVC pattern with EJBs.Looking at the multicaster just after ....Thanks a lot