0

I'am trying to get timezone property from backing bean but it fail because getter() is called before its value is initiated.

Here is pieces of code:

<p:outputLabel value="#{bean.startDate}">
    <f:convertDateTime pattern="#{msg['dateformat.yyymmdd']}"
    timeZone="#{bean.timezone}" />
</p:outputLabel>

And backing bean:

public void init(){
    timezone= getUserTimeZone();
}

public String getTimezone() {
    return timezone;
}

Can anyone explain why this happen?

Quân Trần
  • 31
  • 1
  • 6
  • Apparently you initiated it at the wrong moment? I'm not seeing a `@PostConstruct` annotation on `init()` method. – BalusC Feb 27 '16 at 09:41
  • @BalusC I think it is correct, bean class have a `@ViewScoped`. It is fine with other property or that `timezone` property in another component attribute like p:outputLabel value – Quân Trần Feb 27 '16 at 10:05
  • If it was correct you wouldn't have asked this question. Put `@PostConstruct` on that method. – BalusC Feb 27 '16 at 10:05
  • @BalusC Thank you, it worked. Can I know why `@PostConstruct` is need in this situation? – Quân Trần Feb 27 '16 at 10:24
  • If you don't use the `@PostConstruct` annotation your init method won't be hit unless you especifically invoke it from the view... – Aritz Feb 27 '16 at 12:14
  • @XtremeBiker Yes. I do invoke it from the view with f:event – Quân Trần Feb 29 '16 at 02:04

0 Answers0