@PostConstruct & @PreDestroy annotation in JSF

Quick JSF tip-

I found these two annotation really useful and very tricky too.It should be used at right time otherwise you will see error like me. 🙂

@PostConstruct as per Oracle Doc-
The PostConstruct annotation is used on a method that needs to be executed after dependency injection is done to perform any initialization. This method MUST be invoked before the class is put into service. This annotation MUST be supported on all classes that support dependency injection. The method annotated with PostConstruct MUST be invoked even if the class does not request any resources to be injected. Only one method can be annotated with this annotation. The method on which the PostConstruct annotation is applied MUST fulfill all of the following criteria – – The method MUST NOT have any parameters except in the case of EJB interceptors in which case it takes an InvocationC ontext object as defined by the EJB specification. – The return type of the method MUST be void. – The method MUST NOT throw a checked exception. – The method on which PostConstruct is applied MAY be public, protected, package private or private. – The method MUST NOT be static except for the application client. – The method MAY be final. – If the method throws an unchecked exception the class MUST NOT be put into service except in the case of EJBs where the EJB can handle exceptions and even recover from them.

ok .Quite good description and confusing too.

To Initialize a Managed Bean we use the @PostConstruct Annotation.As we see that @PostConstruct Annotation is mostly used to initialize the resources that are Context specific. The method which you marked with @PostConstruct Annotation will be called immediately by the Container as soon as an instance of bean is created. There are few certain guidelines to be followed, while creating the PostConstruct method such as-

– The method should not be marked as static.
– Return type should be void.
– It should not throw any checked Exceptions and so on….

I did a mistake of calling a bean and i got some null on the bean.Not sure what is problem. After spending my few hours on it 🙁 .
I found the problem.I am calling before the instantiation of the bean.after using this annotation, it resolved the issue , so sharing with everyone.

I have a method which is clearing all the value .i used annotation like this

@PostConstruct
public void clear() {
    this.userName = "";
    this.userBal= 0;
    this.maximum = maxNumber;
    this.number = randomInt.get(); 
}


@PreDestroy-
counter-part to @PostConstruct Annotation is the @PreDestroy Annotation. As the name specify, we know that the method that is marked with this Annotation will be called before object is going to be removed or destroyed by the Container. Like the @PostConstruct Annotation, this is also a method-Level Annotation and i used like this

@PreDestroy()
    public void releaseConnection()
    {
 
        // Close the Connection.
     
    }

method releaseConnection() will call by the container, before the object is going to be destroyed. In Jee 6 ,CDI calls this method before starting to destroy the bean.

Full text search using RIDC API in webcenter Content (UCM)

Requirment -I got task to accomplish to Search UCM using RIDC.

Solution– After spending so much time on it.I got solution on some blog.Not recall the blog name.for my reference , i am writing here.

We need to change some confi file which is in specified path –

Oracle/middleware/userprojects/yourdomain/ucm/cs/config/confing.cfg

There will be property name ‘SearchIndexerEngineName’ equal OracleTextSearch i.e

SearchIndexerEngineName=OracleTextSearch

Delete this and add the following one

SearchIndexerEngineName=DATABASE.FULLTEXT

Then by calling the RIDC API it enable Full text Search in UCM.

IdcClientManager manager = new IdcClientManager();
IdcClient idcClient = manager.createClient(“idc://192.167.3.232:4444″);

IdcContext userContext =new IdcContext('username', 'pwd'); 
DataBinder binder = idcClient.createBinder();

binder.putLocal(“IdcService”, “GET_SEARCH_RESULTS”);
binder.putLocal(“QueryText”,“dDocFullText <substring> <qsch>” + “our query” +”</qsch>”);

binder.putLocal(“SearchEngineName”, “databasefulltext”);
binder.putLocal(“ResultCount”, “10″);

ServiceResponse response = idcClient.sendRequest(userContext, binder);
DataBinder serverBinder = response.getResponseAsBinder();
binder = response.getResponseAsBinder();

DataResultSet resultSet =binder.getResultSet(“SearchResults”);
for (DataObject dataObject : resultSet.getRows()) 
{
  System.out.println(“Title is: ” + dataObject.get(“dDocTitle”));
  System.out.println(“Author is: ” + dataObject.get(“dDocAuthor”));
}


Restart the UCM server and try search again.

happy coding with Vinay in techartifact . 🙂

Webcenter Portal vs Webcenter Spaces

Confusion – Webcenter Portal vs Webcenter Spaces , which one to choose and when.

Webcenter Spaces- WebCenter Spaces is designed to provide a collaborative environment. It integrates all the necessary services such as documents, discussions, events, linking, tagging.In WebCenter Spaces, you build group spaces. Each space is a separate mini-portal with its own configuration, look and feel, security model, and services.

Well one thing is sure.both is fine and works well.But you need to choose in cost,learning,effrot and what you really need it.WebCenter Spaces is ideal to build intranets where you have to collaborate a lot with other.WebCenter Spaces also has a rich set of features for social networking. It has Facebook-like features: you can invite other people to your network, write on their wall, and so on.Oracle WebCenter Spaces allows users to work more effectively with project teams and work groups, including teams that span multiple geographies and include external members. It eliminates or reduces duplication of efforts and content inconsistencies, and it enables sharing valuable team resources to solve business problems, tap into new ideas, and reduce time to market.You can add services, portal,custom taskflow etc.

Webcenter portal –
Oracle WebCenter Portal delivers intuitive user experiences for enterprise applications. This complete, open and integrated enterprise portal and composite applications solution enables the development and deployment of internal and external portals and websites, composite applications and mashups with integrated social and collaboration services and enterprise content management capabilities

Choose Webcenter Spaces if –

-If you don’t need much customization , then choose spaces.It require less effort and development.
-When you require different group spaces, you will also go for WebCenter spaces because such a concept is very hard to build for yourself.
– If your need is something that is more ‘social and collaborative’, then Spaces may be the best place to start.
– You can enable and disable some of the spaces.
– It is role based access.
– When you need people connection like linkedin, facebook like button,personal pages.You can comment, favorite,discussion,event etc – Spaces is best option.

Choose Webcenter Portal if –

– If customization is there.Portal is best.
– You have full control over it.
– More effort required to develop personel pages and space.

Except these points, it also depend on your resources skills, time constraint and architect choice as well 🙂

When you need a high level of customization or you need to extend the site with your custom functionality, then you should create a WebCenter Portal application. When you need a collaborative environment where customization or added functionality is not as important as the collaborative services, then go for WebCenter Spaces.

happy coding with Vinay in techartifact . 🙂