Date: 2004-07-26T00:43:48
Editor: MichaelMcGrady <[EMAIL PROTECTED]>
Wiki: Apache Struts Wiki
Page: StrutsCatalogMultipleImageButtonsWithNoJavaScript
URL: http://wiki.apache.org/struts/StrutsCatalogMultipleImageButtonsWithNoJavaScript
no comment
Change Log:
------------------------------------------------------------------------------
@@ -2,93 +2,132 @@
This code is the composite of the work of lots of people and they also built on those
before them. References to them is at the bottom, but I wanted to acknowledge this at
the start.
+The key to the below is that the image tag will send
button.submit.x=19&button.submit.y=10 and the properties button.submit.x and
button.submit.y will be set as follows:
+
+{{{
+ [ActionForm].getButton().getSubmit().setX(new Integer("9"));
+ [ActionForm].getButton().getSubmit().setX(new Integer("8"));
+}}}
+
Here's the button I use.
{{{
-public class CrackWillowButton implements Serializable {
- private String name = null;
- private Integer x = null;
- private Integer y = null;
+public class Button
+ implements Serializable {
+ private String name = null;
+ private Integer x = null;
+ private Integer y = null;
- public CrackWillowButton() {
- }
+ public Button() {
+ }
- public boolean pressed() {
- return !(name == null || name.trim().length() <= 0) ||
- (x != null || y != null);
- }
+ public Button(String name) {
+ this.name = name;
+ }
- public String getName() {
- return name;
- }
+ public boolean pressed() {
+ return (x != null || y != null);
+ }
- public Integer getX() {
- return x;
- }
+ public String getName() {
+ return name;
+ }
- public Integer getY() {
- return y;
- }
+ public Integer getX() {
+ return x;
+ }
- public void setName(String name) {
- this.name = name;
- }
+ public Integer getY() {
+ return y;
+ }
- public void setX(Integer x) {
- this.x = x;
- }
+ public void setName(String name) {
+ this.name = name;
+ }
- public void setY(Integer y) {
- this.y = y;
- }
-}
+ public void setX(Integer x) {
+ this.x = x;
+ }
+
+ public void setY(Integer y) {
+ this.y = y;
+ }
+
+ public String toString() {
+ return "Button: name = " + name + " x = " + x + " y = " + y;
+ }
}}}
-Here's the class that classifies the buttons into the operation they represent:
+Here's the class that classifies the buttons into the operations they represent:
{{{
-public class ButtonOperation implements Serializable {
- protected CrackWillowButton submit = new CrackWillowButton();
- protected CrackWillowButton clear = new CrackWillowButton();
- protected CrackWillowButton cancel = new CrackWillowButton();
- protected CrackWillowButton reset = new CrackWillowButton();
+public class ButtonOperation
+ implements Serializable {
+
+ protected Button cancel = new Button("cancel");
+ protected Button change = new Button("change");
+ protected Button clear = new Button("clear");
+ protected Button commitChange = new Button("commitChange");
+ protected Button exit = new Button("exit");
+ protected Button reset = new Button("reset");
+ protected Button select = new Button("select");
+ protected Button submit = new Button("submit");
public ButtonOperation() {
}
- public CrackWillowButton getCancel() {
+ public Button getCancel() {
return cancel;
}
- public CrackWillowButton getClear() {
+ public Button getChange() {
+ return change;
+ }
+
+ public Button getClear() {
return clear;
}
- public CrackWillowButton getSubmit() {
- return submit;
+ public Button getCommitChange() {
+ return commitChange;
}
+ public Button getExit() {
+ return exit;
+ }
- public CrackWillowButton getReset() {
+ public Button getReset() {
return reset;
}
- public void setCancel(CrackWillowButton cancel) {
- this.cancel = cancel;
+ public Button getSelect() {
+ return select;
}
- public void setClear(CrackWillowButton clear) {
- this.clear = clear;
+ public Button getSubmit() {
+ return submit;
}
+}
+}}}
+
+Here's the code !ActionForm for this action:
- public void setSubmit(CrackWillowButton submit) {
- this.submit = submit;
+{{{
+
+public class LogonForm
+ extends ActionForm {
+ protected ButtonOperation button = null;
+
+ public LogonForm() {
}
- public void setReset(CrackWillowButton reset) {
- this.reset = reset;
+ public void reset(ActionMapping mapping, HttpServletRequest request) {
+ button = new ButtonOperation();
}
-}
+
+ public ButtonOperation getButton() { return button; }
+ public void setButton (ButtonOperation button) { this.button = button; }
+} ///;-) Michael McGrady HomeSites
}}}
Here's an Action using these buttons for a registration form:
@@ -123,61 +162,6 @@
// example only
return null;
- }
-}
-}}}
-
-Here's the code !ActionForm for this action:
-
-{{{
-public class ButtonForm
- extends ActionForm {
- private ButtonOperation button = null;
- private String firstName = null;
- private String lastName = null;
- private String email = null;
-
- public ButtonForm() {
- }
-
- public void reset(ActionMapping mapping, HttpServletRequest request) {
- button = new ButtonOperation();
- firstName = null;
- lastName = null;
- email = null;
- }
-
- public ButtonOperation getButton() {
- return button;
- }
-
- public void setButton(ButtonOperation button) {
- button = button;
- }
-
- public String getFirstName() {
- return firstName;
- }
-
- public String getLastName() {
- return lastName;
- }
-
- public String getEmail() {
- return email;
- }
-
-
- public void setFirstName(String firstName) {
- this.firstName = firstName;
- }
-
- public void setLastName(String lastName) {
- this.lastName = lastName;
- }
-
- public void setEmail(String email) {
- this.email = email;
}
}
}}}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]