Skip to Main Content
Jakarta Struts Cookbook
book

Jakarta Struts Cookbook

by Bill Siggelkow
February 2005
Intermediate to advanced content levelIntermediate to advanced
528 pages
12h 53m
English
O'Reilly Media, Inc.
Content preview from Jakarta Struts Cookbook

6.9. Submitting a Form from Localized Form Controls

Problem

You want to use a single Action class to process related operations where each button, which has a localized value, on a form corresponds to a specific method in the Action class.

Solution

Extend the Struts pre-built LookupDispatchAction with your own class. Provide methods for each operation you wish to be called. Each method should have the same signature as the execute( ) method. Implement the getKeyMethodMap() method, mapping the button label resource bundle key to the corresponding method name to call. The Action class shown in Example 6-6 provides three related operations in one class: create( ), update( ), and delete( ). The getKeyMethodMap( ) method returns a map where the map key is a MessageResources key for the button label, and the map value is the corresponding method name.

Example 6-6. LookupDispatchAction for related operations

package com.oreilly.strutsckbk.ch06; import java.util.HashMap; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.apache.struts.actions.LookupDispatchAction; public class MyLookupDispatchAction extends LookupDispatchAction { public MyLookupDispatchAction( ) { keyMethodMap = new HashMap( ); keyMethodMap.put("button.add", "create"); keyMethodMap.put("button.edit", "update"); ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming Jakarta Struts

Programming Jakarta Struts

Chuck Cavaness
Beginning Spring Framework 2

Beginning Spring Framework 2

Bruce Snyder, Sing Li, Anne Horton, Thomas Van de Velde, Naveen Balani, Christian Dupuis
Java Cookbook

Java Cookbook

Ian F. Darwin
Struts 2 in Action

Struts 2 in Action

J. Scott Stanlick, Chad Michael Davis, Donald J. Brown

Publisher Resources

ISBN: 059600771XSupplemental ContentErrata Page