0

I wanted to call constructor when I click link second time. For first Time it's calling constructor.

Here is example,

I have few navigation links

  • Link 1
  • Link 2
  • Link 3

When I click on Link 2, It call Link 2 constructor and then I click on Link 3 then its call Link 3 constructor, Now when I click back to Link 2 then Just page displayed but constructor of Link 2 is not calling.

How to call Link 2 constructor whenever I click on Link 2?

I am using PrimeFaces + Java

Cœur
  • 37,241
  • 25
  • 195
  • 267
Neerajkumar
  • 300
  • 4
  • 19

1 Answers1

0

You should @PostConstruct annotation instead of regular constructer to be sure that dependencies are injected and the (post construct) method wil be called only once in bean's life cycle.

Why use @PostConstruct?

There are bean species with different life cycles.

How to choose the right bean scope?

At your situation, you want a new bean for every page or request. So you could use ViewScoped or RequstScoped bean.

Example:

@ManagedBean
@ViewScoped
public class L2sTestOrderBean {

@PostConstruct
public void init(){

//initialize

}

}
Community
  • 1
  • 1
furkan
  • 270
  • 1
  • 7