|
Fornax-Platform
Forum |
|
View:
New views
5 Messages
—
Rating Filter:
Alert me
|
|
|
[Sculptor] Possible Inheritance bug in Web Application and problems with WebSpecialCases.xptDear all,
I'm a Sculptor and OAW newbie, but I'm impressed with the platform possibilites. I'm using Sculptor 1.6.0 I think I have found a bug on the code generator in the Web CRUD project of Sculptor, related to inheritance and Many-to-Many relations. If I make Many-To-Many relationships between an Entity and its parent, or with the Parent with himself, web application classes does not compile because of a casting error. I have tried to solve it, using WebSpecialCases.xpt, but I receive some strange (to me) errors. At first I will show you an example of the bug. Later I will explain how I tried to solve it, and where I'm stuck. Module inheritanceSample { abstract Entity Parent { scaffold String name key String description - Set<@Parent> buyer <-> seller - Set<@Parent> seller <-> buyer - Set<@SonOne> sonone <-> dad } Entity SonOne extends @Parent { scaffold String data1 - Set<@Parent> dad <-> sonone } } When I generate the code, I works. However, when I run "mvn -Dmaven.test.skip=true clean install" there are compilation errors: /proyectos/sculptoride/workspaces/remato/remato-web/src/generated/java/es/aww/remato/inheritanceSample/web/UpdateSonOneAction.java:[98,33] incompatible types found : java.util.List<es.aww.remato.inheritanceSample.domain.SonTwo> required: java.util.Collection<es.aww.remato.inheritanceSample.domain.Parent> /proyectos/sculptoride/workspaces/remato/remato-web/src/generated/java/es/aww/remato/inheritanceSample/web/CreateSonOneAction.java:[73,35] incompatible types found : java.util.List<es.aww.remato.inheritanceSample.domain.SonThree> required: java.util.Collection<es.aww.remato.inheritanceSample.domain.Parent> The problem is with the code at the Update<Entity>Action and Create<Entity>Action classes. This is a sample of the broken code (from UpdateSonOneAction.java): protected List<SelectItem> getSonOneItems() { Collection<Parent> buyer = sonOneService.findAll(ServiceContextStore.get()); List<SelectItem> items = new ArrayList<SelectItem>(); for (Parent parentItem : buyer) { if (parentItem instanceof SonOne) { String label = String.valueOf(parentItem.getName()); items.add(new SelectItem(parentItem.getId(), label)); } } return items; } The problem is with the generic "Collection<Parent> buyer". The "sonOneService.findAll" method returns "List<SonOne>" which can not be directly cast to "Collection<Parent>". Fortunately, using wildcards with generics (See: http://today.java.net/pub/a/today/2004/01/15/wildcards.html?page=2) the offending line can be fixed: Collection<? extends Parent> buyer = sonOneService.findAll(ServiceContextStore.get()); As changing the code manually is boring, I tried to fix the generator. I downloaded the Sculptor 1.6.0 branch from the repository and I searched for the template. It is JSFCrudGuiJava.xpt at the templates.web package. The definition in the file is "getReferenceItems". So I created a rule at WebSpecialCases.xpt to overwrite that definition. Note that it is a very naive solution, as I don't know the posible impact on other parts: «IMPORT sculptormetamodel» «IMPORT sculptorguimetamodel» «EXTENSION extensions::helper» «EXTENSION extensions::dbhelper» «EXTENSION extensions::properties» «EXTENSION extensions::guihelper» «AROUND *getReferenceItems FOR ReferenceViewProperty» «LET getRelatedAddTask() AS addTask» protected java.util.List<javax.faces.model.SelectItem> get«target.name.toFirstUpper()»Items() { java.util.Collection<? extends «reference.to.getDomainPackage()».«reference.to.name»> «name» = «addTask.getPrimaryService().name.toFirstLower()».«addTask.getPrimaryServiceOperation().name»(«IF isServiceContextToBeGenerated()»«serviceContextStoreClass()».get()«ENDIF»); java.util.List<javax.faces.model.SelectItem> items = new java.util.ArrayList<javax.faces.model.SelectItem>(); for («reference.to.getDomainPackage()».«reference.to.name» «reference.to.name.toFirstLower()»Item : «name») { if («reference.to.name.toFirstLower()»Item instanceof «target.getDomainPackage()».«target.name») { String label = «EXPAND itemLabel(reference.to.name.toFirstLower()+"Item") FOR reference.to -»; items.add(new javax.faces.model.SelectItem(«reference.to.name.toFirstLower()»Item.getId(),label)); } } return items; } «ENDLET» «ENDAROUND» However, when I tried that, I obtained a null pointer exception (See the attached stacktrace for more detail). I guess that the problem is that I can not reference values from the original template. Could you please explain me how can I do it? Also, could you please also confirm if the inheritance problem is a bug? I have found similar problems in JIRA, but i don't know if this is related to them. Thanks in advance for your responses, best regards,sculptor-inheritance-stacktrace.txt |
|
|
Re: [Sculptor] Possible Inheritance bug in Web Application and problems with WebSpecialCases.xptHi,
I made a quick test and I can confirm that this is a bug. Created a jira task for it: http://fornax.itemis.de/jira/browse/CSC-395 I also got the null pointer in WebSpecialCase.xpt, but I need to look into it further. .../Andreas On Tue, Sep 1, 2009 at 12:40 PM, apalazon <apalazon@...> wrote:
------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ Fornax-developer mailing list Fornax-developer@... https://lists.sourceforge.net/lists/listinfo/fornax-developer |
|
|
Re: [Sculptor] Possible Inheritance bug in Web Application and problems with WebSpecialCases.xptThank you for finding and reporting this bug.
The problem with WebSpecialCases is due to that you haven't used fully qualified DEFINE names. Both for the AROUND and EXPAND. Try this instead: «REM»Temporary fix of CSC-395 «ENDREM» «AROUND templates::web::JSFCrudGuiJava::getReferenceItems FOR ReferenceViewProperty» «LET getRelatedAddTask() AS addTask» protected java.util.List<javax.faces.model.SelectItem> get«target.name.toFirstUpper()»Items() { java.util.Collection<? extends «reference.to.getDomainPackage()».«reference.to.name»> «name» = «addTask.getPrimaryService().name.toFirstLower()».«addTask.getPrimaryServiceOperation().name»(«IF isServiceContextToBeGenerated()»«serviceContextStoreClass()».get()«ENDIF»); java.util.List<javax.faces.model.SelectItem> items = new java.util.ArrayList<javax.faces.model.SelectItem>(); for («reference.to.getDomainPackage()».«reference.to.name» «reference.to.name.toFirstLower()»Item : «name») { if («reference.to.name.toFirstLower()»Item instanceof «target.getDomainPackage()».«target.name») { String label = «EXPAND templates::web::JSFCrudGuiJava::itemLabel(reference.to.name.toFirstLower()+"Item") FOR reference.to -»; items.add(new javax.faces.model.SelectItem(«reference.to.name.toFirstLower()»Item.getId(),label)); } } return items; } «ENDLET» «ENDAROUND» /Patrik |
|
|
Re: [Sculptor] Possible Inheritance bug in Web Application and problems with WebSpecialCases.xptThank you very much for the help :)
I confirm that the fix is working. Regards, Angel |
|
|
Re: [Sculptor] Possible Inheritance bug in Web Application and problems with WebSpecialCases.xptFixed in trunk.
Again, thx for finding it and providing a solution. .../Andreas
|
| Free embeddable forum powered by Nabble | Forum Help |