0

I'm trying to create a scalable JSF application. I would like to save view states on client side but I have troubles with ViewScoped ManagedBean with CDI Injected attributes.

SomeService.java :

@Singleton
public class SomeService {
    // ...
}

SomeBean.java

@ManagedBean
@ViewScoped
public class SomeBean implements Serializable {

            @Inject
            private SomeService someService;
}

Unfortunately glassfish fails to serialize someService which I don't want to be serializabled but re-injected.

I tried to make it transient which ends up to a NullPointerException when accessing someService after de-serialization.

What shall I do?

I'm aware that I could use CDI ViewScoped with Seam Faces or CODI but I want to minimize at most dependencies.

I could also wait for JEE7 which will provide @ViewScoped for CDI but we won't be using JEE7 before months.

UPDATE :
I just wanted to add that I was using embedded EJB bundled in a jar which is itself linked to my war. NotSerializableException's stack trace has the following message : com.company.core.service.__EJB31_Generated__SomeService__Intf____Bean__

2
  • Why are you injecting an EJB by CDI's @Inject instead of EJB's @EJB?
    – BalusC
    Mar 20, 2013 at 15:24
  • I don't really get the difference, according to link it's better to use @EJB in some cases. I tried to change from @Inject to @EJB without any improvement. Do you have any recommendation? Mar 20, 2013 at 18:38

1 Answer 1

0

I don't like to self respond to my own questions but after some more research I found that it was a bug in Mojarra 2.1.6 (I'm using Glassfish 3.1.2.2) which is now solved in Mojarra 2.1.20.

To update Mojarra you just need to download a fresher version (eg: https://maven.java.net/content/repositories/releases/org/glassfish/javax.faces/2.1.20/javax.faces-2.1.20.jar) and place it in the $GLASSFISH/modules directory as javax.faces.jar.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.