Skip to content

Commit 0e49dfc

Browse files
committed
Adapted Documentation
1 parent 6e2c490 commit 0e49dfc

File tree

4 files changed

+79
-78
lines changed

4 files changed

+79
-78
lines changed

modules/cui-jsf-api/doc/components-decorator.adoc

Lines changed: 65 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -73,115 +73,91 @@ Decorators are typically placed inside the component they should decorate:
7373

7474
[source,xml]
7575
----
76-
<h:panelGroup>
77-
<cui:styleClassDecorator styleClass="panel panel-default"/>
78-
Panel content here...
79-
</h:panelGroup>
76+
<h:commandButton value="Click Me">
77+
<cui:tooltip title="Click this button to submit the form" placement="top"/>
78+
</h:commandButton>
8079
----
8180

82-
When the view is rendered, the decorator modifies its parent component (in this case, adding CSS classes to the `panelGroup`).
81+
When the view is rendered, the decorator modifies its parent component (in this case, adding tooltip functionality to the `commandButton`).
8382

8483
== Common Decorator Types
8584

86-
=== Style Class Decorators
85+
=== Tooltip Decorators
8786

88-
Add CSS classes to the parent component:
87+
Add tooltip functionality to the parent component:
8988

9089
[source,java]
9190
----
92-
public class StyleClassDecorator extends AbstractParentDecorator {
91+
public class TooltipComponent extends AbstractParentDecorator {
9392
94-
private String styleClass;
93+
private String placement;
94+
private String trigger;
95+
private Integer delay;
96+
private String content;
9597
9698
@Override
97-
protected void decorate(UIComponent parent) {
98-
ComponentModifier modifier = ComponentModifierFactory.findFittingWrapper(parent);
99-
if (null != modifier) {
100-
modifier.addStyleClass(parent, styleClass);
99+
public void decorate(final ComponentModifier parent) {
100+
parent.addPassThrough("data-placement", getPlacement())
101+
.addPassThrough("data-toggle", "tooltip")
102+
.addPassThrough("data-trigger", getTrigger())
103+
.addPassThrough("data-delay", getDelay());
104+
105+
if (null != content) {
106+
if (parent.isSupportsTitle()) {
107+
parent.setTitle(content);
108+
} else {
109+
parent.addPassThrough("title", content);
110+
}
101111
}
102112
}
103113
104114
// Getters and setters...
105115
}
106116
----
107117

108-
=== Attribute Decorators
118+
=== Modal Control Decorators
109119

110-
Set attributes on the parent component:
120+
Add modal dialog control functionality to the parent component:
111121

112122
[source,java]
113123
----
114-
public class AttributeDecorator extends AbstractParentDecorator {
124+
public class ModalControl extends AbstractParentDecorator {
115125
116-
private String name;
117-
private Object value;
126+
private String forId;
127+
private String event;
128+
private String action;
118129
119130
@Override
120-
protected void decorate(UIComponent parent) {
121-
parent.getAttributes().put(name, value);
131+
public void decorate(final ComponentModifier parent) {
132+
parent.addPassThrough("data-modal-for", getFor())
133+
.addPassThrough("data-modal-action", getAction())
134+
.addPassThrough("data-modal-event", getEvent());
122135
}
123136
124137
// Getters and setters...
125138
}
126139
----
127140

128-
=== Behavior Decorators
141+
=== Block Element Decorators
129142

130-
Add behaviors to the parent component:
143+
Add block element functionality to the parent component:
131144

132145
[source,java]
133146
----
134-
public class AjaxDecorator extends AbstractParentDecorator {
135-
136-
private String event;
137-
private String execute;
138-
private String render;
147+
public class BlockElementDecorator extends AbstractParentDecorator {
139148
140149
@Override
141-
protected void decorate(UIComponent parent) {
142-
if (parent instanceof ClientBehaviorHolder) {
143-
ClientBehaviorHolder behaviorHolder = (ClientBehaviorHolder) parent;
144-
AjaxBehavior behavior = createAjaxBehavior();
145-
behaviorHolder.addClientBehavior(event, behavior);
146-
}
150+
public void decorate(ComponentModifier parent) {
151+
parent.addPassThrough("data-cui-block-element", "data-cui-block-element");
147152
}
148-
149-
private AjaxBehavior createAjaxBehavior() {
150-
// Create and configure the behavior
151-
// ...
152-
}
153-
154-
// Getters and setters...
155153
}
156154
----
157155

158156
== Examples from the Framework
159157

160158
=== TooltipComponent (Bootstrap Module)
161159

162-
The link:https://github.com/cuioss/cui-jsf-components/blob/main/modules/cui-jsf-bootstrap/src/main/java/de/cuioss/jsf/bootstrap/tooltip/TooltipComponent.java[TooltipComponent] in the Bootstrap module is an example of a decorator that adds tooltip functionality to its parent component:
163-
164-
[source,java]
165-
----
166-
public class TooltipComponent extends AbstractParentDecorator {
167-
168-
// Tooltip configuration properties...
169-
170-
@Override
171-
protected void decorate(UIComponent parent) {
172-
// Add tooltip-related attributes and behaviors to the parent
173-
parent.getAttributes().put("data-toggle", "tooltip");
174-
parent.getAttributes().put("data-placement", getPlacement());
175-
parent.getAttributes().put("title", getTitle());
176-
177-
// Add necessary CSS classes
178-
ComponentModifier modifier = ComponentModifierFactory.findFittingWrapper(parent);
179-
if (null != modifier) {
180-
modifier.addStyleClass(parent, "tooltip-enabled");
181-
}
182-
}
183-
}
184-
----
160+
The link:https://github.com/cuioss/cui-jsf-components/blob/main/modules/cui-jsf-bootstrap/src/main/java/de/cuioss/jsf/bootstrap/tooltip/TooltipComponent.java[TooltipComponent] in the Bootstrap module is a decorator that adds tooltip functionality to its parent component.
185161

186162
Usage:
187163

@@ -194,30 +170,42 @@ Usage:
194170

195171
=== ModalControl (Bootstrap Module)
196172

197-
The link:https://github.com/cuioss/cui-jsf-components/blob/main/modules/cui-jsf-bootstrap/src/main/java/de/cuioss/jsf/bootstrap/modal/ModalControl.java[ModalControl] decorator adds modal dialog control functionality to buttons:
173+
The link:https://github.com/cuioss/cui-jsf-components/blob/main/modules/cui-jsf-bootstrap/src/main/java/de/cuioss/jsf/bootstrap/modal/ModalControl.java[ModalControl] decorator adds modal dialog control functionality to buttons.
198174

199-
[source,java]
175+
Usage:
176+
177+
[source,xml]
178+
----
179+
<h:commandButton value="Open Modal">
180+
<cui:modalControl target="myModalId"/>
181+
</h:commandButton>
200182
----
201-
public class ModalControl extends AbstractParentDecorator {
202183

203-
private String target;
184+
=== BlockElementDecorator (Core Components Module)
204185

205-
@Override
206-
protected void decorate(UIComponent parent) {
207-
// Add modal control attributes
208-
parent.getAttributes().put("data-toggle", "modal");
209-
parent.getAttributes().put("data-target", "#" + target);
210-
}
211-
}
186+
The link:https://github.com/cuioss/cui-jsf-components/blob/main/modules/cui-jsf-core-components/src/main/java/de/cuioss/jsf/components/blockelement/BlockElementDecorator.java[BlockElementDecorator] adds functionality to disable a component and show a loading spinner during Ajax operations.
187+
188+
Usage:
189+
190+
[source,xml]
191+
----
192+
<boot:commandButton value="Submit">
193+
<f:ajax render="@this"/>
194+
<cui:blockElement/>
195+
</boot:commandButton>
212196
----
213197

198+
=== TypewatchComponent (Core Components Module)
199+
200+
The link:https://github.com/cuioss/cui-jsf-components/blob/main/modules/cui-jsf-core-components/src/main/java/de/cuioss/jsf/components/typewatch/TypewatchComponent.java[TypewatchComponent] monitors user input and triggers an action after the user stops typing for a specified period.
201+
214202
Usage:
215203

216204
[source,xml]
217205
----
218-
<h:commandButton value="Open Modal">
219-
<cui:modalControl target="myModalId"/>
220-
</h:commandButton>
206+
<h:inputText value="#{bean.searchTerm}">
207+
<cui:typewatch wait="500" listener="#{bean.search}"/>
208+
</h:inputText>
221209
----
222210

223211
== Implementation Guidelines

modules/cui-jsf-api/doc/components-partial.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ toc::[]
1313
== Overview
1414

1515
The partial implementation pattern is a design approach that follows the composite pattern to create flexible and reusable JSF components. Instead of relying heavily on inheritance, which can lead to complex class hierarchies, this pattern uses composition to combine specific behaviors into complete components.
16+
Another commonly used Anti-Pattern for component design is copy-pasting.
1617

1718
The `de.cuioss.jsf.api.components.partial` package contains provider interfaces and their implementations for common component attributes and behaviors. Many component implementations in the CUI JSF framework use these partial implementations to reduce code duplication and maintain consistency across the component library.
1819

@@ -25,6 +26,7 @@ Provider interfaces define contracts for specific component behaviors. Each inte
2526
=== Implementations
2627

2728
Concrete implementations of these interfaces provide the actual behavior. These implementations typically use the `CuiState` helper to manage component state in a JSF-friendly way.
29+
`CuiState` extends OmniFaces's `StateHelper` and provides additional convenience methods for using component state.
2830

2931
=== Component Bridges
3032

modules/cui-jsf-api/doc/components-renderer.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public class ElementReplacingResponseWriter extends ResponseWriterBase {
189189
}
190190
----
191191

192-
This writer is often used to adapt standard JSF components to Bootstrap or other CSS frameworks that require specific HTML structures.
192+
This writer is used to adapt standard JSF components to Bootstrap or other CSS frameworks that require specific HTML structures.
193193

194194
=== ResponseWriterBase
195195

modules/cui-jsf-api/doc/security-sanitization.adoc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ toc::[]
1414

1515
Web applications are vulnerable to Cross-Site Scripting (XSS) attacks when they display user-provided content without proper sanitization. The CUI JSF API provides a comprehensive set of tools to sanitize HTML content, preventing XSS vulnerabilities while allowing legitimate HTML formatting when needed.
1616

17+
== JSF Default Escaping
18+
19+
It's important to note that JSF, by design, provides default escaping for output, which helps prevent XSS attacks. However, it is still sensible to add sanitization as another line of defense, especially in the following scenarios:
20+
21+
1. When other clients are working on the same data that might not have the same built-in protections
22+
2. When a developer explicitly sets `escape="false"` on JSF components
23+
3. As part of a defense-in-depth security strategy
24+
25+
This multi-layered approach to security ensures that your application remains protected even if one layer is bypassed or disabled.
26+
1727
== CuiSanitizer
1828

1929
The `CuiSanitizer` enum is the core component of the security framework. It provides predefined sanitization policies based on the OWASP HTML Sanitizer library, offering different levels of HTML element and attribute filtering.
@@ -265,6 +275,7 @@ Some sanitizers preserve HTML entities, which can be useful for displaying speci
265275

266276
Sanitization adds some processing overhead. For high-performance applications, consider caching sanitized content when appropriate.
267277

278+
268279
== Conclusion
269280

270281
The CUI JSF API provides a comprehensive framework for HTML sanitization through the `CuiSanitizer` enum and corresponding converters. By using these tools consistently, you can protect your application from XSS attacks while still allowing rich HTML content when needed.

0 commit comments

Comments
 (0)