Skip to content

Commit 933572a

Browse files
Add initial implementation of improved partial rendering controls
1 parent c52e897 commit 933572a

File tree

7 files changed

+29
-46
lines changed

7 files changed

+29
-46
lines changed

ng-appserver/src/main/java/ng/appserver/templating/NGComponent.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ public NGResponse generateResponse() {
277277
response.setHeader( "content-type", "text/html;charset=utf-8" ); // FIXME: This is most definitely not the place to set the encoding // Hugi 2023-03-12
278278
}
279279

280-
appendToResponse( response, context() );
280+
appendOrTraverse( response, context() );
281281

282282
// So, we've generated the page, and it's ready to return. Now we let the context tell us whether it should be stored in the page cache for future reference.
283283
// CHECKME: This *still* feels a little like the wrong place to stash the page in the cache. Not yet sure where it *should* be but my gut *still* has a feeling // Hugi 2024-09-28
@@ -300,17 +300,8 @@ public NGActionResults invokeAction( NGRequest request, NGContext context ) {
300300
}
301301

302302
@Override
303-
public void appendToResponse( NGResponse response, NGContext context ) {
304-
305-
final NGElement template = template();
306-
307-
// FIXME: I think this actually belongs in NGComponentReference // Hugi 2025-04-15
308-
if( context.shouldAppendToResponse() ) {
309-
template.appendToResponse( response, context );
310-
}
311-
else if( template instanceof NGStructuralElement se ) {
312-
se.appendStructureToResponse( response, context );
313-
}
303+
public void appendOrTraverse( NGResponse response, NGContext context ) {
304+
template().appendOrTraverse( response, context );
314305
}
315306

316307
/**

ng-appserver/src/main/java/ng/appserver/templating/NGElement.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import ng.appserver.NGContext;
77
import ng.appserver.NGRequest;
88
import ng.appserver.NGResponse;
9+
import ng.kvc.NGKeyValueCoding.UnknownKeyException;
10+
import ng.xperimental.NGErrorMessageElement;
911

1012
public interface NGElement extends WOElement {
1113

@@ -16,4 +18,18 @@ public default NGActionResults invokeAction( NGRequest request, NGContext contex
1618
}
1719

1820
public default void appendToResponse( NGResponse response, NGContext context ) {}
21+
22+
public default void appendOrTraverse( NGResponse response, NGContext context ) {
23+
if( context.shouldAppendToResponse() ) {
24+
try {
25+
appendToResponse( response, context );
26+
}
27+
catch( UnknownKeyException unknownKeyException ) {
28+
new NGErrorMessageElement( "VOFF! VOFF! Unknown key", getClass().getSimpleName(), unknownKeyException.getMessage() ).appendToResponse( response, context );
29+
}
30+
}
31+
else if( this instanceof NGStructuralElement se ) {
32+
se.appendStructureToResponse( response, context );
33+
}
34+
}
1935
}

ng-appserver/src/main/java/ng/appserver/templating/NGStructuralElement.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88
* See implementing elements and you'll know what that means.
99
*/
1010

11-
public interface NGStructuralElement {
11+
public interface NGStructuralElement extends NGElement {
12+
13+
@Override
14+
public default void appendToResponse( NGResponse response, NGContext context ) {
15+
appendStructureToResponse( response, context );
16+
}
1217

1318
public void appendStructureToResponse( NGResponse response, NGContext context );
1419
}

ng-appserver/src/main/java/ng/appserver/templating/elements/NGComponentContent.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,13 @@ public NGComponentContent( String name, Map<String, NGAssociation> associations,
1818
super( null, null, null );
1919
}
2020

21-
@Override
22-
public void appendToResponse( NGResponse response, NGContext context ) {
23-
appendStructureToResponse( response, context );
24-
}
25-
2621
@Override
2722
public void appendStructureToResponse( NGResponse response, NGContext context ) {
2823
final NGComponent component = context.component();
2924

3025
if( component.contentElement() != null ) {
3126
context.setComponent( component.parent() );
32-
component.contentElement().appendToResponse( response, context );
27+
component.contentElement().appendOrTraverse( response, context );
3328
context.setComponent( component );
3429
}
3530
}

ng-appserver/src/main/java/ng/appserver/templating/elements/NGComponentReference.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,10 @@ private void afterComponent( final NGContext context ) {
9797
context.setComponent( context.component().parent() );
9898
}
9999

100-
@Override
101-
public void appendToResponse( NGResponse response, NGContext context ) {
102-
appendStructureToResponse( response, context );
103-
}
104-
105100
@Override
106101
public void appendStructureToResponse( NGResponse response, NGContext context ) {
107102
beforeComponent( context );
108-
context.component().appendToResponse( response, context );
103+
context.component().appendOrTraverse( response, context );
109104
afterComponent( context );
110105
}
111106

ng-appserver/src/main/java/ng/appserver/templating/elements/NGDynamicGroup.java

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
import ng.appserver.templating.NGElement;
1212
import ng.appserver.templating.NGStructuralElement;
1313
import ng.appserver.templating.assications.NGAssociation;
14-
import ng.kvc.NGKeyValueCoding.UnknownKeyException;
15-
import ng.xperimental.NGErrorMessageElement;
1614

1715
/**
1816
* A common superclass for dynamic elements that have multiple children in our template element tree
@@ -40,11 +38,6 @@ public NGDynamicGroup( final List<NGElement> children ) {
4038
_children = children;
4139
}
4240

43-
@Override
44-
public void appendToResponse( NGResponse response, NGContext context ) {
45-
appendChildrenToResponse( response, context );
46-
}
47-
4841
@Override
4942
public void appendStructureToResponse( NGResponse response, NGContext context ) {
5043
appendChildrenToResponse( response, context );
@@ -55,19 +48,7 @@ protected void appendChildrenToResponse( NGResponse response, NGContext context
5548
context.elementID().addBranch();
5649

5750
for( final NGElement child : children() ) {
58-
if( context.shouldAppendToResponse() ) {
59-
// FIXME: This try/catch clause is experimental, let's see how this works out and work from there // Hugi 2024-11-19
60-
try {
61-
child.appendToResponse( response, context );
62-
}
63-
catch( UnknownKeyException unknownKeyException ) {
64-
new NGErrorMessageElement( "VOFF! VOFF! Unknown key", child.getClass().getSimpleName(), unknownKeyException.getMessage() ).appendToResponse( response, context );
65-
}
66-
}
67-
else if( child instanceof NGStructuralElement structuralChild ) {
68-
structuralChild.appendStructureToResponse( response, context );
69-
}
70-
51+
child.appendOrTraverse( response, context );
7152
context.elementID().increment();
7253
}
7354

ng-appserver/src/main/java/ng/appserver/templating/elements/NGSwitchComponent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public void appendStructureToResponse( NGResponse response, NGContext context )
143143

144144
final NGElement componentElement = realComponentWithName( name, id );
145145

146-
componentElement.appendToResponse( response, context );
146+
componentElement.appendOrTraverse( response, context );
147147

148148
context.elementID().removeBranch();
149149
}

0 commit comments

Comments
 (0)