### Run Basic Install
Source: https://github.com/apache/struts-site/blob/main/source/contributors/building-with-maven.md
Execute this command in the root of the source distribution to perform a basic Maven install. This will download dependencies, run tests, package JARs, and install them locally.
```bash
mvn
```
--------------------------------
### Info Panel Example
Source: https://github.com/apache/struts-site/blob/main/source/updating-website.md
This example demonstrates how to create an info-styled panel or alert box. Use for displaying general information.
```text
Info panel
{:.alert .alert-info}
```
--------------------------------
### Example: Storing and Retrieving Messages
Source: https://github.com/apache/struts-site/blob/main/source/core-developers/message-store-interceptor.md
This example demonstrates storing messages in 'submitApplication.action' and retrieving them in 'applicationFailed.action'.
```xml
STORE
applicationFailedapplicationSuccess.jsp
RETRIEVE
applicationFailed.jsp
```
--------------------------------
### Warning Panel Example
Source: https://github.com/apache/struts-site/blob/main/source/updating-website.md
This example shows how to create a warning-styled panel. Use for displaying cautionary messages or alerts.
```text
Warning panel
{:.alert .alert-warning}
```
--------------------------------
### Install Project with Maven
Source: https://github.com/apache/struts-site/blob/main/source/maven-archetypes/index.md
Installs the project artifacts into the local Maven repository. This command should be run from the project's root directory.
```bash
mvn install
```
--------------------------------
### Hello World JSP Example
Source: https://github.com/apache/struts-site/blob/main/source/plugins/convention/index.md
A simple JSP file for a 'hello-world' example. The Convention Plugin automatically maps URLs to results based on naming conventions, assuming results are in `WEB-INF/content` by default.
```jsp
Hello world!
```
--------------------------------
### Tiles Definition File Example (tiles.xml)
Source: https://github.com/apache/struts-site/blob/main/source/plugins/tiles/index.md
Define Tiles layouts and pages in a tiles.xml file. This example shows a layout and a specific page extending it.
```xml
```
--------------------------------
### Background Success Example
Source: https://github.com/apache/struts-site/blob/main/source/updating-website.md
This example demonstrates setting the background color to the success theme color. Use for elements related to successful operations.
```text
Background success
{:.bg-success}
```
--------------------------------
### Basic Action Chaining Example
Source: https://github.com/apache/struts-site/blob/main/source/core-developers/chaining-interceptor.md
This example demonstrates how to chain two actions, 'someAction' to 'otherAction', using the 'chain' result type.
```xml
otherActiongood_result.ftl
```
--------------------------------
### Install Bundler
Source: https://github.com/apache/struts-site/blob/main/GEMINI.md
Installs the Bundler gem, a dependency manager for Ruby projects. Run this before installing other Ruby gems.
```bash
gem install bundler
```
--------------------------------
### Bind Tag Examples
Source: https://github.com/apache/struts-site/blob/main/source/tag-developers/dojo-bind-tag.md
Examples demonstrating various use cases of the sx:bind tag.
```APIDOC
## Bind Tag Examples
Examples demonstrating various use cases of the `sx:bind` tag.
### Example 1: Listening to a topic (making an Ajax call without attaching to an event)
```xml
```
### Example 2: Attached to an event 'onclick' on a submit button
```xml
```
### Example 3: Submit form
```xml
```
### Example 4: Using beforeNotifyTopics
```xml
```
### Example 5: Using afterNotifyTopics and highlight
```xml
```
### Example 6: Using errorNotifyTopics and indicator
(No specific code example provided in the source text for this scenario, but the attribute is documented.)
```
--------------------------------
### Submit Tag Examples
Source: https://github.com/apache/struts-site/blob/main/source/tag-developers/dojo-submit-tag.md
Examples demonstrating various ways to use the Struts submit tag.
```APIDOC
## Submit Tag Examples
Examples demonstrating various ways to use the Struts submit tag.
### Render a default submit button
```xml
```
### Render an image submit
```xml
```
### Render a button submit
```xml
```
### Update target content with HTML returned from an action
```xml
Div 1
```
### Submit form (inside the form)
```xml
```
### Submit form (outside the form)
```xml
```
```
--------------------------------
### Example Resource Bundle Structure
Source: https://github.com/apache/struts-site/blob/main/source/core-developers/localization.md
Illustrates the hierarchical search order for resource bundles within packages and action classes.
```text
com/
acme/
package.properties
actions/
package.properties
FooAction.java
FooAction.properties
```
--------------------------------
### RESTful URL to Method Mapping Examples
Source: https://github.com/apache/struts-site/blob/main/source/plugins/rest/index.md
These examples illustrate how different HTTP methods and URL patterns map to specific controller methods and parameters in a RESTful context.
```text
GET: /movies => method=index
GET: /movies/Thrillers => method=show, id=Thrillers
GET: /movies/Thrillers;edit => method=edit, id=Thrillers
GET: /movies/Thrillers/edit => method=edit, id=Thrillers
GET: /movies/new => method=editNew
POST: /movies => method=create
PUT: /movies/Thrillers => method=update, id=Thrillers
DELETE: /movies/Thrillers => method=destroy, id=Thrillers
```
--------------------------------
### Create a RESTful Controller Action
Source: https://github.com/apache/struts-site/blob/main/source/plugins/rest/index.md
Implement controller actions for RESTful resources. This example handles GET requests for '/orders/{id}' and PUT requests for '/orders/{id}'. It uses the ModelDriven interface to ensure only the Order object is serialized.
```java
package org.apache.struts2.rest.example;
public class OrdersController implements ModelDriven {
private OrderManager orderManager;
private String id;
private Order model;
// Handles /orders/{id} GET requests
public HttpHeaders show() {
model = orderManager.findOrder(id);
return new DefaultHttpHeaders("show")
.withETag(model.getUniqueStamp())
.lastModified(model.getLastModified());
}
// Handles /orders/{id} PUT requests
public String update() {
orderManager.updateOrder(model);
return "update";
}
// getters and setters
}
```
--------------------------------
### Example Action Mapping Configuration
Source: https://github.com/apache/struts-site/blob/main/source/core-developers/action-file-upload.md
Configure an Action mapping for your Action class to handle file uploads.
```xml
good_result.jsp
```
--------------------------------
### Post-Back Form Example
Source: https://github.com/apache/struts-site/blob/main/source/core-developers/action-configuration.md
This example demonstrates a form that submits back to the action that created it, utilizing the default execute method for handling the submission.
```jsp
```
--------------------------------
### Project Setup for REST Demo
Source: https://github.com/apache/struts-site/blob/main/source/plugins/rest/index.md
Steps to set up a Struts 2 project for the REST demo by adding necessary plugins.
```APIDOC
## Usage
### Setting Up
Assuming you have a normal Struts 2 application, all you need to do for this REST demo is to add the following two plugins:
- Struts 2 Rest Plugin
- Struts 2 Convention Plugin
> Note, you can download the jars for these plugins from [Maven Central](http://search.maven.org/#search%7Cga%7C1%7Cstruts2-convention-plugin)
```
--------------------------------
### Label Success Example
Source: https://github.com/apache/struts-site/blob/main/source/updating-website.md
This example demonstrates creating a success-colored label. Use for tags indicating positive status or completion.
```text
Label success
{:.label .label-success}
```
--------------------------------
### Build Struts with Maven
Source: https://github.com/apache/struts-site/blob/main/source/contributors/building-the-framework-from-source.md
Navigate to the framework's home directory and execute the Maven clean install command to build the project.
```bash
cd Projects\Apache\struts
mvn clean install
```
--------------------------------
### Restful2ActionMapper Package Configuration Example
Source: https://github.com/apache/struts-site/blob/main/source/core-developers/restful-action-mapper.md
An example of configuring a package for REST actions using Restful2ActionMapper, including interceptor configuration and action mapping.
```xml
....interceptor config
{1}
....results
....
```
--------------------------------
### Action Chaining Example
Source: https://github.com/apache/struts-site/blob/main/source/plugins/convention/index.md
This example demonstrates action chaining. If action 'foo' returns 'bar' and no result is defined for 'bar', the Convention plugin will look for and execute an action named 'foo-bar' in the same package.
```java
package com.example.actions;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;
public class HelloAction extends ActionSupport {
@Action("foo")
public String foo() {
return "bar";
}
@Action("foo-bar")
public String bar() {
return SUCCESS;
}
}
```
--------------------------------
### Struts 2.1 web.xml Filter Chain Example
Source: https://github.com/apache/struts-site/blob/main/source/plugins/sitemesh/index.md
This example shows the web.xml configuration for Struts 2.1, including Struts prepare and execute filters, and SiteMesh filter.
```xml
struts-prepareorg.apache.struts2.dispatcher.filter.StrutsPrepareFilterstruts-executeorg.apache.struts2.dispatcher.filter.StrutsExecuteFiltersitemeshcom.opensymphony.module.sitemesh.filter.PageFilterstruts-prepare/*sitemesh/*struts-execute/*
```
--------------------------------
### Struts URL Tag Example
Source: https://github.com/apache/struts-site/blob/main/source/getting-started/hello-world-using-struts.md
This example demonstrates how to use the Struts URL tag to generate a link to a specific action named 'hello'.
```html
```
--------------------------------
### Bind tag example with loading indicator
Source: https://github.com/apache/struts-site/blob/main/source/tag-developers/dojo-bind-tag.md
This example demonstrates how to use the bind tag to update a div's content when a button is clicked. It shows how to configure event sources, targets, and manage loading text display.
```jsp
```
--------------------------------
### Run Site Locally with Jekyll
Source: https://github.com/apache/struts-site/blob/main/CLAUDE.md
Install dependencies and serve the site locally using Jekyll directly. Requires Ruby and Bundler.
```bash
# Using Jekyll directly
bundle install # Install dependencies
bundle exec jekyll serve -w --trace --host 0.0.0.0
```
--------------------------------
### Background Info Example
Source: https://github.com/apache/struts-site/blob/main/source/updating-website.md
Apply this class to set the background color to the info theme color. Suitable for informational blocks or callouts.
```text
Background info
{:.bg-info}
```
--------------------------------
### Example XWork Package Naming
Source: https://github.com/apache/struts-site/blob/main/source/plugins/convention/index.md
This is an example of an XWork package name generated by the Convention plugin for an action in the 'com.example.actions' Java package with a '/' namespace and 'conventionDefault' parent package.
```plaintext
com.example.actions#/#conventionDefault
```
--------------------------------
### Label Info Example
Source: https://github.com/apache/struts-site/blob/main/source/updating-website.md
Use this class combination to create an info-colored label. Suitable for informational tags.
```text
Label info
{:.label .label-info}
```
--------------------------------
### Initialize Project with Maven
Source: https://github.com/apache/struts-site/blob/main/source/maven-archetypes/index.md
Performs project initialization tasks, including downloading necessary JAR files and dependencies. Run from the project's root directory.
```bash
mvn initialize
```
--------------------------------
### Get User from LoginPage
Source: https://github.com/apache/struts-site/blob/main/source/tag-developers/ognl-expression-compilation.md
Retrieves the user from a LoginPage object. This is an example of a direct OGNL expression evaluation.
```java
public void get(OgnlContext context, Object root) {
return ((LoginPage)root).getUser();
}
```
--------------------------------
### Annotated Action Example
Source: https://github.com/apache/struts-site/blob/main/source/core-developers/annotation-workflow-interceptor.md
Demonstrates an action class with @Before, @BeforeResult, and @After annotations. The order of execution for @Before annotations on superclasses is guaranteed before subclasses.
```java
public class BaseAnnotatedAction {
protected String log = "";
@Before
public String baseBefore() {
log = log + "baseBefore-";
return null;
}
}
public class AnnotatedAction extends BaseAnnotatedAction {
@Before
public String before() {
log = log + "before";
return null;
}
public String execute() {
log = log + "-execute";
return Action.SUCCESS;
}
@BeforeResult
public void beforeResult() throws Exception {
log = log +"-beforeResult";
}
@After
public void after() {
log = log + "-after";
}
}
```
--------------------------------
### Basic Wildcard Mapping Example
Source: https://github.com/apache/struts-site/blob/main/source/core-developers/wildcard-mappings.md
Use a wildcard '*' in the 'name' attribute to match URIs starting with '/edit'. The matched part is substituted into attributes using {1}.
```xml
/mainMenu.jsp{1}.jsp
```
--------------------------------
### Run Site Locally with Docker
Source: https://github.com/apache/struts-site/blob/main/CLAUDE.md
Use these commands to build the Docker image and serve the site locally. Recommended for Apple Silicon.
```bash
# Using Docker (recommended, Apple Silicon)
./docker-build.sh # Build image (only when Dockerfile changes)
./docker-arm64-serve.sh # Serve site at http://localhost:4000
```
--------------------------------
### Build Struts with Maven
Source: https://github.com/apache/struts-site/blob/main/source/builds.md
Install Apache Struts from source using Maven. Maven will automatically download necessary dependencies.
```bash
> mvn install
```
--------------------------------
### Access and Modify HTTP Session in Action
Source: https://github.com/apache/struts-site/blob/main/source/getting-started/http-session.md
Use the injected userSession map to get and put objects into the HTTP session. This example increments a counter stored in the session.
```java
private void increaseHelloCount() {
Integer helloCount = (Integer) userSession.get(HELLO_COUNT);
if (helloCount == null ) {
helloCount = 1;
} else {
helloCount++;
}
userSession.put(HELLO_COUNT, helloCount);
}
```
--------------------------------
### Lazy Parameter Evaluation in Interceptor
Source: https://github.com/apache/struts-site/blob/main/source/core-developers/interceptors.md
This example shows how to define an interceptor with parameters that are evaluated lazily during action invocation. The interceptor must implement the `WithLazyParams` interface. Parameters are evaluated as expressions starting from the action context.
```xml
result.jsp
${bar}
```
--------------------------------
### Access ValueStack using Custom EL Functions
Source: https://github.com/apache/struts-site/blob/main/source/tag-developers/access-to-valuestack-from-jsps.md
Import a custom TLD to use EL functions for accessing the ValueStack. This example shows how to retrieve array elements, perform calculations, and get action context information.
```jsp
<%@ taglib uri="/WEB-INF/tld/wwel.tld" prefix="x" %>
a[0] = ${x:vs('a[0]')}
a[0] * 4 = ${x:vs('a[0] * 4')}
Current action name: ${x:name()}
Top of ValueStack: ${x:top()}
```
--------------------------------
### Install Jekyll Dependencies
Source: https://github.com/apache/struts-site/blob/main/GEMINI.md
Installs all the necessary Ruby gems for the Jekyll project. This command should be run after installing Bundler.
```bash
bundle install
```
--------------------------------
### Configure Chain Result to Login Action
Source: https://github.com/apache/struts-site/blob/main/source/core-developers/chain-result.md
This example demonstrates chaining the 'createAccount' action to the 'login' action using the default parameter. Ensure the 'login' action is defined in the same package.
```xml
login
dashboard
/secure
```
--------------------------------
### Implement CspSettingsAware Interface
Source: https://github.com/apache/struts-site/blob/main/source/core-developers/csp-interceptor.md
Java example demonstrating how to implement the CspSettingsAware interface to configure CSP settings per action. Requires implementing the getCspSettings() method.
```java
public class MyAction implements CspSettingsAware {
public String execute() {
return "success";
}
public CspSetting getCspSettings() {
...
}
}
```
--------------------------------
### Create URL Including GET Parameters
Source: https://github.com/apache/struts-site/blob/main/source/tag-developers/url-tag.md
Generate a URL that includes all GET parameters. A specific parameter 'id' is also set, which will take precedence over any existing 'id' parameter if includeParams is 'get' or 'all'.
```jsp
```
--------------------------------
### Java Hello World Example
Source: https://github.com/apache/struts-site/blob/main/source/contributors/documentation-style-guide.md
A basic Java class demonstrating a 'Hello, World!' program. Ensure code blocks are properly formatted with spaces instead of tabs and adhere to line length limits.
```java
/** Hello World class. */
public class HelloWorld {
/** Main method. */
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
```
--------------------------------
### Compile and Run Hello World
Source: https://github.com/apache/struts-site/blob/main/source/contributors/documentation-style-guide.md
Command-line instructions for compiling and running a Java program. Use the '$' symbol to denote system prompts.
```bash
$ javac HelloWorld.java
$ java HelloWorld
Hello, World!
```
--------------------------------
### Label Danger Example
Source: https://github.com/apache/struts-site/blob/main/source/updating-website.md
This example shows how to create a danger-colored label. Use for tags indicating errors or critical states.
```text
Label danger
{:.label .label-danger}
```
--------------------------------
### JSP Example: Hello.jsp with include
Source: https://github.com/apache/struts-site/blob/main/source/plugins/embedded-jsp/index.md
A JSP file demonstrating the use of `` to include another JSP. Note that relative paths are not supported; use the full classpath resource path.
```jsp
```
--------------------------------
### Package Project with Maven
Source: https://github.com/apache/struts-site/blob/main/source/maven-archetypes/index.md
Creates a WAR file for deployment. This command compiles the code, runs tests, and packages the application. Execute from the project's root directory.
```bash
mvn package
```
--------------------------------
### Label Primary Example
Source: https://github.com/apache/struts-site/blob/main/source/updating-website.md
This example shows how to create a primary-colored label. Labels are often used to categorize or tag content.
```text
Label primary
{:.label .label-primary}
```
--------------------------------
### Text Left Alignment Example
Source: https://github.com/apache/struts-site/blob/main/source/updating-website.md
Use this example to align text to the left. This is typically the default alignment, but can be explicitly set.
```text
Text left
{:.text-left}
```
--------------------------------
### SiteGraph Command-Line Usage
Source: https://github.com/apache/struts-site/blob/main/source/plugins/sitegraph/index.md
Demonstrates the command-line syntax for executing the SiteGraph plugin, specifying configuration, view directories, and output location.
```text
java -cp ... -jar struts2-sitegraph-plugin-x.x.x.jar
-config CONFIG_DIR
-views VIEWS_DIRS
-output OUTPUT
[-ns NAMESPACE]
```
```text
Usage: -config CONFIG_DIR -views VIEWS_DIRS -output OUTPUT [-ns NAMESPACE]
CONFIG_DIR => a directory containing struts.xml
VIEWS_DIRS => comma seperated list of dirs containing JSPs, VMs, etc
OUPUT => the directory where the output should go
NAMESPACE => the namespace path restriction (/, /foo, etc)
```
--------------------------------
### Custom JSONWriter Implementation Example
Source: https://github.com/apache/struts-site/blob/main/source/plugins/json/index.md
An example Java class implementing the 'JSONWriter' interface to customize JSON serialization using Flexjson.
```java
import flexjson.JSONSerializer;
import flexjson.transformer.DateTransformer;
import org.apache.struts2.json.JSONException;
import org.apache.struts2.json.JSONWriter;
public class FlexJSONWriter implements JSONWriter {
private String dateFormatter;
public String write(Object object) throws JSONException {
return this.write(object, null, null, false);
}
public String write(Object object, Collection excludeProperties, Collection includeProperties,
boolean excludeNullProperties) throws JSONException {
JSONSerializer serializer = new JSONSerializer();
if (excludeProperties != null) {
for (Pattern p : excludeProperties) {
serializer = serializer.exclude(p.pattern());
}
}
if (includeProperties != null) {
for (Pattern p : includeProperties) {
serializer = serializer.include(p.pattern());
}
}
if (excludeNullProperties) {
serializer = serializer.transform(new ExcludeTransformer(), void.class);
}
if (dateFormatter != null) {
serializer = serializer.transform(new DateTransformer(dateFormatter), Date.class);
}
return serializer.serialize(object);
}
//...
```
--------------------------------
### Struts Configuration Example (struts.xml)
Source: https://github.com/apache/struts-site/blob/main/source/core-developers/nutshell.md
A sample XML configuration file for Struts, defining packages, action mappings, and results for a login workflow. This file controls how requests are mapped to Action classes and how results are rendered.
```xml
/pages/Logon.jspWelcomeMainMenuChangePasswordWelcome
```
--------------------------------
### Parameterized Message Example
Source: https://github.com/apache/struts-site/blob/main/source/core-developers/validation.md
This is an example of a parameterized message that can be used in validation. It pulls 'min' and 'max' parameters from the IntRangeFieldValidator and the 'bar' value from the Action.
```plaintext
bar must be between ${min} and ${max}, current value is ${bar}.
```
--------------------------------
### Maven Build Success Output
Source: https://github.com/apache/struts-site/blob/main/source/contributors/building-with-maven.md
Example output indicating a successful Maven build. This shows the summary of modules built and the total time taken.
```bash
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] Struts 2 Bill of Materials ......................... SUCCESS [ 1.188 s]
[INFO] Struts 2 2.5.24-SNAPSHOT ........................... SUCCESS [ 2.249 s]
[INFO] Struts 2 Core ...................................... SUCCESS [01:13 min]
[INFO] Struts Plugins ..................................... SUCCESS [ 0.232 s]
[INFO] Struts 2 Configuration Browser Plugin .............. SUCCESS [ 1.374 s]
[INFO] Struts 2 Sitemesh Plugin ........................... SUCCESS [ 1.429 s]
[INFO] Struts 2 Tiles Plugin .............................. SUCCESS [ 2.303 s]
[INFO] Struts 2 DWR Plugin ................................ SUCCESS [ 0.905 s]
[INFO] Struts 2 Spring Plugin ............................. SUCCESS [ 2.232 s]
[INFO] Struts 2 Convention Plugin ......................... SUCCESS [ 4.540 s]
[INFO] Struts 2 JUnit Plugin .............................. SUCCESS [ 4.297 s]
[INFO] Struts 2 JSON Plugin ............................... SUCCESS [ 5.384 s]
[INFO] Struts 2 Bean Validation Plugin .................... SUCCESS [ 3.345 s]
[INFO] Struts 2 Webapps ................................... SUCCESS [ 0.391 s]
[INFO] Struts 2 Showcase Webapp ........................... SUCCESS [ 6.104 s]
[INFO] Struts 2 REST Plugin ............................... SUCCESS [ 4.058 s]
[INFO] Struts 2 Rest Showcase Webapp ...................... SUCCESS [ 1.524 s]
[INFO] Struts 2 CDI Plugin ................................ SUCCESS [ 2.758 s]
[INFO] Struts 2 Embedded JSP Plugin ....................... SUCCESS [ 8.111 s]
[INFO] Struts 2 GXP Plugin ................................ SUCCESS [ 1.137 s]
[INFO] Struts 2 Jasper Reports Plugin ..................... SUCCESS [ 4.392 s]
[INFO] Struts 2 Java Templates Plugin ..................... SUCCESS [ 2.666 s]
[INFO] Struts 2 JFreeChart Plugin ......................... SUCCESS [ 3.169 s]
[INFO] Struts 2 OSGi Plugin ............................... SUCCESS [ 3.209 s]
[INFO] Struts 2 OVal Plugin ............................... SUCCESS [ 3.113 s]
[INFO] Struts 2 Pell Multipart Plugin ..................... SUCCESS [ 0.842 s]
[INFO] Struts 2 Plexus Plugin ............................. SUCCESS [ 1.003 s]
[INFO] Struts 2 Portlet Plugin ............................ SUCCESS [ 5.210 s]
[INFO] Struts 2 Portlet Tiles Plugin ...................... SUCCESS [ 0.999 s]
[INFO] DEPRECATED: Struts 2 Sitegraph Plugin .............. SUCCESS [ 2.634 s]
[INFO] Struts 2 TestNG Plugin ............................. SUCCESS [ 2.081 s]
[INFO] Struts OSGi Bundles ................................ SUCCESS [ 0.083 s]
[INFO] Struts 2 OSGi Admin Bundle ......................... SUCCESS [ 1.237 s]
[INFO] Struts 2 OSGi Demo Bundle 2.5.24-SNAPSHOT .......... SUCCESS [ 1.157 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 02:39 min
[INFO] Finished at: 2020-08-14T11:24:15+02:00
[INFO] ------------------------------------------------------------------------
```
--------------------------------
### Implement ActionEventListener for Action Preparation
Source: https://github.com/apache/struts-site/blob/main/source/core-developers/action-event-listener.md
Implement the prepare method to intercept action instantiation. This example shows how to set a UserService on a MyBaseAction instance using the ValueStack.
```java
public class MyActionEventListener implements ActionEventListener {
public Object prepare(Object action, ValueStack stack) {
if (action instanceof MyBaseAction) {
((MyBaseAction)action).setUserService(stack.findValue("userService"));
}
}
public String handleException(Throwable t, ValueStack stack) {
if (t instanceof MyBusinessException) {
return stack.findString("defaultBusinesResult");
}
return null;
}
}
```
--------------------------------
### Package Application into WAR with Maven
Source: https://github.com/apache/struts-site/blob/main/source/maven-archetypes/struts2-archetype-blank.md
Creates a Web Application Archive (WAR) file in the 'target' directory, ready for deployment.
```bash
$ mvn package
```
--------------------------------
### Text Danger Color Example
Source: https://github.com/apache/struts-site/blob/main/source/updating-website.md
This example shows how to color text with the danger theme color. Typically used for error messages or critical alerts.
```text
Text danger
{:.text-danger}
```
--------------------------------
### Resume Release Preparation
Source: https://github.com/apache/struts-site/blob/main/source/contributors/building-struts-master.md
Use this command to resume the release preparation process if it failed previously. It will pick up from where it left off.
```bash
mvn release:prepare -Dresume
```
--------------------------------
### Text Success Color Example
Source: https://github.com/apache/struts-site/blob/main/source/updating-website.md
This example demonstrates setting text color to the success theme color. Ideal for indicating positive outcomes or confirmations.
```text
Text success
{:.text-success}
```
--------------------------------
### Example Abstract LoginPage Class
Source: https://github.com/apache/struts-site/blob/main/source/tag-developers/ognl-expression-compilation.md
An example of an abstract LoginPage class in Tapestry that implements UserPermissions, showing the structure relevant to OGNL expression compilation.
```java
public abstract LoginPage extends BasePage implements UserPermissions {
public abstract User getUser();
}
..
/**
* Interface for any page/component that holds references to the current system
* User.
*/
public interface UserPermissions {
User getUser();
}
```
--------------------------------
### Example OGNL Expression for Tapestry
Source: https://github.com/apache/struts-site/blob/main/source/tag-developers/ognl-expression-compilation.md
An example of an OGNL expression 'user.firstName' used in a Tapestry context, illustrating how it might be compiled against different object instances.
```ognl
user.firstName
```
--------------------------------
### Generate Website Locally with Docker
Source: https://github.com/apache/struts-site/blob/main/source/contributors/building-normal-release.md
These commands show how to build the Struts website locally using a Docker Jekyll image. Ensure Docker is installed and running.
```bash
# Download the official Struts image to build the site from
# https://hub.docker.com/r/theapachestruts/struts-site-jekyll/
# Use one of the bash scripts already provided in the `struts-site`:
# docker-run.sh - used with Bash
# docker-run.fish - to use with Fish Shell (via `fish docker-run.fish`)
# Check the generated site at http://localhost:4000
```
--------------------------------
### Text Justify Alignment Example
Source: https://github.com/apache/struts-site/blob/main/source/updating-website.md
This example shows how to justify text, spreading it evenly between the left and right edges. Apply the class to the text container.
```text
Text justify
{:.text-justify}
```
--------------------------------
### Define a Package with Actions
Source: https://github.com/apache/struts-site/blob/main/source/core-developers/package-configuration.md
This example demonstrates a basic package configuration named 'employee' that extends 'struts-default' and defines several actions with their associated results and interceptors.
```xml
/empmanager/listEmployees.jsp
{1}
/empmanager/editEmployee.jsp
execute
/empmanager/editEmployee.jspedit-${currentEmployee.empId}.action/empmanager/editEmployee.jspedit-${currentEmployee.empId}.action
```
--------------------------------
### XML Action Mapping Configuration
Source: https://github.com/apache/struts-site/blob/main/source/core-developers/action-configuration.md
Defines an action named 'Logon' that maps to the 'tutorial.Logon' class, specifying a redirect action and an input result.
```xml
Menu/Logon.jsp
```
--------------------------------
### Text Center Alignment Example
Source: https://github.com/apache/struts-site/blob/main/source/updating-website.md
This example demonstrates how to center-align text using the provided class. Ensure the class is correctly applied to the relevant HTML element.
```text
Text center
{:.text-center}
```
--------------------------------
### Run Project with Jetty using Maven
Source: https://github.com/apache/struts-site/blob/main/source/maven-archetypes/index.md
Starts the embedded Jetty server to run the application. This command is useful for local development and testing. Execute from the project's root directory.
```bash
mvn jetty:run
```
--------------------------------
### Install Custom OGNL Cache Factories (struts.xml)
Source: https://github.com/apache/struts-site/blob/main/source/core-developers/ognl-cache-configuration.md
Install custom OGNL cache factories in struts.xml by specifying the fully qualified class names that implement OgnlCacheFactory.
```xml
```
--------------------------------
### Prepare Release with Maven
Source: https://github.com/apache/struts-site/blob/main/source/contributors/building-struts-master.md
Initiates the release preparation process using the Maven release plugin. Ensure you have the latest Apache Parent POM applied and committed before running this.
```bash
mvn release:prepare -DautoVersionSubmodules=true
```
--------------------------------
### Configurable OptionTransferSelect Example
Source: https://github.com/apache/struts-site/blob/main/source/tag-developers/optiontransferselect-tag.md
This example demonstrates a more configurable optionTransferSelect tag. It includes custom titles for each list, enables multiple selections, and sets header and empty options for both lists.
```jsp
```
--------------------------------
### Basic Usage of sx:head Tag
Source: https://github.com/apache/struts-site/blob/main/source/tag-developers/dojo-head-tag.md
A simple example demonstrating how to include the `sx:head` tag within an HTML head section.
```APIDOC
## Basic Usage of sx:head Tag
### Description
This example shows the minimal configuration required to include the Dojo head tag in your Struts application.
### Method
N/A (JSP Tag)
### Endpoint
N/A (JSP Tag)
### Request Body
N/A (JSP Tag)
### Request Example
```xml
<%@ taglib prefix="sx" uri="/struts-dojo-tags" %>
My page
```
### Response
N/A (JSP Tag)
```