I have Spring+Java Server Faces (Facelets) application for which I would like to create Single Page Application (SPA) version, e.g. using AngularJS (which is the best and most popular GUI framework). But after some investigation of technologies I have come to conclusion that REST (which is necessarity for AngularJS) ir bad choice for complex business applications, because there is requirement to divide business logic accross software layers.

Let me explain this. In Spring+JSF application all the business logic was encoded in special layer - Spring entities and services. In Spring+REST+AngluarJS this should be different. I don't want to rewrite (move) business logic from Spring/Java to AngularJS/JavasScript but obviously I am required to to. There are one issue and 3 types of business logic in my application that requires consideration.

  • Issue one. Spring provided stateful interaction with business object. E.g. one could open new invoice, add customer, add invoice lines, recalculate discounts, sales tax, totals, add shipping information and so on. Session and business objects were stored in Spring server side session. REST architecture requires that session abd business objects are stores in client (Browser JavaScript objects). So, migration required almost complete rewrite of applicateion.
  • Business logic type 1. Validatione. It was possible to include validation rules in Spring server side objects. REST requires that validation is done in JavaScript objects, because it is impossible upon each change of each field to send complete client state to the server for validation.
  • Business logic type 2. Change monitoring and propagation. E.g. if user adds invoice line with article to the invoice inside application form, then program can retrieve all the discounts that are relevant for this customer, this article and this moment of time. Discounts can be applied to the invoice line and changes can be propagated to update invoice sales tax and totals. It is almost impossible to do this type of change propagation in the REST, if part of the business object in session are stored in the server side.
  • Business logic type 3. Processing of business objects. E.g. if invoice is marked as ordered then Spring application can make extensive changes in other database objects - e.g. update inventory levels, plan shipping activities, create accounting entriess and so on. Spring could do this and Spring will still be able to do this in REST application. This is the only type of business logic that I can retaing from my initial application.

So - it seems to me that migration from Spring+JSF to Spring+AngluarJS requires rewrite of almost three fourths (3/4) of application. Does adding new type of GUI (and new type of communication - REST) to existing application should be so involved?

I am thinking about two problemts

  • Alternative to REST. All my migration problems come from the requirement that AngularJS should use REST for communication with server state (Spring) objects and session. Maybe there are alternatives to REST? JSF/facelets is already doing lot of JavaScript for for communication with server, maybe AngluarJS can be adapted to this?
  • I am uneasy about writing business logic in JavaScript. We are doing lot of work for automatic generation of Java code from models and we would like to keep this experience. There are lot of strange thins about OO JavaScript. And beside Java is researched a lot more in this regard.

So - the main question is - is there alternative to REST for SPA business application (AngularJS) communication with the stateful business logic that is implemented in the server side application (Spring/Java/Enterprise Java)?

  • I am seeking alternative to REST stackoverflow.com/questions/37367586/… JSF AJAX can call server side functions and getters/setter directly and retrieve result, there is no REST. This protocol can be used for AngularJS-Spring communication as well. The problem is, that I don't know internals of this protocol and I am not aware about independent (outside JSF) implementation of this protocol.
    – TomR
    Commented May 21, 2016 at 20:23
  • 1
    It sounds like its not rest that you want an alterative for. You are not replacing spring. You want a js framework which integrates with spring
    – Ewan
    Commented May 24, 2016 at 13:06
  • To echo others, REST isn't the issue. If you are using HTTP you are already using REST (though you could be using it wrong). I think the issue is that Spring/JSF does a lot of HTML generation server side (even though that is still sent over HTTP to the web browser) but with an Angular app now you are putting more logic into the client by using Javascript on the browser. That concern (which code should do what where) is literally nothing to do with REST though. I think you are confusing javascript heavy single page apps with the ideas of REST. Very different. Commented May 24, 2016 at 20:10

1 Answer 1


There is a gross misconception somewhere. I think it is near this idea.

In Spring+JSF application all the business logic was encoded in special layer - Spring entities and services. In Spring+REST+AngluarJS this should be different. I don't want to rewrite (move) business logic from Spring/Java to AngularJS/JavasScript but obviously I am required to

No, that isn't obvious at all. Why would the implementation details of your application state require you to rewrite your domain model? Those are completely orthogonal concerns.

REST architecture requires that session and business objects are stored in client (Browser JavaScript objects).

Not at all. REST architecture calls for sending representations of application state to the client.

Put very simply, the client and the server are just sending messages back and forth, so that the client can successfully navigate the application protocol. The side effects that the application protocol has on the domain model are limited to the server.

Review Jim Webber's How to GET a cup of coffee.

  • 2
    +1 totally in agreement with Voice. What I think is happening is that his current code is highly tied to view layer and to change this into a SPA with any sort of JS framework will demand a deep redesign instead of a mere refactor. There's no miraculous alternatives that could release to him to such work. To pass from JSF to any other design use to be painful. JSF is one of the worse thing I have ever seen in Java for many and tedius reasons.
    – Laiv
    Commented May 21, 2016 at 12:41
  • 1
    No, my code is neatly separated into business and GUI layers. It is true, that application is really responsive/reactive, but the layers are separated. E.g. if user changes line price, then InvoiceLine.setPrice(newPrice) is called from Spring/Managed beans layer and the business logic propagates those changes to other business objects - line totals, invoice totals, taxes, etc. And view layer can retrieve the updated values via InvoiceLine.getLineTotal(), etc. All the business logic sits in its layer.
    – TomR
    Commented May 21, 2016 at 20:27
  • 1
    One can imagine to do such update with REST, the should be so much calls: 1) REST update of single price; 2) REST GET for InvoiceLine; 3) REST GET for Invoice; 4) REST GET for SalesTax objects. I don't see the way to keep state in the server side with the REST...
    – TomR
    Commented May 21, 2016 at 20:28
  • 1
    Business logic is lot more than Domain model. Business logic involves services for processing business objects and also processing events (when data are changed and so on).
    – TomR
    Commented May 21, 2016 at 20:30
  • Add it all in js and have one validateInvoice call
    – Ewan
    Commented May 24, 2016 at 12:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.