Re: Wicket Components as Class Members
Thank you everyone for your replies. -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/Wicket-Components-as-Class-Members-tp4662235p4662345.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Wicket Components as Class Members
Since the original question was about storing component references as class members, let me answers how we handle that in our shop. Wicket serializes stateful pages anyway, so any component references within the page don't hurt (at all). It's just a 4-byte reference to an object wicket already references (through the component hierarchy). As for stateless pages it matters even less, as they are not serialized at all (so only a 4-byte reference per component uses some memory). I think the most important rules regarding serialization are: - don't reference other pages or components within those pages - don't reference large object (use loadable detachable models instead) Like an earlier reponse to this question said: referencing components by their (string) id within the page is quite ugly. not to mention it breaks quite easily. We use component references extensively (e.g. when the visibility of one component depends on the state others), and have never encountered any problems. Met vriendelijke groet, Kind regards, Bas Gooren schreef meduolis op 8-11-2013 17:20: The only thing I googled related to final and wicket is this: 7. Java nuances — There are two Java nuances that catch many Wicket newcomers off-guard. 1. The first is serialization. Wicket uses Java serialization to store the state of your component hierarchy (the page and all its components and their components and so-on) in memory or on disk between page requests. This means you need to be careful because things can get serialized by accident. The most common cause of this is declaring a variable final outside of an anonymous inner class and then using it inside that anonymous inner class. Doing this causes the compiler to add a member variable to the anonymous inner class. If that final variable is a large collection or a service from your middle-tier, this can cause a gigantic explosion of memory usage and can be hard to track down. In short: be very cautious with what you reference within anonymous inner classes and use member variables in your classes sparingly. source: http://wickettraining.com/ten-things-every-wicket-programmer-should-know.html -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/Wicket-Components-as-Class-Members-tp4662235p4662237.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Wicket Components as Class Members
Dumb question everyone, I heard somewhere that it is bad to declare variables as final in Wicket because they are treated as class members, and Wicket serializes the page that would increase your session size. Because of this I have not declared any components I add to my page as final (or created class member variables for them), and if I need to access them from an anonymous class I use the page.get(compId) method. This has made my code very cumbersome and hard to read. I got to thinking, since Wicket serializes all the components anyways, what would it hurt to make a component final or a class member when declaring it? It would sure make it easier to access later on. I really feel like an idiot asking this question, just concerned about session size. -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/Wicket-Components-as-Class-Members-tp4662235.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Wicket Components as Class Members
The only thing I googled related to final and wicket is this: 7. Java nuances — There are two Java nuances that catch many Wicket newcomers off-guard. 1. The first is serialization. Wicket uses Java serialization to store the state of your component hierarchy (the page and all its components and their components and so-on) in memory or on disk between page requests. This means you need to be careful because things can get serialized by accident. The most common cause of this is declaring a variable final outside of an anonymous inner class and then using it inside that anonymous inner class. Doing this causes the compiler to add a member variable to the anonymous inner class. If that final variable is a large collection or a service from your middle-tier, this can cause a gigantic explosion of memory usage and can be hard to track down. In short: be very cautious with what you reference within anonymous inner classes and use member variables in your classes sparingly. source: http://wickettraining.com/ten-things-every-wicket-programmer-should-know.html -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/Wicket-Components-as-Class-Members-tp4662235p4662237.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Wicket Components as Class Members
Hi, since Wicket serializes all the components anyways, what would it hurt to make a component final or a class member when declaring it? your reasoning is sound, it does not hurt (besides 4 additional bytes for the object reference). if I need to access them from an anonymous class I use the page.get(compId) method. This has made my code very cumbersome and hard to read. I've seen this in some projects, personally I can't stand this usage. Regards Sven On 11/08/2013 05:08 PM, mashleyttu wrote: Dumb question everyone, I heard somewhere that it is bad to declare variables as final in Wicket because they are treated as class members, and Wicket serializes the page that would increase your session size. Because of this I have not declared any components I add to my page as final (or created class member variables for them), and if I need to access them from an anonymous class I use the page.get(compId) method. This has made my code very cumbersome and hard to read. I got to thinking, since Wicket serializes all the components anyways, what would it hurt to make a component final or a class member when declaring it? It would sure make it easier to access later on. I really feel like an idiot asking this question, just concerned about session size. -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/Wicket-Components-as-Class-Members-tp4662235.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org