J2EE pattern • Presentation
J2EEPresentationJava example
View Helper solves a specific structural problem in the design.
Keep presentation-specific formatting and lookup logic near the view layer.
Pattern overview
J2EE pattern
Keep presentation-specific formatting and lookup logic near the view layer.
Intent
Encapsulate view preparation and formatting behavior outside raw templates or pages.
Problem
Templates become cluttered with formatting rules, lookup logic, and presentation decisions.
Solution
Use helper classes or tags to keep views focused on rendering.
Fit and tradeoffs
FamilyJ2EE
CategoryPresentation
Best used when
- For formatting, localization, and small presentation-only decisions.
Tradeoffs
- Business rules can leak into helpers if boundaries are weak.
Java example
This example is intentionally compact so the pattern shape stays easy to see.
public final class CurrencyViewHelper {
public String format(BigDecimal amount) {
return NumberFormat.getCurrencyInstance(Locale.US).format(amount);
}
}