File tree Expand file tree Collapse file tree 3 files changed +42
-2
lines changed
srv/src/main/java/my/bookshop/handlers Expand file tree Collapse file tree 3 files changed +42
-2
lines changed Original file line number Diff line number Diff line change @@ -39,10 +39,11 @@ annotate AdminService.Books with @(UI : {
3939 },
4040 {
4141 // TODO: should work dynamically
42- @ UI . Hidden ,
4342 $Type : ' UI.ReferenceFacet ' ,
4443 Label : ' {i18n>Contents} ' ,
45- Target : ' contents/@UI.PresentationVariant '
44+ Target : ' contents/@UI.PresentationVariant ' ,
45+ ![@UI.Hidden] : contentsHidden
46+
4647 }
4748 ],
4849 FieldGroup # General : {Data : [
Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ entity Books : cuid, managed {
2323 on reviews .book = $self ;
2424 isReviewable : TechnicalBooleanFlag not null default true ;
2525 contents : Composition of many Contents on contents .book = $self @ odata . contained : false ;
26+ virtual contentsHidden : Boolean default false ;
2627}
2728
2829entity Authors : cuid , managed {
Original file line number Diff line number Diff line change 1+ package my .bookshop .handlers ;
2+
3+
4+ import java .util .List ;
5+ import java .util .Map ;
6+
7+ import org .springframework .context .annotation .Profile ;
8+ import org .springframework .stereotype .Component ;
9+
10+ import com .sap .cds .services .EventContext ;
11+ import com .sap .cds .services .handler .EventHandler ;
12+ import com .sap .cds .services .handler .annotations .After ;
13+ import com .sap .cds .services .handler .annotations .On ;
14+ import com .sap .cds .services .handler .annotations .ServiceName ;
15+
16+ import cds .gen .adminservice .AdminService_ ;
17+ import cds .gen .adminservice .Books_ ;
18+
19+ @ Component
20+ @ ServiceName (AdminService_ .CDS_NAME )
21+ /**
22+ * Example of a custom handler for nextSiblingAction
23+ */
24+ @ Profile ("hybrid" )
25+ public class SetHiddenHandler implements EventHandler {
26+
27+ @ After (entity = Books_ .CDS_NAME )
28+ void removeUIHidden (EventContext context ){
29+ Object result = context .get ("result" );
30+ if (result instanceof Map row ) {
31+ row .put ("contentsHidden" , true );
32+ } else if (result instanceof List rows && rows .size () == 1 ) {
33+ ((Map )rows .get (0 )).put ("contentsHidden" , true );
34+ }
35+ }
36+ }
37+
38+
You can’t perform that action at this time.
0 commit comments