Format Date output in JSF

Use <f:convertDateTime>. You can nest this in any input and output component. Pattern rules are same as java.text.SimpleDateFormat. <h:outputText value=”#{someBean.dateField}” > <f:convertDateTime pattern=”dd.MM.yyyy HH:mm” /> </h:outputText>

Defining and reusing an EL variable in JSF page

You can use <c:set> for this: <c:set var=”myVar” value=”#{myBean.data.something.very.long}” scope=”request” /> This EL expression will then be evaluated once and stored in the request scope. Note that this works only when the value is available during view build time. If that’s not the case, then you’d need to remove the scope attribtue so that it … Read more

Method must have signature “String method() …[etc]…” but has signature “void method()”

Ignore it. Eclipse is a jerk. You can tone it by setting Window > Preferences > Web > JavaServer Faces Tools > Validation > Type Assignment Problems > Method expression signature incompatibility to Warning or Ignore (it defaults to Error). Image borrowed from this blog in all courtesy. The reason is, Eclipse expect the action … Read more

What are the differences between ${} and #{}?

#{} are for deferred expressions (they are resolved depending on the life cycle of the page) and can be used to read or write from or to a bean or to make a method call. ${} are expressions for immediate resolution, as soon as they are encountered they are resolved. They are read-only. You can … Read more

JSP EL String concatenation [duplicate]

Using java string concatenation works better. #{var1 == 0 ? ‘hi’ : ‘hello’.concat(var2)} The benefit here is you can also pass this into a function, for instance #{myCode:assertFalse(myVar == “foo”, “bad myVar value: “.concat(myVar).concat(“, should be foo”))}

EL access a map value by Integer key

Initial answer (EL 2.1, May 2009) As mentioned in this java forum thread: Basically autoboxing puts an Integer object into the Map. ie: map.put(new Integer(0), “myValue”) EL (Expressions Languages) evaluates 0 as a Long and thus goes looking for a Long as the key in the map. ie it evaluates: map.get(new Long(0)) As a Long … Read more

How to call a static method in JSP/EL?

You cannot invoke static methods directly in EL. EL will only invoke instance methods. As to your failing scriptlet attempt, you cannot mix scriptlets and EL. Use the one or the other. Since scriptlets are discouraged over a decade, you should stick to an EL-only solution. You have basically 2 options (assuming both balance and … Read more

How does EL empty operator work in JSF?

From EL 2.2 specification (get the one below “Click here to download the spec for evaluation”): 1.10 Empty Operator – empty A The empty operator is a prefix operator that can be used to determine if a value is null or empty. To evaluate empty A If A is null, return true Otherwise, if A … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)