2015-10-05 54 views
0

我正在研究Jspresso框架(使用Swing啓動項目)。我已經在組件之間建立了N-N雙向關係,但沒有出現與這些關係相對應的字段。 例如,我有項目和學生之間的關係(一個學生可以有很多項目,一個項目可以有很多學生)。當我添加一個項目並在其詳細視圖中打開它時,我可以創建一個新學生並將其添加到項目中,但是我無法將現有學生添加到項目中,也不會在搜索視圖中根據學生搜索項目。 有沒有辦法顯示這個?N-N雙向關係沒有在用戶界面上使用Jspresso處理

這裏是我的view.groovy

// Implement your views here using the SJS DSL. 

form('Project.pane', 
    parent:'decoratedView', 
    labelsPosition:'ASIDE', 
    columnCount:2, 
    fields:  ['name','students','technologies','usesTrainers','technicalTrainers']){ 
    actionMap{ 
      actionList('FILE'){ 
       action(ref:'saveModuleObjectFrontAction') 
       action(ref:'reloadModuleObjectFrontAction') 
      } 
    } 
} 

table'Project-students.table', 
    parent:'decoratedView', 
    actionMap:'masterDetailActionMap' 

split_vertical'Project.proj.view', 
    model:'Project', 
    top:'Project.pane', 
    bottom:'Project-students.table' 



form('Student.pane', 
    parent:'decoratedView', 
    labelsPosition:'ASIDE', 
    columnCount:2){ 
     actionMap{ 
       actionList('FILE'){ 
       action(ref:'saveModuleObjectFrontAction') 
       action(ref:'reloadModuleObjectFrontAction') 
      } 
    } 
} 

table'Student-technologies.table', 
    parent:'decoratedView', 
    actionMap:'masterDetailActionMap' 

split_vertical'Student.proj.view', 
    model:'Student', 
    top:'Student.pane', 
    bottom:'Student-technologies.table' 

form('Trainer.pane', 
    parent:'decoratedView', 
    labelsPosition:'ASIDE', 
    columnCount:5) 

form('Technology.pane', 
    parent:'decoratedView', 
    labelsPosition:'ASIDE', 
    columnCount:5) 

這裏是我的model.groovy

// Implement your domain here using the SJS DSL. 

Interface('Traceable', 
interceptors: 'TraceableLifecycleInterceptor', 
uncloned: ['createTimestamp', 
      'lastUpdateTimestamp','lastUpdatedBy','createdBy']) { 
    string_64 'createdBy',readOnly:true 
    date_time 'createTimestamp', timeZoneAware: true, readOnly: true 
    string_64 'lastUpdatedBy', readOnly:true 
    date_time 'lastUpdateTimestamp', timeZoneAware: true, readOnly: true 
} 

Entity ('Project', extend:'Traceable',toString:'name', 
icon:'project.png', 
rendered: ['name','lastUpdateTimestamp','lastUpdatedBy','createTimestamp','createdBy'], 
queryable: ['name']){ 
string_64 'name' 
set 'technologies', composition:true, ref:'Technology' 
set 'technicalTrainers', composition:true, ref:'Trainer' 
set 'usesTrainers', composition:true, ref:'Trainer' 
set 'students', composition:true, ref:'Student' 

} 

Entity ('Technology', extend:'Traceable',toString:'name', 
icon:'technology.png', 
rendered: ['name','lastUpdateTimestamp','lastUpdatedBy','createTimestamp','createdBy'], 
queryable: ['name']){ 
string_64 'name' 
set 'projects', ref:'Project', reverse:'Project-technologies' 
set 'studentsAbleToUseIt', ref:'Technology', reverse:'Student-technologies' 
set 'trainersAbleToTeachIt', ref:'Technology', reverse:'Trainer-technologies' 
} 

Interface ('Person', extend:'Traceable'){ 
string_64 'lastname' 
string_64 'firstname' 
date_time 'createTimestamp', timeZoneAware: true, readOnly: true 
date_time 'lastUpdateTimestamp', timeZoneAware: true, readOnly: true 
} 

Entity ('Trainer', 
    extend: 'Person', 
    toString:'firstname', 
    icon:'trainer.png', 
    rendered: ['firstname','lastname','lastUpdateTimestamp','lastUpdatedBy','createTimestamp','createdBy'], 
    queryable: ['firstname','lastname']){ 
set 'projectsAsTechnicalTrainer', ref:'Project', reverse:'Project-technicalTrainers' 
set 'projectsAsUsesTrainer', ref:'Project', reverse:'Project-usesTrainers' 
set 'technologies', composition:true, ref:'Technology' 
date_time 'createTimestamp', timeZoneAware: true, readOnly: true 
date_time 'lastUpdateTimestamp', timeZoneAware: true, readOnly: true 
} 

Entity ('Student', 
    extend: 'Person', 
    toString:'firstname', 
    icon:'student.png', 
    rendered: ['firstname','lastname','lastUpdateTimestamp','lastUpdatedBy','createTimestamp','createdBy'], 
    queryable: ['firstname','lastname']){ 
set 'technologies', composition:true, ref:'Technology' 
set 'projects', ref:'Project', reverse:'Project-students' 
date_time 'createTimestamp', timeZoneAware: true, readOnly: true 
date_time 'lastUpdateTimestamp', timeZoneAware: true, readOnly: true 
} 

回答

1

你絕對可以實現這兩個目標很容易。

1/A N-N關係可以簡單地認爲是兩個1-N的關係。因此,您可以在面向學生的視圖上使用Project面向視圖上的Project-students關係和Student-projects關係。您可以使用2個不同的過濾器模塊(Project上的一個和Student上的一個)或者補充Project.proj.view以添加第二級詳細信息,方法是添加一個額外表格,該表格將在第一個表格詳細信息中顯示所選學生的Student-projects

喜歡的東西:

split_vertical ('Project.proj.view', 
    model:'Project', 
    top:'Project.pane') { 
    bottom { 
    split_horizontal(
     left: 'Project-students.table', 
     right: 'Student-projects.table', 
     cascadingModels: true 
    ) 
    } 
} 

2 /關於選擇和添加現有ProjectStudent到相應的集合,你可以使用自定義LOV行動在1st chapter of the Jspresso-CE reference documentation解釋的能力。

是這樣的:

table('Project-students.table') { 
    actionMap { 
    actionList('EDIT'){ 
     action(parent:'lovAction', 
     custom:[ 
      autoquery:false, 
      entityDescriptor_ref:'Student', 
      okAction_ref:'addAnyToMasterFrontAction' 
     ] 
    ) 
     action(ref:'removeAnyCollectionFromMasterFrontAction') 
    } 
    } 
} 

3 /至於過濾由Student(或相反)Project,Jspresso支持定義集合屬性作爲過濾器的性能。在這種情況下,過濾器視圖將爲學生安裝LOV以過濾項目。

如果您想在每個項目過濾器視圖中默認使用它,請直接在模型上聲明它。

喜歡的東西:

Entity ('Project' 
     ... 
     queryable : ['name', 'students'] 
     ...){ 
    ... 
}