📄 wfieldupdate.java
字号:
/******************************************************************************
* The contents of this file are subject to the Compiere License Version 1.1
* ("License"); You may not use this file except in compliance with the License
* You may obtain a copy of the License at http://www.compiere.org/license.html
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
* The Original Code is Compiere ERP & CRM Business Solution
* The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
* Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
* created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
* Contributor(s): ______________________________________.
*****************************************************************************/
package org.compiere.www;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.sql.*;
//import org.apache.ecs.*;
import org.apache.ecs.xhtml.*;
import org.compiere.util.*;
import org.compiere.model.*;
/**
* Dynamic Field Updates
*
* @author Jorg Janke
* @version $Id: WFieldUpdate.java,v 1.2 2002/11/11 07:03:37 jjanke Exp $
*/
public class WFieldUpdate extends HttpServlet
{
/**
* Initialize global variables
* @param config
* @throws ServletException
*/
public void init(ServletConfig config) throws ServletException
{
super.init(config);
if (!WEnv.initWeb(config))
throw new ServletException("WFieldUpdate.init");
} // init
/**
* Clean up resources
*/
public void destroy()
{
} // destroy
private static final String FORM_NAME = "fieldUpdate";
//
private static final String FIELD_FORM = "formName";
private static final String FIELD_NAME = "fieldName";
private static final String FIELD_VALUE = "fieldValue";
/**
* Process the HTTP Get request
* @param request
* @param response
* @throws ServletException
* @throws IOException
*/
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
doPost(request, response);
} // doPost
/**
* Process the HTTP Post request
* @param request
* @param response
* @throws ServletException
* @throws IOException
*/
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
Log.trace(Log.l1_User, "WFieldUpdate.doPost");
// Get Session Info
HttpSession sess = request.getSession();
Properties ctx = (Properties)sess.getAttribute(WEnv.SA_CONTEXT);
WWindowStatus ws = (WWindowStatus)sess.getAttribute(WEnv.SA_WINDOW);
if (sess == null || ctx == null) // ws can be null for Login
;
// Get Parameter
String formName = request.getParameter(FIELD_FORM);
String fieldName = request.getParameter(FIELD_NAME);
String fieldValue = request.getParameter(FIELD_VALUE);
// Document
WDoc doc = WDoc.create (true);
body body = doc.getBody();
// The Reply
createReply (body, ctx, ws, formName, fieldName, fieldValue);
// The Form
form fu = new form(request.getRequestURI(), form.post);
fu.setName(FORM_NAME);
fu.addElement(new input(input.hidden, FIELD_FORM, "y"));
fu.addElement(new input(input.hidden, FIELD_NAME, "y"));
fu.addElement(new input(input.hidden, FIELD_VALUE, "y"));
body.addElement(fu);
// Log.trace(Log.l1_User, "WFieldUpdate=" + doc.toString());
// Answer
WUtil.createResponse (request, response, this, null, doc, false);
} // doPost
/**
* Create Reply.
* <p>
* Including special handling of login pages
* @param body
* @param ctx
* @param ws
* @param formName
* @param fieldName
* @param fieldValue
*/
private static void createReply (body body, Properties ctx, WWindowStatus ws,
String formName, String fieldName, String fieldValue)
{
StringBuffer sb = new StringBuffer (FIELD_FORM);
sb.append("=").append(formName).append(", ")
.append(FIELD_NAME).append("=").append(fieldName).append(", ")
.append(FIELD_VALUE).append("=").append(fieldValue);
Log.trace(Log.l3_Util, "WFieldUpdate.createReply", sb.toString());
// Info
body.addElement(new p().addElement(sb.toString()));
// Called manually - do nothing
if (formName == null || fieldName == null)
;
//
else if (formName.equals("Login2") && fieldName.equals(WLogin.P_ROLE))
reply_Login2_Role (body, ctx, formName, fieldValue);
//
else if (formName.equals("Login2") && fieldName.equals(WLogin.P_CLIENT))
reply_Login2_Client (body, ctx, formName, fieldValue);
} // getReply
/**
* Login 2nd page Response - Field Role.
* <p>
* fill Client, Org, Warehouse
* @param body
* @param ctx
* @param formName
* @param fieldValue
*/
private static void reply_Login2_Role (body body, Properties ctx, String formName, String fieldValue)
{
// Formname
String form = "top." + WEnv.TARGET_WINDOW + ".document." + formName + ".";
// Get Data
KeyNamePair[] clients = DB.loadClients(ctx, new KeyNamePair(Integer.parseInt(fieldValue) , fieldValue));
// Set Client ----
StringBuffer script = new StringBuffer ();
// var A=top.WWindow.document.formName.selectName.options;
script.append("var A=").append(form).append(WLogin.P_CLIENT).append(".options; ");
// A.length=0; // resets options
script.append("A.length=0; ");
// A[0]=new Option('text','value'); // add new oprtion
for (int i = 0; i < clients.length; i++)
{
KeyNamePair p = clients[i];
script.append("A[").append(i).append("]=new Option('");
script.append(p.getName()); // text
script.append("','");
script.append(p.getKey()); // value
script.append("'); ");
}
script.append("\n");
// Set Organization ----
if (clients.length > 0)
{
// var A=top.WWindow.document.formName.selectName.options;
script.append("var B=").append(form).append(WLogin.P_ORG).append(".options; ");
// A.length=0; // resets options
script.append("B.length=0; ");
// A[0]=new Option('text','value'); // add new oprtion
KeyNamePair[] orgs = DB.loadOrgs(ctx, clients[0]);
for (int i = 0; i < orgs.length; i++)
{
KeyNamePair p = orgs[i];
script.append("B[").append(i).append("]=new Option('");
script.append(p.getName()); // text
script.append("','");
script.append(p.getKey()); // value
script.append("'); ");
}
script.append("\n");
}
// Set Warehouse ----
if (clients.length > 0)
{
// var A=top.WWindow.document.formName.selectName.options;
script.append("var C=").append(form).append(WLogin.P_WAREHOUSE).append(".options; ");
// A.length=0; // resets options
script.append("C.length=0; ");
// A[0]=new Option('text','value'); // add new oprtion
KeyNamePair[] whs = DB.loadWarehouses(ctx, clients[0]);
if (whs != null)
{
for (int i = 0; i < whs.length; i++)
{
KeyNamePair p = whs[i];
script.append("C[").append(i).append("]=new Option('");
script.append(p.getName()); // text
script.append("','");
script.append(p.getKey()); // value
script.append("'); ");
}
}
}
// add script
body.addElement(new p().addElement(WLogin.P_CLIENT + "="));
body.addElement(new script(script.toString()));
// Log.trace(Log.l6_Database, "reply_Login2_Role - Script=" + script.toString());
} // reply_Login2_Role
/**
* Login 2nd page Response - Field Client.
* <p>
* fill Org & Warehouse -
* @param body
* @param ctx
* @param formName
* @param fieldValue
*/
private static void reply_Login2_Client (body body, Properties ctx, String formName, String fieldValue)
{
// Formname
String form = "top." + WEnv.TARGET_WINDOW + ".document." + formName + ".";
StringBuffer script = new StringBuffer ();
// Set Organization ----
// var A=top.WWindow.document.formName.selectName.options;
script.append("var B=").append(form).append(WLogin.P_ORG).append(".options; ");
// A.length=0; // resets options
script.append("B.length=0; ");
// A[0]=new Option('text','value'); // add new oprtion
KeyNamePair client = new KeyNamePair(Integer.parseInt(fieldValue), fieldValue);
KeyNamePair[] orgs = DB.loadOrgs(ctx, client);
for (int i = 0; i < orgs.length; i++)
{
KeyNamePair p = orgs[i];
script.append("B[").append(i).append("]=new Option('");
script.append(p.getName()); // text
script.append("','");
script.append(p.getKey()); // value
script.append("'); ");
}
script.append("\n");
// Set Warehouse ----
// var A=top.WWindow.document.formName.selectName.options;
script.append("var C=").append(form).append(WLogin.P_WAREHOUSE).append(".options; ");
// A.length=0; // resets options
script.append("C.length=0; ");
// A[0]=new Option('text','value'); // add new oprtion
KeyNamePair[] whs = DB.loadWarehouses(ctx, client);
if (whs != null)
{
for (int i = 0; i < whs.length; i++)
{
KeyNamePair p = whs[i];
script.append("C[").append(i).append("]=new Option('");
script.append(p.getName()); // text
script.append("','");
script.append(p.getKey()); // value
script.append("'); ");
}
}
// add script
body.addElement(new p().addElement(WLogin.P_WAREHOUSE + "="));
body.addElement(new script(script.toString()));
// Log.trace(Log.l6_Database, "Login2-Client - Script=" + script.toString());
} // reply_Login2_Client
} // WFieldUpdate
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -