How to customize error message in store front

Unexpected conditions is something, which is unavoidable in any application. So is Hybris store front. There may be hundreds of situations, where you would like to show an error message to users. The error could be because of, wrong user input, unavailability of data, inadequate exception handling or some thing else. But the bottom line is, it is unavoidable.

Hybris provides a very flexible and modular approach to show error messages. But your customer may still want to customize the way we show error messages in store front.

GlobalMessages class

While serving a particular request in your java classes (controllers, facades, service, dao etc), whenever you come across a error situation (like validation error or a possible null pointer etc), you should use this class. This class provides static methods to add error messages to your model object.

There are different type of messages, you can add to your model. They include confirmation message, error or warning messages.

global

 

globalMessages.tag

This tag is used to actually render the error message at a particular position and some css. Now you can customize the csss as you want.

error

The error messages, are present in base properties. If you want to add a new type of error message to your store front, you should do that in Global message class.

Why hybris deprecated tenant scope?

To understand, the meaning of tenant scope, see my previous post on scopes in hybris. With version 5.0 , hybris decided to deprecate tenant scope.

In verion 5, Hybris has tenant specific application contexts. So the bean you will get will be singleton by default, which is already limited to a tenant. So there is no need to have a different scope called tenant.

scopes

 

 

As you can see fro above picture, each tenant creates its own set of application context, so now tenant scope is redundant.

Source : Hybris Wiki

What are different scopes in Hybris?

The scope can be defined as a virtual space, situation or time line, under which a particular activity is valid or possible. In terms of Hybris, the scope is the time for which a bean is available for performing business logic.

In addition to Spring scopes, Hybris has defined below scopes.

1) Tenant : This is equivalent  to singleton scope of spring. The only difference is that here Hybris limit the instance of bean in question to a particular tenant.

Hybris has deprecated this scope in version 5.0.

2) yrequest : This scope is equivalent to request scope. But this is used out side the web application context. It means that you can access these beans even in absence of a web application. These are basically used in back end processes, where we don’t want to expose our services on web, but still want to use them from outside of our project.

Once a session is invalidated, the scope ceases to exist, and instances are destroyed.

Why Hybris deprecated Jalo layer?

Or Explain difference between Jalo layer and Service layer?

Hybris 4.3.0, deprecated the Jalo layer for item types. This means, that hybris discouraged the usage of Jalo classes to serve as utility methods for performing business logics.

Prior to service layer, Jalo classes used to have both data model logics, methods and also business logic methods.

<itemtype code=”PickingCenter”
autocreate=”true” generate=”true”>
<deployment table=”PICKING_CENTER” typecode=”22113″/>
<attributes>
           <attribute qualifier=”warehouseForFresh” type=”Warehouse”>
           <persistence type=”property” />
           <modifiers read=”true” write=”true” optional=”true” />
           <description>Warehouse for fresh items</description>
</attribute>
</attributes>
</itemtype>

A sample item type in items.xml

The build framework will generate below classed for this item type:

1) An abstract class : GeneratedPickingCenter –  This class is basically a data model class, which has getter/setter for accessing data model, like attributes of data model. 

3

 

2) PickingCenter.java

Non Abstract class : This class extends the Generated class, and can have other methods for accommodating business logic.

So what is the big deal?

1) Service layer comes with the idea of segregating business logic from data model. Service layer sits inside other extensions (not necessarily) and access data layer via DAOs.  This layer is much more flexible and loosely coupled with database.

2) Think of a scenario, where you are using a legacy code, you don’t have access to source code. Had it been all Jalo, How would you override a business logic? In service layer it is easy to override, since ever service is configured as a bean, which is more adaptable to spring MVC design pattern.

3) If there is a change in database design, you need not to change your service layer necessarily. This flexibility is not available in Jalo layers.

4) In Jalo, we use like below:                                                                                                VoucheManager vm = VoucherManager().getInstance();

In Service layer,                                                                                                          private VoucherService voucherService;

So we can inject any implementation of VoucherService in our custom code, but how do we do so in Jalo. We need to break into Jalo layers.

Source : Hybris Wiki

Set up a MVC application in hybris

Background

There are times, when OOB cockpits, applications are not sufficient for client requirements.  Customizing cockpit is often a tedious task as it involves struggle with adamant ZK framework.

Alternative

Hybris never discouraged us to create more flexible MVC applications and still use the powerful platform features. This acts just like other full fledged application and run inside same hybris server.
1. Create a new extension. Let’s call it Backoffice.
1