addClientBehavior error

UI Components for JSF
Post Reply
szszab
Posts: 1
Joined: 16 Jun 2015, 10:15

12 Sep 2016, 12:35

Hello All!

When I call anything UIComponent addClientBehavior function for example change (
InputText anam = new InputText();
AjaxBehavior changeBehavior = new AjaxBehavior();
changeBehavior.addAjaxBehaviorListener(new AnamAjaxChanged());
anam.addClientBehavior("change", changeBehavior);
) I had error if miss addClienBehavior its working:
java.io.NotSerializableException: org.primefaces.component.inputtext.InputText
java.io.ObjectOutputStream.writeObject0(Unknown Source)
java.io.ObjectOutputStream.defaultWriteFields(Unknown Source)
java.io.ObjectOutputStream.writeSerialData(Unknown Source)
java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
java.io.ObjectOutputStream.writeObject0(Unknown Source)
java.io.ObjectOutputStream.defaultWriteFields(Unknown Source)
java.io.ObjectOutputStream.writeSerialData(Unknown Source)
java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source) ...etc

My Listener

private class AnamAjaxChanged extends AjaxBehaviorListenerImpl {
private static final long serialVersionUID = 7143366298515003573L;

@Override
public void processAjaxBehavior(AjaxBehaviorEvent event)
throws AbortProcessingException {
System.out.println("change");;
}
}

Please to help me why.

User avatar
andyba
Expert Member
Posts: 2473
Joined: 31 Mar 2011, 16:27
Location: Steinfeld, near Bremen/Osnabrück, DE
Contact:

14 Sep 2016, 12:19

First off please use code tags to format code in your post.

Never instantiate UIComponent instance yourself and don't have them as instance members, especially if the instance has to be serialized.
Do this instead.

Code: Select all

        FacesContext facesContext = FacesContext.getCurrentInstance();
        Application application = facesContext.getApplication();
        InputText anam = application.createComponent(InputText.COMPONENT_TYPE); 
If you don't know what the stack trace meant you may need to get a grounding in base Java EE or even Java SE as it showed that the InputText instance variable is not serializable and cannot be written out from a session.
PF 4.x (Elite versions), PF 5, Pf 5.1, PF 6.0
Glassfish 4.1, Mojarra 2.x, Java 8, Payara 4.1.1.
If you haven't read the forum rules read them now

tandraschko
PrimeFaces Core Developer
Posts: 3979
Joined: 03 Dec 2010, 14:11
Location: Bavaria, DE
Contact:

14 Sep 2016, 13:01

The exception is probably because you have a InputText as member variable in a Session/ViewScoped bean. This won't work.
Thomas Andraschko

PrimeFaces | PrimeFaces Extensions

Apache Member | OpenWebBeans, DeltaSpike, MyFaces, BVal, TomEE

Sponsor me: https://github.com/sponsors/tandraschko
Blog: http://tandraschko.blogspot.de/
Twitter: https://twitter.com/TAndraschko

User avatar
andyba
Expert Member
Posts: 2473
Joined: 31 Mar 2011, 16:27
Location: Steinfeld, near Bremen/Osnabrück, DE
Contact:

15 Sep 2016, 09:33

tandraschko wrote:The exception is because you have a InputText as member variable in a Session/ViewScoped bean. This won't work.
Corrected
PF 4.x (Elite versions), PF 5, Pf 5.1, PF 6.0
Glassfish 4.1, Mojarra 2.x, Java 8, Payara 4.1.1.
If you haven't read the forum rules read them now

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 61 guests