OptimusFaces 2.0 has been released! It is built on OmniPersistence 2.0, which was released last week. And OptimusFaces 2.0 already supports PrimeFaces 17! The other highlights are entities which no longer need to extend BaseEntity, sorting by multiple columns, and value based paging to any page.
PrimeFaces 17
PrimeFaces 17, which is almost released and currently already available as 17.0.0-M1, comes with a completely rewritten theming, and it's a big step forward. The themes are no longer compiled from SASS variables. They are built on CSS variables, which the components read at runtime. PrimeFaces calls them "design tokens" here and there. Customizing a theme is therefore a matter of plain CSS in your own stylesheet:
:root {
--p-primary-base: #0a7d5a; /* Your brand color; the whole palette from 50 to 950 follows, and so does a readable text color on top of it. */
}
:root {
--p-primary-base: var(--p-orange-500); /* Or one of the colors of the theme's own palette. */
--p-button-border-radius: 2rem; /* Rounded buttons. */
--p-form-field-border-radius: 0; /* Square input fields. */
--p-datatable-header-cell-background: var(--p-surface-100); /* Grayish table headers. */
}
.sidebar {
color-scheme: dark; /* A dark area inside a light page. */
}
All PrimeFaces CSS lives in cascade layers, so your own CSS simply wins, without !important and without fighting specificity.
Let's take square input fields with a green border on hover and focus, in light and dark mode, as an example. Previously, in PrimeFaces 16 and older, you had to override the selectors of the theme including their body prefix, for every input component which has its own border, and once again for dark mode, because the dark theme has its own hardcoded colors:
body .ui-inputfield,
body .ui-selectonemenu,
body .ui-selectcheckboxmenu {
border-radius: 0;
}
body .ui-inputfield.ui-state-hover,
body .ui-inputfield.ui-state-focus,
body .ui-selectonemenu.ui-state-focus,
body .ui-selectcheckboxmenu.ui-state-focus {
border-color: #0a7d5a;
box-shadow: 0 0 0 .2em rgba(10, 125, 90, .25);
}
@media (prefers-color-scheme: dark) {
body .ui-inputfield.ui-state-hover,
body .ui-inputfield.ui-state-focus,
body .ui-selectonemenu.ui-state-focus,
body .ui-selectcheckboxmenu.ui-state-focus {
border-color: #66bb6a;
box-shadow: 0 0 0 1px #66bb6a;
}
}
And then we're not even talking about the other states, such as active, disabled and invalid, which each need their own overrides as well. In PrimeFaces 17 you just set the variables of the form fields. All input components follow them, because their own variables refer to them:
:root {
--p-form-field-border-radius: 0;
--p-form-field-hover-border-color: light-dark(#0a7d5a, #66bb6a);
--p-form-field-focus-border-color: light-dark(#0a7d5a, #66bb6a);
}
Dark mode is no longer a separate theme but just the CSS color-scheme, which by default follows the OS. So you no longer need to load two separate themes next to each other. Even density (compact, normal, comfortable) can be set per area of the page. And all themes ship in the primefaces JAR itself, so the separate primefaces-themes dependency is gone. The new <pc:themeConfigurator> even gives your users a ready-made panel to pick color scheme, density, primary color and theme themselves, and it remembers their choice.
One visible change is the prefix of the CSS classes: ui- has become p-. The CSS classes which <op:dataTable> and <op:column> add follow it. So the OptimusFaces-specific .ui-datatable-actions becomes .p-datatable-actions on PrimeFaces 17. Adjust your own CSS on these classes when you move to PrimeFaces 17.
The same OptimusFaces JAR still runs on PrimeFaces 16 and older. ExtendedDataTable#getCssPrefix() picks the prefix from the PrimeFaces version in use, and you can use it in your own templates as well. Inside the table, #{component.namingContainer} is the table component itself, so a custom cell can use the input group of PrimeFaces like this:
<op:column field="price">
<ui:define name="cell">
<h:panelGroup layout="block" styleClass="#{component.namingContainer.cssPrefix}inputgroup">
<h:outputText styleClass="#{component.namingContainer.cssPrefix}inputgroup-addon" value="EUR" />
<p:inputNumber value="#{item.price}" />
</h:panelGroup>
</ui:define>
</op:column>
This renders ui-inputgroup on PrimeFaces 16 and older, and p-inputgroup on PrimeFaces 17.
The header of <op:dataTable> got a default stylesheet. Its layout is a flexbox now. The global search field and its button form an input group which takes the remaining width, and the export buttons follow on the same line. Here's an example:
<op:dataTable id="table" value="#{personBacking.model}" searchable="true" exportable="true">
<op:column field="id" />
<op:column field="email" />
<op:column field="status" />
<op:column field="dateOfBirth" />
</op:dataTable>
This is how it looks with the default theme of PrimeFaces 17:
And this is how it looks with the default theme of PrimeFaces 16 and older:
You'll notice that the PrimeFaces 17 theme is leaner.
The OptimusFaces integration tests run on 17.0.0-M1, next to 16.0.4 and 15.0.21.
When migrating your own CSS, every ui- selector becomes p-, and the CSS variables of the old themes such as --primary-color are gone. See the PrimeFaces 17 migration guide.
Any entity
Since OmniPersistence 2.0 you're not anymore required to extend BaseEntity nor BaseEntityService. You can just @Inject the EntityRepository of OmniPersistence 2.0 for your entity and rely on the @Id of your entity:
@Named
@RequestScoped
public class PersonBacking {
private PagedDataModel<Person> model;
@Inject
private EntityRepository<Long, Person> repository;
@PostConstruct
public void init() {
model = PagedDataModel.lazy(repository).build();
}
public PagedDataModel<Person> getModel() {
return model;
}
}
In case you want another row key than the @Id, such as a public reference, set both rowKey and rowData on the builder:
model = PagedDataModel.lazy(repository)
.rowKey(Person::getReference)
.rowData(personService::getByReference)
.build();
Sorting, paging and serialization
<p:dataTable> has been able to sort by multiple columns for ages, since PrimeFaces 3.5 actually. <op:dataTable> has finally caught up. Set sortMode="multiple" on it to sort by more than one column. A click on a column header with Ctrl or Cmd pressed adds the column to the sort. A click without replaces the sort. The query string holds one o parameter per sorted column, such as ?o=gender&o=-email, so a sorted table stays bookmarkable.
When you use the paging buttons of <op:dataTable>, OptimusFaces transparently uses value based paging, also known as keyset paging, instead of offset based paging. This is much faster than an SQL OFFSET on large tables. In 1.x it only worked for the page next to the current one. The model now caches the ordering values of the pages it has loaded, and jumps to any page from the nearest one, with a small offset for what's left.
The PagedDataModel#lazy() no longer serializes the entities of the loaded page and of the selection. After deserialization it loads the same page again and resolves the selection again. So your entities need not be Serializable, and a passivated or replicated session no longer holds them.
Upgrading from 1.x
OptimusFaces 2.0 is not binary compatible with 1.x, and OptimusFaces 1.x does not run on OmniPersistence 2.0. Recompile your code against both. Generally this goes without problems. Most likely you only need to change the import of Page to org.omnifaces.persistence.query.Page. The upgrade notes list the rest, and the release notes have the complete list of breaking changes, changes in behavior, new features and fixes.
Installation
It still requires a minimum of Java 17, Jakarta EE 10 Web Profile, OmniFaces 4.0 and PrimeFaces 15.0.0, and it now requires OmniPersistence 2.0 instead of 1.x.
Non-Maven users: download OptimusFaces 2.0 JAR and OmniPersistence 2.0 JAR and drop them in /WEB-INF/lib the usual way, replacing the older versions if any.
Maven users: just the OptimusFaces dependency is sufficient; OmniPersistence 2.0 is fetched transitively.
<dependency>
<groupId>org.omnifaces</groupId>
<artifactId>optimusfaces</artifactId>
<version>2.0</version>
</dependency>



No comments:
Post a Comment