Cascading Style Sheets & JavaServer Faces

by Tor Norbye





Listing One



public String getSeasonStyle() {

// For instructional purposes only -- my hometown has winter WAY longer than 

// this... and this won't work for the southern hemisphere

int month = calendar.get(Calendar.MONTH);

if (month <= Calendar.FEBRUARY || month >= Calendar.DECEMBER) {

   return "winter";

      } else if (month < Calendar.JUNE) {

   return "spring";

      } else if (month < Calendar.SEPTEMBER) {

   return "summer";

}  else {

      return "fall";

   }

}

private static Calendar calendar = Calendar.getInstance();



Listing Two



public String getNameStyle() {

String s = String.valueOf(getValue("#{currentRow['NAME']}"));

if (s != null && s.startsWith("A")) {

   return "highlighted";

      } else {

   return "normal";

   }

}

protected Object getValue(String expr) {

FacesContext context = FacesContext.getCurrentInstance();

Application app = context.getApplication();

ValueBinding vb = app.createValueBinding(expr);

   return (vb.getValue(context));

}







1



