跳至主要内容

博文

目前显示的是标签为“jsf”的博文

JSF 2.3:Websocket support

Websocket support One of the most attractive features is JSF 2.3 added native websocket support, it means you can write real-time applications with JSF and no need extra effort. To enable websocket support, you have to add javax.faces.ENABLE_WEBSOCKET_ENDPOINT in web.xml . < context-param > < param-name >javax.faces.ENABLE_WEBSOCKET_ENDPOINT</ param-name > < param-value >true</ param-value > </ context-param > Hello Websocket Let's start with a simple example. @ViewScoped @Named ( " helloBean " ) public class HelloBean implements Serializable { private static final Logger LOG = Logger . getLogger( HelloBean . class . getName()); @Inject @Push PushContext helloChannel; String message; public void sendMessage () { LOG . log( Level . INFO , " send push message " ); this . sendPushMessage( " hello " ); } private ...

JSF 2.3: Class level validation with f:validateWholeBean

Class level validation with f:validateWholeBean JSF provides a f:validateBean which bridges Bean Validation to JSF, why we need another f:validateWholeBean ? This is explained in details in the VDL docs of f:validateWholeBean . Support multi-field validation by enabling class-level bean validation on CDI based backing beans. This feature causes a temporary copy of the bean referenced by the value attribute, for the sole purpose of populating the bean with field values already validated by <f:validateBean /> and then performing class-level validation on the copy. Regardless of the result of the class-level validation, the copy is discarded. in another word, it provides the capability of cross fields validation. A good example is password matching check in a signup page, we have to make sure the values in password field and password confirm field are equivalent. Create a bean validation annotation @Password . @Constraint ( validatedBy = PasswordValidator ...

JSF 2.3: UIData improvements

UIData improvements In JSF 2.3, <h:dataTable/> and <ui:repeat /> support Iterable and Map . Iterable example Let's create a simple demo to try it. The backing bean. @Model public class IterableBean { @Inject Logger LOG ; private Iterable data = Arrays . asList( " javaee 8 " , " jsf 2.3 " ); public Iterable getData () { LOG . log( Level . INFO , " called IterableBean.getData " ); return data; } } And the faclets template. <! DOCTYPE html > < html lang = " en " xmlns = " http://www.w3.org/1999/xhtml " xmlns : ui = " http://xmlns.jcp.org/jsf/facelets " xmlns : f = " http://xmlns.jcp.org/jsf/core " xmlns : h = " http://xmlns.jcp.org/jsf/html " > < f : view > < h : head > < title >JSF 2.3: DataModel Sample</ title > </ ...

JSF 2.3: Component search expression framework

Component search expression framework In before JSF versions, it uses an absolute hierarchical ID, or a relative local ID to locate a component, it is useful to rerender a component in an ajax request. For more flexible to query the component, JSF added @all , @form , @this expression to search the component to be rerendered. JSF 2.3 extends these expression by introducing new Component search expression framework , which adds some useful and powerful keywords, and also provides APIs to define your own keywords in the expression. The following table lists all new keywords added in JSF 2.3, it is just a copy from Arjan Tijms' blog entry: What's new in JSF 2.3 . Keyword Description @child(n) The nth child of the base component @composite The closest composite component ancestor of the base component @id(id) All component descendants of the base component with the specified component id @namingcontainer The closest NamingContainer ancestor of the ...