1

I'm creating an app using Spring 3 and JSF 2. I used custom ViewScope implementation from https://github.com/michail-nikolaev/primefaces-spring-scopes. I registered custom scope.

The problem is that when I try to access page where view scoped bean is used I get following exception:

INFO - ViewScope - Creating bean {editUser}
INFO - EditUser - EditUser() - class[com.myapp.beans.EditUser@f0ac4], rewId[null]
INFO - ViewScope - registerDestructionCallback for bean editUser
INFO - ViewScope - Session event bound sessionBindingListener
INFO - ViewScope - Bean created {com.myapp.beans.EditUser@f0ac4}
2013-03-18 00:30:30 com.sun.faces.lifecycle.ProcessValidationsPhase execute
WARNING: /editUser.xhtml @10,78 value="#{editUser.rewId}": The class '$Proxy115' does not have the property 'rewId'.
javax.el.PropertyNotFoundException: /editUser.xhtml @10,78 value="#{editUser.rewId}": The class '$Proxy115' does not have the property 'rewId'.

When bean is session scoped everything works fine.

I will be grateful for your help.

Michail Nikolaev
  • 3,733
  • 22
  • 18
Mungo
  • 61
  • 5

2 Answers2

0

Looks like your problem caused by JDK-based proxies generated to deal with @Transactional annotation.

JDK proxies are created only for interfaces implemented by the class (in your case Serializable). So, you proxy have only methods from Serializable interfaces (not at all).

To fix the problem you need to switch to another proxy mode (using cglib), for example using: @EnableTransactionManagement(proxyTargetClass = true). Also, add cglib:cglib-nodep:2.2 to dependencies of the project.

Michail Nikolaev
  • 3,733
  • 22
  • 18
  • I've got it set, and accessor methods are there, must be something else, another bean which is simplier works fine as view scoped – Mungo Mar 18 '13 at 09:49
  • 1
    Looks like it because some proxy crated over bean. Could you provide EditUser code? – Michail Nikolaev Mar 18 '13 at 11:41
  • ping-ping? (btw, I am author of code you using for ViewScope, so want to find fix too) – Michail Nikolaev Mar 18 '13 at 17:09
  • the class is very complicated so it's hard to paste it here, however I marked all properties as transient and the error still occurs, maybe there is a problem with some methods inside it or the types they return (but this seems to be ridiculous) – Mungo Mar 18 '13 at 20:39
  • I don't know how transient fields may change anything to be honest.. Anyway Proxy115 is name of proxy class created by Spring for some reason (maybe it is annotated by @Transactional or something about it...). And I think it is possible source of the problem. Please provide next things: Your class declaration (including annotations), rewId getter and setter code, xhtml header (with imports), xhtml code you use to access rewId. Thanks a lot. – Michail Nikolaev Mar 18 '13 at 20:58
  • Transient fields are not serialized and ViewScope requires bean to be serializable, using this my class seems to be very simple for serialization. – Mungo Mar 18 '13 at 21:07
  • I have methods annotated with @Transactional (that's normal I think). Class is annotated only as follow: &Named("editUserBean") &SpringViewScoped public class EditUserBean implements Serializable { Getter/setter for rewId are very simple, generated by IDE. – Mungo Mar 18 '13 at 21:18
  • looks like the Proxy exception arises when I'm adding "implements Serializable" to the bean – Mungo Mar 18 '13 at 21:51
  • O, I think I know the problem. It is because way your proxy-weaving implemented - if there is any interface implemented - Spring generates JDK-based proxy for it (check here - http://stackoverflow.com/questions/6460599/java-jsf-tomcat-spring-proxy-object-has-different-methods-than-original-object) – Michail Nikolaev Mar 18 '13 at 21:59
  • Thanks for your help, I found that the Transactional annotation was problematic, after removing it and managing transaction manually everything works fine – Mungo Mar 19 '13 at 00:17
  • unfortunately @EnableTransactionManagement(proxyTargetClass = true) is not working and I still get the same error when @Transactional is used, I'm maintaining transactions manually and it works fine, maybe somebody will find a better solution, I have no time for this now – Mungo Mar 25 '13 at 02:10
0

This is a ViewScope problem, it creates dummy versions, read over here: http://forum.primefaces.org/viewtopic.php?f=3&t=24082

mchamati
  • 109
  • 1
  • 7