Re: Class cast exception in ASTChain, Bug OGNL-11
Kevin Menard wrote: On 8/15/07 10:50 AM, in article [EMAIL PROTECTED], Andrus Adamchik [EMAIL PROTECTED] wrote: Thinking about it some more This is not the end of the world for our application. We can either skip the upgrade or indeed force an interface on the objects involved, or avoid multi-step property traversal by moving it to Java class. But at a higher level it seems like the expression compilation algorithm is sacrificing correctness for performance. An implicit requirement on the @For to have homogeneous objects in the loop is confusing and non-obvious. A failover strategy hidden from the users would be great. How hard it would be to say decorate an expression compiled within a For loop in a try/catch that would switch to a generic algorithm on the first ClassCastException? This is an interesting idea that I think would work well. We ran into problems ourselves. OGNL would dump out a ton of output to the console, but then fallback to an expression that would work. I think it would be good to allow users to turn off expression compilation, i.e. revert to the old way that OGNL worked. Is this possible? It would allow us to continue with 4.1, without having all our expressions break on us. For me it was only 2 parts of the app that needed fixing, but I can imagine loads of people relying on the reflective nature of OGNL when constructing their pages... Damien -- Damien Uern Online Applications Developer Synect Online Solutions - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: [T4]Handling Nulls in OGNL expressions
(Sorry for top posting, but everybody else seems to do it on this list) Anyway, the null pointer exception in a long property access chain was one of the issues I had with OGNL a while ago and have basically just learned to live with it. It is highly annoying. One of the things I preferred with Apple's WebObjects (which used NSKeyValueCoding for property access expressions) was that if any object in the chain was null, it just returned null. So if you have the expression: a.b.c.d where c is null, the entire expression would evaluate to null. Having to implement some sort of hivemind null pointer handling service just to get this sort of behaviour just screams over designed to me. (Not that I'm knocking OGNL/Tapestry in general, I still prefer using it over WebObjects for a variety of reasons). Damien Martino Piccinato wrote: In my opinion is all that you want is not having NullPointerException it would be better to implement MethodAccessor and/or PropertyAccessor, that would return null if the target object is null, then you could simply check expressions returning nulls and returning your message, or maybe have a special component doing this. Tapestry has configuration point also for default Method/Property accessors. On 7/26/07, Marcos Chicote [EMAIL PROTECTED] wrote: Responding to my own mail... I found an old Andreas mail to the lis ( http://mail-archives.apache.org/mod_mbox/tapestry-dev/200606.mbox/[EMAIL PROTECTED] ) that explained how to do this. I'll sumarize my ideas so that I can check if they are correct and maybe it will result usefull to the next person that wants to do this. The idea is to define a class that implements NullHandler ( http://www.ognl.org/2.6.9/Documentation/javadoc/ognl/NullHandler.html). That class job is to handle null's when an specific class access to property returns null. To make tapestry use your NullHandler you define something like this in your hivemind configuration file: contribution configuration-id=tapestry.ognl.NullHandlers null-handler class=classThatImplementsNullHandler object=instance:classToCaptureNulls/ /contribution where classToCaptureNulls represents the name of the class who's nulls you want to handle and classThatImplementsNullHandler represents the class that knows how to deal with nulls in classToCaptureNulls. Now that I have this working I would like to know how to use it :D I mean, if I have a long ognl expression like obj1.obj2.obj3.obj4 and access to obj2 in obj1 return null, I would like to show an obj2 not available message on screen. Can anyone help me on how to use this service? Thanks! Marcos On 7/26/07, Marcos Chicote [EMAIL PROTECTED] wrote: Hi Andreas! When I emailed to Tapestry's list I was prototyping a project. Now I'm actually developing it and I'm very interested in getting this service working. Did you find some code where you used this feature? Thanks! Marcos On 6/29/07, Marcos Chicote [EMAIL PROTECTED] wrote: Thanks Andreas. I have to do some more reading then. I you have some code that I can use as an example I would be really grateful. Thanks! Marcos On 6/29/07, Andreas Andreou [EMAIL PROTECTED] wrote: O/H Marcos Chicote έγραψε: Thanks Andreas. Before mailing to this list, I tried looking at the ognl documentation and I found the NullHandler interface but I wasn't sure how it worked with Tapestry or if it was possible to do it another way without altering the BOs. Correct me if I'm wrong but what I understand is that Tapestry already implements a Hivemind service that does the null handling. All I have to do is make my BOs implement NullHandler interface. Am I right? Hmmm, not really... Tapestry simply provides that point so that your have a global way of registring handlers - so, making your BOs implement NullHandler is not enough Also, i'm not sure if that's the correct approach - seems it polutes your BOs I think I'd create a service that would be able to null-handle your specific objects, and esp. of all those objects have a common superclass, i'd be able to register them all at once. I'll dig in for some code - it's been a while since i last used this Thanks a lot! Marcos On 6/29/07, Andreas Andreou [EMAIL PROTECTED] wrote: http://tapestry.apache.org/tapestry4.1/tapestry-framework/hivedoc/config/tapestry.ognl.NullHandlers.html the way it works, is that you associate implementations of http://www.ognl.org/2.6.9/Documentation/javadoc/ognl/NullHandler.html with class types whose methods (or properties) may return null O/H Marcos Chicote έγραψε: Hi! I have a Table component (actually I have TableRows, TableView, and all those other components that form a Table) and one of the columns in TableView is declared like this: columnName: object1.object2.property. As you can see this can throw NullPointerException if either object1 or object2 are null. To solve this problem, I have to alternatives: a) Use a Block
Re: user access control
Chris Lewis wrote: Hello all, I am seeking information/code samples on how to implement user access control in Tapestry (4.1.2). Specifically, restricting pages to authenticated users. I assume that all restricted pages would have to make a call to an authentication system, checking if the user is logged in and if they have access to the page. If a user tries to access a page they are not authorized to view, then something should happen. This something may just be a message or an error page - the important part is how to implement this across pages or a group of pages. Thanks for your input! chris Piece of cake, you can create a page that handles authentication checking as follows: public abstract class AbstractSecurePage extends AbstractPage implements PageValidateListener { InjectState(visit) public abstract Session getSession(); public void pageValidate(PageEvent event) { //check user permissions here e.g.: if (!getSession().isUserLoggedIn()) { throw new PageRedirectException(LoginPage); } } } Hope that helps :D Damien -- Damien Uern Online Applications Developer Synect Online Solutions - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Class cast exception in ASTChain, Bug OGNL-11
Hello, I recently upgraded to OGNL 2.7, Tapestry 4.1.2 and am experiencing the same issue described here http://jira.opensymphony.com/browse/OGNL-11. The original poster didn't seem to provide much information, so I have added a comment to that bug describing the issue I am having. I'm not sure if I need to open a new bug in order for somebody to look at it. I will reproduce my comment here for convenience, any help/workarounds would be most appreciated: I have just updated from Tapestry 4.0 to 4.1.2 with OGNL 2.7 and I am having this same class cast exception on an ASTChain generated class, stack trace is here: Caused by: java.lang.ClassCastException: com.jigsawpublications.common.tapestry.menu.ActionLinkNode at $ASTChain_113aed5c33f.get($ASTChain_113aed5c33f.java) at org.apache.tapestry.services.impl.ExpressionEvaluatorImpl.read(ExpressionEvaluatorImpl.java:142) What we have in the component template looks like this: span jwcid=[EMAIL PROTECTED] li a jwcid=@DirectLink listener=listener:callParentAction parameters=ognl:getNodeIter().getAction() href=# title=ognl:nodeIter.title span jwcid=@Insert value=ognl:nodeIter.title / /a /li /span The nodeIter property on the component class is declared as follows: public IMenuNode getNodeIter() { } So what we have here is a list of objects all implementing this interface IMenuNode, and getNodeIter() returns the current iteration as set by the tapestry @For component. The class cast exception was on an ActionLinkNode which implements that interface. Other classes are PageLinkNode, RootNode and MenuNode. The *only* one that causes a problem seems to be the above @Block component, as another block: span jwcid=[EMAIL PROTECTED] li a jwcid=@PageLink href=# title=ognl:nodeIter.title page=ognl:nodeIter.page span jwcid=@Insert value=ognl:nodeIter.title / /a /li /span renders fine without any issue (these other blocks occur earlier in the page than the ActionLinkBlock). If I change the actionLink block to be the following (i.e. change the offending ognl expressions): span jwcid=[EMAIL PROTECTED] li a jwcid=@DirectLink listener=listener:callParentAction parameters=ognl:'action' href=# title=ognl:'title' span jwcid=@Insert value=ognl:'title' / /a /li /span Then I do not get an exception during the page render. This worked fine with the previous version of ognl we were using (2.6.7). Please let me know if you require more information. Regards, Damien Uern -- Damien Uern Online Applications Developer Synect Online Solutions http://www.synect.com - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]