Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

ActionButton.java

Go to the documentation of this file.
00001 import java.util.Enumeration;
00002 
00003 public class ActionButton extends Widget
00004 {  
00005   int action = 0;
00006   int param = 0;
00007         
00008         public ActionButton(String prefix, Form form)
00009         {
00010           super(prefix, form);
00011         }
00012         
00013         public void loadValues()
00014         {
00015     String s = form.req.getParameter(prefix);
00016     if(s != null && s.length() > 0)
00017       setThisString(s);
00018     else
00019     {
00020       String c = prefix + ".";
00021       int cl = c.length();
00022       
00023       for (Enumeration e = form.req.getParameterNames(); e.hasMoreElements() ;)
00024       {
00025         String n = (String) e.nextElement();
00026         if (n == null) break; 
00027         if (n.length() < cl) continue;       
00028         if (n.substring(0,cl).equals(c))
00029         {
00030           String p = n.substring(cl);
00031           setThisString(p);
00032           break;
00033         }
00034       }
00035     }
00036         }
00037         
00038         protected String getString(int action, int param)
00039         {
00040           String s = Integer.toString(action) +  "_" + Integer.toString(param);
00041           return s;
00042         }
00043         
00044         protected void setThisString(String s)
00045         {
00046           int p = s.lastIndexOf('_');
00047           this.action = Integer.parseInt(s.substring(0,p));
00048           this.param = Integer.parseInt(s.substring(p+1));
00049         }
00050         
00051         public void display(boolean hidden)
00052         {
00053           // actions are not persistent
00054         }
00055         
00056         public void display(String name, int action)
00057         {
00058           display(name, action, 0, "");
00059         }
00060         
00061   public void display(String name, int action, int param)
00062         {
00063           display(name, action, param, "");
00064         }
00065         
00066         public void display(String name, int action, int param, String attribs)
00067         {
00068     String n = this.n(getString(action, param));
00069     p("<input type=submit name=\"" + n + "\" value=\"" + name
00070       + "\"" + attribs + ">");
00071         }
00072         
00073         public String gethref(int action, int param)
00074   {
00075     return "javascript:ActionButton_sgo(" + action + ", " + param + ", '"
00076       + form.name + "', '" + prefix + "');";
00077   }
00078   
00079   public void dumpScript()
00080   {
00081     p(
00082 ""/*"<!-- Begin ActionButton Script -->\n"+
00083 "<script>\n"+
00084 "<!--\n"+
00085 "  function ActionButton_go(action,object,actionobject)\n"+
00086 "  {\n"+
00087 "    //alert(actionobject.name + \" set to '\" + action + \"'\");\n"+
00088 "    actionobject.value = action + '_' + object;\n"+
00089 "    if (actionobject.form.onsubmit) actionobject.form.onsubmit();\n"+
00090 "    actionobject.form.submit();\n"+
00091 "  }\n"+
00092 "\n"+
00093 "  function ActionButton_sgo(action,object,form,actionelement)\n"+
00094 "  {\n"+
00095 "    //alert(document.forms[form][actionelement]);\n"+
00096 "    ActionButton_go(action,object,document.forms[form][actionelement]);\n"+
00097 "  }\n"+
00098 "// -->\n"+
00099 "</script>\n"+
00100 "<!-- End ActionButton Script -->\n"+
00101 ""*/
00102     );
00103   }
00104 };

Generated on Mon Mar 6 23:34:34 2006 by  doxygen 1.4.4