
com.viaoa.html.OAForm Maven / Gradle / Ivy
/*
This software and documentation is the confidential and proprietary
information of ViaOA, Inc. ("Confidential Information").
You shall not disclose such Confidential Information and shall use
it only in accordance with the terms of the license agreement you
entered into with ViaOA, Inc..
ViaOA, Inc. MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE, OR NON-INFRINGEMENT. ViaOA, Inc. SHALL NOT BE LIABLE FOR ANY DAMAGES
SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
THIS SOFTWARE OR ITS DERIVATIVES.
Copyright (c) 2001 ViaOA, Inc.
All rights reserved.
*/
package com.viaoa.html;
// response.setHeader("refresh", "1200;URL=Login.jsp");
import java.awt.*;
import java.io.*;
import java.util.*;
import javax.servlet.*;
import com.viaoa.object.*;
import com.viaoa.hub.*;
import com.viaoa.util.OAFile;
/*
processing commands:
1: create an OAHtmlAdapter that implements the processCommand() method
2: form.put("NAME", adapter)
3: use a submit image with the name="oacommand_nameLength_NAME:[ID]" on html page
4: the form will call your processCommand(form, command)
5: your processCommand can return an url to go to or null to keep same
*/
/** Container that represents a HTML Form and holds OAHtmlComponents.
[Java Code]
OAForm form = new OAForm(oaFormId);
form.setName("Expert Edit");
... add OAHtmlComponents ...
....
[HTML Code]
<form method="post" action="<%=form.getAction()%>">
This will set the scrolling postion
<BODY <%=form.getJavaScriptOnLoad()%>>
*/
public class OAForm extends OABase implements Serializable {
private static final long serialVersionUID = 1L;
protected Hashtable hashComponent = new Hashtable(13,0.75f);
protected Vector vecComponent = new Vector(5,5);
protected String url; // jsp name
String status,name;
boolean bFormEnded = true;
// name of last command or subCommand processed.
// This does not include the command prefix "oacommand_NAME_"
protected String lastCommand;
protected transient OAObject lastObject; // last object used. Set by OACommand.processCommand()
protected transient OASession session;
protected transient OAFrame frame; // set by oasession
protected String forwardUrl; // set during processRequest()
protected boolean bNeedsRefreshed;
protected int scrollx, scrolly;
protected boolean readOnly;
protected int top; // y scroll position
protected boolean autoScroll=true, bScroll;
protected String frameName; // set by processRequest, the name of the frame that sent request
protected String targetName; // set by processRequest, the name of the request target
/** @param url name of jsp that this form is used on; must be unique within session
ex: "education.jsp"
*/
public OAForm(String url) {
this.url = url;
if (url == null || url.length() == 0) throw new IllegalArgumentException("OAForm url required");
if (url.indexOf('-') >= 0) throw new IllegalArgumentException("OAForm url can not have any '-' characters");
}
public String getUrl() {
return url;
}
public int getTop() {
return top;
}
public void setTop(int y) {
top = y;
}
/** calls OAFrame.getPreviousUrl() to get the return url. If this form is not yet in a frame, then return
will be null.
@see OAFrame#getPreviousUrl
*/
public String getReturnUrl() {
if (frame == null) return null;
return frame.getPreviousUrl();
}
/** calls OAFrame.setUrlToPrevious(url).
@see OAFrame#setUrlToPrevious
*/
public void setReturnUrl(String url) {
if (frame != null) frame.setUrlToPrevious(url);
}
/** scroll position of upper left corner of window. */
public Point getScrollPosition() {
return new Point(scrollx, scrolly);
}
public void setScrollPosition(Point p) {
if (p != null) {
scrollx = p.x;
scrolly = p.y;
}
}
/** return the frame that this form is currently under. */
public OAFrame getFrame() {
return frame;
}
/** if true then components will not receive data from submit.
Note: commands and listeners are not affected.
*/
public boolean getReadOnly() {
return readOnly;
}
public void setReadOnly(boolean b) {
this.readOnly = b;
}
/** if true then top of form will automatically be scrolled. Default is false.
@see OAForm#getJavaScriptOnLoad
@see OAForm#getTop
*/
public boolean getAutoScroll() {
return autoScroll;
}
public void setAutoScroll(boolean b) {
this.autoScroll = b;
}
/** flag to know if the getEndHtml() has been called. This can be used by a "footer", so
that it can include a "return" img button
*/
public boolean hasFormEnded() {
return bFormEnded;
}
/** set by OAForm.processRequest() and OACommand.processCommand() to store the last
command name or subCommand name processed.
This does not include the command prefix "oacommand_NAME_". This is only needed by
OAForm so that it will know that it is a command to process
*/
public String getLastCommand() {
return lastCommand;
}
public void setLastCommand(String s) {
lastCommand = s;
}
/** set by OACommad.processCommand() */
public OAObject getLastObject() {
return lastObject;
}
public void setLastObject(OAObject obj) {
lastObject = obj;
}
/** automatically turned on when a component is added, and set to false when getAction() is called
*/
public void setNeedsRefreshed(boolean b) {
bNeedsRefreshed = b;
}
public boolean needsRefreshed() {
if (bNeedsRefreshed) return true;
// see if any component needs refreshed
Enumeration enumx = hashComponent.elements();
for ( ; enumx.hasMoreElements(); ) {
OAHtmlComponent oh = (OAHtmlComponent) enumx.nextElement();
if (oh.needsRefreshed()) return true;
}
return false;
}
public String getName() {
return name;
}
public void setName(String s) {
this.name = s;
}
/** resets the form, takes off any edits not saved */
public void reset() {
Enumeration enumx = hashComponent.elements();
for ( ; enumx.hasMoreElements(); ) {
OAHtmlComponent oh = (OAHtmlComponent) enumx.nextElement();
oh.reset();
}
}
/** finds out if any of the values have changed */
public boolean isChanged() {
Enumeration enumx = hashComponent.elements();
for ( ; enumx.hasMoreElements(); ) {
OAHtmlComponent oh = (OAHtmlComponent) enumx.nextElement();
if (oh.isChanged()) return true;
}
return false;
}
/** finds out the name of components that have changed */
public String[] getChanges() {
Vector v = new Vector();
Enumeration enumx = hashComponent.keys();
for ( ; enumx.hasMoreElements(); ) {
String s = ((String) enumx.nextElement());
OAHtmlComponent oc = (OAHtmlComponent)hashComponent.get(s.toUpperCase());
if ( oc.isChanged()) {
v.addElement(s);
}
}
String[] ss = new String[v.size()];
v.copyInto(ss);
return ss;
}
public OAHtmlComponent[] getComponents() {
OAHtmlComponent[] comps = new OAHtmlComponent[hashComponent.size()];
Enumeration enumx = hashComponent.elements();
for (int i=0; enumx.hasMoreElements(); i++) {
comps[i] = (OAHtmlComponent) enumx.nextElement();
}
return comps;
}
/** updates the objects bound to the form */
public void update() {
Enumeration enumx = hashComponent.keys();
for ( ; enumx.hasMoreElements(); ) {
String name = (String) enumx.nextElement();
OAHtmlComponent oh = (OAHtmlComponent) hashComponent.get(name.toUpperCase());
oh.update();
/****
try {
oh.update();
}
catch (Exception e) {
OAException oae = new OAException(OAForm.class, "OAForm.update() component="+name+" "+e.getMessage());
}
**/
}
}
/** returns null if not found
@param name is not case sensitive
*/
public OAHtmlComponent getComponent(String name) {
if (name == null) return null;
return (OAHtmlComponent) hashComponent.get(name.toUpperCase());
}
/**
stores component by name.
@param name is not case sensitive
*/
public void put(String name, OAHtmlComponent obj) {
if (obj == null) return;
if (name == null || name.length() == 0) throw new IllegalArgumentException("OAForm.add() name required");
if (hashComponent.get(name.toUpperCase()) != null) {
String s = "OAForm.add() \""+name+"\" already exists on form - it will be overwritten";
System.out.println(s);
this.addError(s);
}
hashComponent.put(name.toUpperCase(), obj);
obj.form = this;
obj.name = name;
bNeedsRefreshed = true;
vecComponent.addElement(obj);
}
/**
stores component by name.
@param name is not case sensitive
@see OAForm#put
*/
public void add(String name, OAHtmlComponent obj) {
put(name, obj);
}
/**
@param name is not case sensitive
*/
public OARelationshipGrid getRelationshipGrid(String name) {
Object obj = getComponent(name);
if (obj instanceof OARelationshipGrid) return (OARelationshipGrid) obj;
throw new RuntimeException("OAForm.getRelationshipGrid() \""+name+"\" not found");
}
/**
@param name is not case sensitive
*/
public OARadio getRadio(String name) {
Object obj = getComponent(name);
if (obj instanceof OARadio) return (OARadio) obj;
throw new RuntimeException("OAForm.getRadio() Radio \""+name+"\" not found");
}
/**
@param name is not case sensitive
*/
public OACheckBox getCheckBox(String name) {
Object obj = getComponent(name);
if (obj instanceof OACheckBox) return (OACheckBox) obj;
throw new RuntimeException("OAForm.getCheckBox() CheckBox \""+name+"\" not found");
}
/**
@param name is not case sensitive
*/
public OAComboBox getComboBox(String name) {
Object obj = getComponent(name);
if (obj instanceof OAComboBox) return (OAComboBox) obj;
throw new RuntimeException("OAForm.getComboBox() ComboBox \""+name+"\" not found");
}
/**
@param name is not case sensitive
*/
public OAList getList(String name) {
Object obj = getComponent(name);
if (obj instanceof OAList) return (OAList) obj;
throw new RuntimeException("OAForm.getList() List \""+name+"\" not found");
}
/**
@param name is not case sensitive
*/
public OATextArea getTextArea(String name) {
Object obj = getComponent(name);
if (obj instanceof OATextArea) return (OATextArea) obj;
throw new RuntimeException("OAForm.getTextArea() TextArea \""+name+"\" not found");
}
/**
@param name is not case sensitive
*/
public OATree getTree(String name) {
Object obj = getComponent(name);
if (obj instanceof OATree) return (OATree) obj;
throw new RuntimeException("OAForm.getTree() Tree \""+name+"\" not found");
}
/**
@param name is not case sensitive
*/
public OATextField getTextField(String name) {
Object obj = getComponent(name);
if (obj instanceof OATextField) return (OATextField) obj;
throw new RuntimeException("OAForm.getTextField() TextField \""+name+"\" not found");
}
/**
@param name is not case sensitive
*/
public OAPasswordField getPasswordField(String name) {
Object obj = getComponent(name);
if (obj instanceof OAPasswordField) return (OAPasswordField) obj;
throw new RuntimeException("OAForm.getPasswordField() PasswordField \""+name+"\" not found");
}
/**
@param name is not case sensitive
*/
public OATable getTable(String name) {
Object obj = getComponent(name);
if (obj instanceof OATable) return (OATable) obj;
throw new RuntimeException("OAForm.getTable() Table \""+name+"\" not found");
}
public OADataTable getDataTable(String name) {
Object obj = getComponent(name);
if (obj instanceof OADataTable) return (OADataTable) obj;
throw new RuntimeException("OAForm.getDataTable() DataTable \""+name+"\" not found");
}
/**
@param name is not case sensitive
*/
public OACommand getCommand(String name) {
Object obj = getComponent(name);
if (obj instanceof OACommand) return (OACommand) obj;
throw new RuntimeException("OAForm.getCommand() Command \""+name+"\" not found");
}
/**
@param name is not case sensitive
*/
public OATabbedPane getTabbedPane(String name) {
Object obj = getComponent(name);
if (obj instanceof OATabbedPane) return (OATabbedPane) obj;
throw new RuntimeException("OAForm.getTabbedPane() \""+name+"\" not found");
}
/**
@param name is not case sensitive
*/
public OAImage getImage(String name) {
Object obj = getComponent(name);
if (obj instanceof OAImage) return (OAImage) obj;
throw new RuntimeException("OAForm.getImage() name \""+name+"\" not found");
}
/**
@param name is not case sensitive
*/
public OAFileInput getFileInput(String name) {
Object obj = getComponent(name);
if (obj instanceof OAFileInput) return (OAFileInput) obj;
throw new RuntimeException("OAForm.getFileInput() \""+name+"\" not found");
}
/**
@param name is not case sensitive
*/
public OALink getLink(String name) {
Object obj = getComponent(name);
if (obj instanceof OALink) return (OALink) obj;
throw new RuntimeException("OAForm.getLink() Link \""+name+"\" not found");
}
/**
@param name is not case sensitive
*/
public OAToggleButton getToggleButton(String name) {
Object obj = getComponent(name);
if (obj instanceof OAToggleButton) return (OAToggleButton) obj;
throw new RuntimeException("OAForm.getToggleButton() ToggleButton \""+name+"\" not found");
}
/**
@param name is not case sensitive
*/
public OAButtonGroup getButtonGroup(String name) {
Object obj = getComponent(name);
if (obj instanceof OAButtonGroup) return (OAButtonGroup) obj;
throw new RuntimeException("OAForm.getButtonGroup() ButtonGroup \""+name+"\" not found");
}
/**
@param name is not case sensitive
*/
public OALabel getLabel(String name) {
Object obj = getComponent(name);
if (obj instanceof OALabel) return (OALabel) obj;
throw new RuntimeException("OAForm.getLabel() Label \""+name+"\" not found");
}
/** tag to use inside of BODY tag to set the pages top scroll position. */
public String getJavaScriptOnLoad() {
if (top != 0) {
Enumeration enumx = hashComponent.elements();
for ( ; enumx.hasMoreElements(); ) {
OAHtmlComponent oh = (OAHtmlComponent) enumx.nextElement();
if (oh.resetTop()) {
top = 0;
break;
}
}
}
bScroll = true;
if (top != 0) return "onLoad=\"window.scrollTo(0,"+top+");\"";
return "";
}
/** used for supplying needed HTML within a form tag. This will also set "enctype="multipart/form-data""
if the form has any OAFileInput components on it.
Calls all components on the form "getInitScript()" to get any initialization javascript.
Note: this will set OASession.setCurrentForm(this)
ex:
<form method="post" action="<=form.getAction()>">
<form method="post" action="oaform.jsp" enctype="multipart/form-data"><input type="hidden" name="oaform" value="formName">
*/
public String getAction() {
// if (session != null) session.setCurrentForm(this);
bNeedsRefreshed = false;
bFormEnded = false;
String js = "";
/*********
js = "\r\n";
js += "\r\n";
String s = "oaform.jsp\" onSubmit=\"doSubmit();\">"+js+"\r\n\r\n";
js += "function submitOA(cmd) {\r\n";
js += "setOA();";
js += "document.forms[0].action += '?' + cmd + '=1';";
js += "document.forms[0].submit();";
js += "";
js += "}\r\n";
js += "// -->\r\n";
Enumeration enumx = hashComponent.elements();
for ( ; enumx.hasMoreElements(); ) {
OAHtmlComponent oh = (OAHtmlComponent) enumx.nextElement();
String s = oh.getInitScript();
if (s != null) js += s + "\r\n";
}
js += "\r\n";
if (session != null) {
if (session.bSubmitFlag) {
session.bSubmitFlag = false;
if (session.lastForm != null && session.lastForm.forwardUrl != null) {
js += session.getJavaScript(session.lastForm.forwardUrl, false); // 12/15
}
}
}
if (autoScroll && !bScroll) {
js += "";
}
//qqqqqqqqqqqqqqqqqqqqqqvvvvvvvvvvvvvvvvvv sssssssssssssssss
//qqqqqqqqqqqqqqqqqqqqqqvvvvvvvvvvvvvvvvvv
//qqqqqqqqqqqqqqqqqqqqqqvvvvvvvvvvvvvvvvvv
String s2 = "";
enumx = hashComponent.elements();
for ( ; enumx.hasMoreElements(); ) {
OAHtmlComponent oh = (OAHtmlComponent) enumx.nextElement();
// if form has an OAFileInput comp on it, then it will need to be able to get the file and
// parse out the other component name/value pairs
if (oh instanceof OAFileInput) {
s2 = "?oaform="+url+"\"";
s2 += " enctype=\"multipart/form-data";
break;
}
}
/*
© 2015 - 2025 Weber Informatics LLC | Privacy Policy