Note that there are some explanatory texts on larger screens.

plurals
  1. POJSF ViewHandlerWrapper causes NullPointerException
    primarykey
    data
    text
    <p>I have a little issue with a JSF ViewHandlerWrapper that I've coded. It works fine most of the times, but at times I will get a NullPointerException from the very core of Mojarra and thus started to wonder whether I implemented my ViewHandlerWrapper correctly.</p> <pre><code>public class TokenViewHandler extends ViewHandlerWrapper { private ViewHandler parent; public TokenViewHandler(ViewHandler parent) { this.parent = parent; } @Override public ViewHandler getWrapped() { return parent; } @Override public void renderView(FacesContext context, UIViewRoot viewToRender) throws IOException, FacesException { final String token = UUID.randomUUID().toString(); findAndModifyForms(viewToRender, token, context); getWrapped().renderView(context, viewToRender); } private void findAndModifyForms(final UIComponent component, final String token, final FacesContext ctx) { if (component instanceof UIForm) { final HtmlInputHidden hidden = (HtmlInputHidden) ctx.getApplication().createComponent(HtmlInputHidden.COMPONENT_TYPE); hidden.setValue(token); component.getChildren().add(hidden); } else { for (UIComponent tempComponent : component.getChildren()) { findAndModifyForms(tempComponent, token, ctx); } } } } </code></pre> <p>From the code you quickly realize that I want to add a <strong>inputHidden</strong>-component with a UUID value to each <strong>form</strong> on the view.</p> <p>As I haven't found any good examples for ViewHandlerWrappers I assumed that it should look like a ExceptionHandlerWrapper but since I get the occassional NPE using my ViewHandler, I assume that something is wrong and I can't seem to see it.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload