- java.lang.Object
-
- jakarta.faces.view.facelets.TagHandler
-
- org.omnifaces.taghandler.EnableRestorableView
-
- All Implemented Interfaces:
FaceletHandler
public class EnableRestorableView extends TagHandler
The
<o:enableRestorableView>
taghandler instructs the view handler to recreate the entire view whenever the view has been expired, i.e. wheneverViewHandler.restoreView(FacesContext, String)
returnsnull
and the current request is a postback. This effectively preventsViewExpiredException
on the view. This tag needs to be placed in<f:metadata>
of the view.There are however technical design limitations: the recreated view is exactly the same as during the initial request. In other words, the view has lost its state. Any modifications which were made after the original initial request, either by taghandlers or (ajax) conditionally rendered components based on some view or even session scoped variables, are completely lost. Thus, the view should be designed that way that it can be used with a request scoped bean. You can use it with a view scoped bean, but then you should add a
@PostConstruct
which checks if the request is a postback and then fill the missing bean properties based on request parameters.Usage
To enable the restorable view, just add the
<enableRestorableView>
to the view metadata.<f:metadata> <o:enableRestorableView/> </f:metadata>
Mojarra's new stateless mode
Since Mojarra 2.1.19, about 2 months after OmniFaces introduced the
<o:enableRestorableView>
, it's possible to enable a stateless mode on the view by simply setting itstransient
attribute totrue
:<f:view transient="true"> ... </f:view>
This goes actually a step further than
<o:enableRestorableView>
as no state would be saved at all. However, on those kind of pages where<o:enableRestorableView>
would work just fine, this statelessness should not form any problem at all. So, if you have at least Mojarra 2.1.19 at hands, use thetransient="true"
instead.- Since:
- 1.3
- Author:
- Bauke Scholtz
- See Also:
OmniViewHandler
-
-
Field Summary
-
Fields inherited from class jakarta.faces.view.facelets.TagHandler
nextHandler, tag, tagId
-
-
Constructor Summary
Constructors Constructor Description EnableRestorableView(TagConfig config)
The tag constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
apply(FaceletContext context, UIComponent parent)
Enable the current view to be restorable.static boolean
isRestorableView(UIViewRoot view)
Returns true if given view indeed containsEnableRestorableView
.static boolean
isRestorableViewRequest(FacesContext context, UIViewRoot view)
Returns true if given view is null, and this is a postback, andEnableRestorableView
has been activated.-
Methods inherited from class jakarta.faces.view.facelets.TagHandler
getAttribute, getRequiredAttribute, toString
-
-
-
-
Constructor Detail
-
EnableRestorableView
public EnableRestorableView(TagConfig config)
The tag constructor.- Parameters:
config
- The tag config.
-
-
Method Detail
-
apply
public void apply(FaceletContext context, UIComponent parent) throws IOException
Enable the current view to be restorable. This basically sets a specific view attribute which theOmniViewHandler
could intercept on.- Throws:
IllegalStateException
- When given parent is not an instance ofUIViewRoot
.IOException
-
isRestorableViewRequest
public static boolean isRestorableViewRequest(FacesContext context, UIViewRoot view)
Returns true if given view is null, and this is a postback, andEnableRestorableView
has been activated.- Parameters:
context
- The involved faces context.view
- The involved view.- Returns:
- true if given view is null, and this is a postback, and
EnableRestorableView
has been activated.
-
isRestorableView
public static boolean isRestorableView(UIViewRoot view)
Returns true if given view indeed containsEnableRestorableView
.- Parameters:
view
- The involved view.- Returns:
- true if given view indeed contains
EnableRestorableView
.
-
-