0

This is my snipped part of xhtml. I have on condition changing styleClass.

`<p:panel id="upload_host" header="CIB HOST" styleClass="#{(bulkToHostBean.titleBackground == 'true') ? 'greencolor' : 'redcolor'}">`

Below is my bean class file. The main purpose of this class file is to return boolean true or false.

@ManagedBean
@SessionScoped
public class BulkToHostBean {
......
private boolean titleBackground;


public boolean getTitleBackground() {

    int counter = 0;

    for(int i = 0; i < hostList.size();i++ ) {
        if(hostList.get(i).getFile_status().trim().equals(Constant.DELAYED)) {
            counter = counter + 1;
        }

    }
    //counter = 0;
    if(counter == 0) {      
        logger.info("Set title background to Green");
        titleBackground = true;
    }else {
        logger.info("Set title background to DarkRed");
        titleBackground = false;
    }
    return titleBackground;
}

public void setTitleBackground(boolean titleBackground) {
    this.titleBackground = titleBackground;
} 

And below is my console result from my eclipse. As you can see, the result printed twice at the same time.

Sep 13, 2017 5:00:50 PM 
com.sheaf.payment.dashboard.managedbeans.BulkToHostBean getTitleBackground
INFO: Set title background to DarkRed
Sep 13, 2017 5:00:50 PM 
com.sheaf.payment.dashboard.managedbeans.BulkToHostBean getTitleBackground
INFO: Set title background to DarkRed

The code is working fine but I just wonder why it call method two times? Any idea why it call two times?

Mel
  • 5,837
  • 10
  • 37
  • 42
shanelim
  • 11
  • 1
  • 4
  • 1
    Possible duplicate of [Why JSF calls getters multiple times](https://stackoverflow.com/questions/2090033/why-jsf-calls-getters-multiple-times) – Aritz Sep 13 '17 at 10:48
  • XtremeBiker has a valid point, but besides that are you sure it is accessed twice and not just logged twice due to a log configuration (happened to me once)? – Kukeltje Sep 13 '17 at 14:07
  • @Kukeltje , i don't think so it is related to log configuration that logged twice since i had a similar method public String getStyleBackground{} in my class file also, and it's only called once and logged once but for this public boolean getTitleBackground{} method it's called and logged twice. – shanelim Sep 14 '17 at 03:55
  • 2 panels using it? – Kukeltje Sep 14 '17 at 05:56
  • No, only one panel. – shanelim Sep 14 '17 at 07:00
  • Don't you need to implement Serializable in your class? – ziMtyth Sep 14 '17 at 08:08
  • @ZiMtyth Same,nothing changed after implement Serializable – shanelim Sep 14 '17 at 10:37
  • @shanelim maybe this link: https://stackoverflow.com/questions/5166086/why-is-my-onchange-function-called-twice-when-using-focus can give you some help. and check that duplicate comment. – ziMtyth Sep 14 '17 at 10:48
  • Thanks, anyway i will look at it first. – shanelim Sep 15 '17 at 07:47

0 Answers0