- java.lang.Object
-
- jakarta.faces.application.ViewHandler
-
- jakarta.faces.application.ViewHandlerWrapper
-
- org.omnifaces.viewhandler.NoAutoGeneratedIdViewHandler
-
- All Implemented Interfaces:
FacesWrapper<ViewHandler>
public class NoAutoGeneratedIdViewHandler extends ViewHandlerWrapper
This
ViewHandler
once installed will during development stage throw anIllegalStateException
whenever an automatically generated Faces component ID (j_id...
) is encountered in the rendered output. This has various advantages:- Keep the HTML output free of autogenerated Faces component IDs.
- No need to fix the IDs again and again when the client side unit tester encounters an unusable autogenerated ID.
- Make the developer aware which components are naming containers and/or implicitly require outputting its ID.
Note that this does not check every component for its ID directly, but instead checks the
ResponseWriter
for writes to the "id" attribute. Components that write their markup in any other way won't be checked and will thus slip through.Additionally, since version 3.0 it will also log a warning line when
prependId="false"
is encountered. This is considered bad practice. See also UIForm with prependId=“false” breaks <f:ajax render>.Installation
Register it as
<view-handler>
infaces-config.xml
.<application> <view-handler>org.omnifaces.viewhandler.NoAutoGeneratedIdViewHandler</view-handler> </application>
Note that this only runs if
Application.getProjectStage()
equals toProjectStage.Development
.- Since:
- 2.0
- Author:
- Arjan Tijms
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
NoAutoGeneratedIdViewHandler.NoAutoGeneratedIdResponseWriter
This response writer throws anIllegalStateException
when an attribute with name "id" is written with a non-null value which starts withUIViewRoot.UNIQUE_ID_PREFIX
or contains an intermediate.
-
Field Summary
-
Fields inherited from class jakarta.faces.application.ViewHandler
CHARACTER_ENCODING_KEY, DEFAULT_FACELETS_SUFFIX, DEFAULT_SUFFIX, DEFAULT_SUFFIX_PARAM_NAME, DISABLE_FACELET_JSF_VIEWHANDLER_PARAM_NAME, FACELETS_BUFFER_SIZE_PARAM_NAME, FACELETS_DECORATORS_PARAM_NAME, FACELETS_LIBRARIES_PARAM_NAME, FACELETS_REFRESH_PERIOD_PARAM_NAME, FACELETS_SKIP_COMMENTS_PARAM_NAME, FACELETS_SUFFIX_PARAM_NAME, FACELETS_VIEW_MAPPINGS_PARAM_NAME
-
-
Constructor Summary
Constructors Constructor Description NoAutoGeneratedIdViewHandler(ViewHandler wrapped)
Construct a new No Auto Generated Id view handler around the given wrapped view handler.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
renderView(FacesContext context, UIViewRoot viewToRender)
-
Methods inherited from class jakarta.faces.application.ViewHandlerWrapper
addProtectedView, calculateCharacterEncoding, calculateLocale, calculateRenderKitId, createView, deriveLogicalViewId, deriveViewId, getActionURL, getBookmarkableURL, getProtectedViewsUnmodifiable, getRedirectURL, getResourceURL, getViewDeclarationLanguage, getViews, getViews, getWebsocketURL, getWrapped, initView, removeProtectedView, restoreView, writeState
-
-
-
-
Constructor Detail
-
NoAutoGeneratedIdViewHandler
public NoAutoGeneratedIdViewHandler(ViewHandler wrapped)
Construct a new No Auto Generated Id view handler around the given wrapped view handler.- Parameters:
wrapped
- The wrapped view handler.
-
-
Method Detail
-
renderView
public void renderView(FacesContext context, UIViewRoot viewToRender) throws IOException
- Overrides:
renderView
in classViewHandlerWrapper
- Throws:
IOException
-
-