Three-layered approach in PHP - java

I liked using three layers (data/business logic|services/ui) in Java and wish to apply this to a web site in PHP. What advice, links, tutorials could you suggest in this respect?
P.S: I'm particularly interested in knowing how the domain/entity objects can be written and used.

You could go with some frameworks of PHP.
They already done three layer for you
ZendFramework
CakePHP
This could be interesting for you and help you to choose right framework.
PHPFrameworks

If you want a PHP framework that actually follows the Model View Controll (MVC) pattern then you will need to look at Agavi. Many other frameworks have attempted to implement it but have failed.

Correct me if I am wrong, but this is an MVC approach (Model->View->Controller)?
If so, checkout a framework like CakePHP, they have a pretty good learning zone for you.

You could look at the MVC pattern used in many frameworks for PHP.
You could use frameworks like Kohana, Zend, CakePHP, Yii, which all uses this pattern.
MVC stands for Model-View-Controller, where the model contains the business logic, the view contains the UI, and the controller handles the requests and ties things together.

Symfony (http://www.symfony-project.org/) gets good reviews from my PHP slinging mates

Related

databinder for wicket concept & status

Seems like Wicket + DataBinder(https://github.com/wicket-databinder/wicket-databinder) is good solution if you know only plain java and need to write data-driven web app, as i am. But when i use auth functionality of dataBinder i gain error - when i register new user my password and confirm password not match. I look into the code - getConvertedInput() of RSAPasswordTextField return some long Base64 and it's different for password fields. I don't find databinder auth examples on net. Question and thought:
What is the common way of using current version of DataBinder? For example, how i can use net.databinder.auth.components.hib.DataSignInPage?
There is many todo comments in databinder. What of databinder features is stable?
I like that common web functionality is already in databinder, so i don't need reinvent the wheel. Maybe there is more actual alternative for that?
Otherwise i can contribute to databinder. Anyway i need to develop my application, so i can start from that is already in databinder. But i need status of modules(what works and how to use/what not work and what to do). Sorry for my english.
As far as I know, Nathan (author of databinder) has moved on to scala development, and databinder has since been stuck. Your best avenue is to contact Nathan, or one of the 10 forks on github to see how you can reignite development of databinder.
As I don't use databinder, I can't answer this one
I'd see the todo comments as a good pointer to where you can pick up maintaining the code base
There are several libraries that integrate with Wicket in various forms of maintenance.
Today databinder have no contributors. I write to Fausto Bencosme (he was the last). We try to use DataBinder together, but few problems occur. Fausto recommend to use Ebean. I try - looks like it works. So for newbies i recommend Ebean to.

Vaadin:A suitable Design Pattern

I'm about to start to develop a Vaadin web application, I also plan to use Spring IOC container.
As far was I know it is pretty much like a Swing application, and I see that people use Presentation Model or MVC "like" patterns.
If you have experience on Vaadin can you suggest me a design pattern regrading the structure of Vaadin framework? maybe a slightly modified version of Presentation Model or MVP or MVC whatever? I also read that there are some patterns provided in Vaadin, what are they?
Thanks
Personally, I prefer to use the MVP pattern, it keeps the code nice and clean and it suites well for Vaadin applications. There are even multiple MVP add-ons you could try out.
Maybe you could try Vaadin together with Grails. Grails gives you clear division between database, services and view layer (+ you will get Spring IoC for free). If you want to give it a try, follow this one.
If not, you can
as view, create UI with components from Vaadin
you could also use State pattern for implementation of different states of UI screens
create your implementation of DAO pattern (and put somewhere there also your domain classes)
and use Listener pattern for action
The second option without Grails is pure Java, but it is also more painful.
If you're using Spring and Vaadin together, consider using the Spring Stuff Vaadin add-on for application autowiring, etc.
Disclaimer: I'm the author

Adding business logic in JSP

This has been asked in few times in this thread. But sometimes its hard to make it decouple. Let say Im dealing with session, cookie stuff how do I decouple or basically how do I move the existing code out from the JSP? UseBean will be a good alternative. But how to deal with business logic with lot of HTTPServletRequest and HTTPServerletResponse and its related objects used services?
Thank you
Developing web-applications in Java has evolved quite a lot over the past 10 or so years. PHP-style JSP pages may have been ok-ish in 1999 but not today. At very minimum, you should isolate your business-logic in a servlet and only have your rendering/view in the JSP. That is just the bare-minimum to pass some form of basic level of hygiene. If you are doing any sort of new development or even refactoring, you should look into a more refined MVC/MVP framework. Spring is a good candidate. Maybe not the "coolest" but definitely established and well-known. The tutorial Andrea mentioned is a good place to start. And don't get too nervous about things like "how does it make sure the right request and session is used" - that is what spring-mvc does, it's the core functionality. Go through the tutorials, try it out and then dig deeper to understand what is happening under the hood and how you can customize the behavior to fit your needs.
I suggest you to use a MVC patter to add the business logic to your web application on Java classes instead of add the logic into the JSP.
Take a look to that: http://static.springsource.org/docs/Spring-MVC-step-by-step/part3.html

Understanding the need for struts 2 and commons chain in simple CRUD website

I have a simple CRUD website in development process, almost done. I was asked to refactor the code but this time use struts 2 and commons chain. I read a couple of sites like this but wasn't able to know exactly what will be the key roles done by these two (struts 2 and commons chain) in my project. I was also asked that don't worry about struts tags like in this tutorial as the code that i made earlier can be used.
Can anyone give me an insight. Thanks
Note: A day back I started to see about struts 2
Well any framework is designed (most of them) to provide some sort of ease of use. That should be the driver when you chose one.
In your case, I can comment on Struts2.
Using Struts2 provides and enforces a better design in terms of separation of your code responsibilities (model view controller). This way the over all application design is well formed.
On top of this, framework provides many interesting features like interceptors, out of box request parameter assignments, validation, ui tags etc etc which you can benefit from.
So if you are still in the starting phase, yes - go through various frameworks available and weigh them out in terms of what ease you are looking for.
If the website is almost done, I don't see any compelling reason to adapt Struts 2. In fact, the person who asked you all this is the best person to contact, in this case.
Regarding commons chain, yes it can help you implement Chain of Responsibility pattern if it can solve the cases in hand.

Java webservice: use MVC or DAO+managers

I'm trying to learn how to develop web-services in java.
Now some tutorials (I'm trying to learn how to do it myself without using a framework) use the MVC pattern and expose the class to create a WSDD file etc., other tutorials go for a DAO + managers.
Now I haven't been able to find an article discussing the differences (asking for up and downsides is probably a bit too simplistic), so I was wondering if anyone here had some insights and maybe some recommended reading (be it books or tutorials on sites) since some sites are a bit contradictory.
Thank you in advance.
DAO + managers is simply how you would implement the model part of your MVC design.
A DAO gives you access to your data store and the DAO, the managers, and all the logic are what make up your model.
The view and controller and then made up of other components and talk to the model to get information from your data store.
WSDD files simply chain these parts together.
You should be able to use both pattern together.

Categories