Search code examples
jsf-2myfacesomnifaces

java.io.NotSerializableException: org.omnifaces.taghandler.Validator


I'm trying to use Omnifaces's validator in the following lines of code:

<p:inputText
            value="#{createEventBean.newGuest.name}">
            <o:validator validatorId="javax.faces.Required"
                                 message="Numbers only" />
</p:inputText>

But I get the following error:

 DefaultFacele E   Exiting serializeView - Could not serialize state: org.omnifaces.taghandler.Validator
                                 java.io.NotSerializableException: org.omnifaces.taghandler.Validator

The most close SO discussion to this issue I find here: java.io.NotSerializableException - org.omnifaces.taghandler.Converter but I use MyFaces 2.0.3 implementation by Websphere 8.0.0.9 together with PrimeFaces 5.1, can it be the same bug? This lines of code work without any issues:

<p:inputText id="phone" styleClass="mask-num"
                            value="#{adminBean.user.mobilePhone}">
                            <o:validator validatorId="javax.faces.RegularExpression"
                                pattern="[0-9-]*" message="Numbers only" />
                        </p:inputText>

Am I use it wrong or is there workaround for this issue? Thank you.


Solution

  • This is a bug in MyFaces. I can't tell which MyFaces version exactly contains the fix, but I can tell that this construct works fine in at least MyFaces 2.1.12. However, upgrading MyFaces in WebSphere might not be a trivial task (technically and bureaucracy).

    Your best bet is to tell MyFaces to not serialize the whole view state in session, but instead keep it in memory and hold a reference (like as Mojarra by default does). You can do that via the following context param in web.xml:

    <context-param>
        <param-name>org.apache.myfaces.SERIALIZE_STATE_IN_SESSION</param‌​-name>
        <param-value>false</param-value>
    </context-param>
    

    See also: