2026-03-18 15:18:30 +08:00
|
|
|
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
|
|
|
|
|
<!DOCTYPE html>
|
2026-03-18 18:12:20 +08:00
|
|
|
<html lang="en">
|
2026-03-18 15:18:30 +08:00
|
|
|
<head>
|
|
|
|
|
<meta charset="UTF-8">
|
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
2026-03-18 18:12:20 +08:00
|
|
|
<title>Model Binding Guide</title>
|
2026-03-18 15:18:30 +08:00
|
|
|
<style>
|
2026-03-18 18:12:20 +08:00
|
|
|
body { margin: 0; padding: 24px; font-family: "Aptos", "Segoe UI", sans-serif; background: linear-gradient(135deg, #7c3aed, #a855f7); }
|
|
|
|
|
.shell { max-width: 980px; margin: 0 auto; background: rgba(255,255,255,0.96); border-radius: 28px; padding: 28px; box-shadow: 0 24px 60px rgba(0,0,0,0.18); }
|
|
|
|
|
.eyebrow { font-size: 12px; text-transform: uppercase; letter-spacing: 0.12em; color: #7c3aed; font-weight: 800; }
|
|
|
|
|
h1, h2 { margin: 10px 0 12px; }
|
|
|
|
|
p, li { color: #5e5570; line-height: 1.9; }
|
|
|
|
|
pre { background: #101827; color: #d9e7ff; padding: 18px; border-radius: 18px; overflow-x: auto; }
|
|
|
|
|
.links { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }
|
|
|
|
|
.btn { display: inline-flex; padding: 10px 14px; border-radius: 999px; text-decoration: none; font-weight: 700; background: #f0e9ff; color: #7c3aed; }
|
2026-03-18 15:18:30 +08:00
|
|
|
</style>
|
|
|
|
|
</head>
|
|
|
|
|
<body>
|
2026-03-18 18:12:20 +08:00
|
|
|
<div class="shell">
|
|
|
|
|
<div class="eyebrow">Guide</div>
|
|
|
|
|
<h1>Property binding vs model-driven binding</h1>
|
|
|
|
|
<p>This note helps explain how Struts2 turns request parameters into action state. It works well alongside the user form and validation examples.</p>
|
2026-03-18 15:18:30 +08:00
|
|
|
|
2026-03-18 18:12:20 +08:00
|
|
|
<h2>Property-driven</h2>
|
|
|
|
|
<ul>
|
|
|
|
|
<li>Define simple fields directly on the action.</li>
|
|
|
|
|
<li>Expose setters and getters for each form field.</li>
|
|
|
|
|
<li>Great for short demos and small forms.</li>
|
|
|
|
|
</ul>
|
2026-03-18 15:18:30 +08:00
|
|
|
|
2026-03-18 18:12:20 +08:00
|
|
|
<h2>Model-driven</h2>
|
|
|
|
|
<ul>
|
|
|
|
|
<li>Return a dedicated model object from <code>getModel()</code>.</li>
|
|
|
|
|
<li>Keep request data separate from action orchestration logic.</li>
|
|
|
|
|
<li>Better for larger forms and nested objects.</li>
|
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
|
|
<pre>public class UserAction extends ActionSupport implements ModelDriven<User> {
|
|
|
|
|
private final User user = new User();
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public User getModel() {
|
|
|
|
|
return user;
|
2026-03-18 15:18:30 +08:00
|
|
|
}
|
|
|
|
|
}</pre>
|
|
|
|
|
|
2026-03-18 18:12:20 +08:00
|
|
|
<div class="links">
|
|
|
|
|
<a class="btn" href="../../user/form.jsp">Open user form</a>
|
|
|
|
|
<a class="btn" href="../../index.jsp">Back to portal</a>
|
2026-03-18 15:18:30 +08:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</body>
|
2026-03-18 18:12:20 +08:00
|
|
|
</html>
|