我有一个大的“订单表单” Xpage,显示99行,每行有3个文本输入框。为了捕获更改,我已在每个输入框的“ on Change”事件中呼叫对SSJS函数的调用。调用只需发送产品ID,更改的类型(哪个列)和数量。然后,SSJS函数将这些更改保留在SessionsCope变量(Java.util.hashmap)中。没有与变更相关的刷新。

当用户单击“提交”按钮时,将对更改进行处理。那是另一个SSJS函数,它简单地写入后端多米诺数据库的所有更改。

这一切似乎都很好,已经做了几年。但是,看来我的用户对应用程序的效率变得过于高效,并且输入的速度比它可以跟上的快。

我的调试代码将每个更改都写入服务器的控制台,我可以看到如果用户快速连续更改,则简单地忽略了某些更改(他们只是在输入框之间进行选项卡)。几乎好像服务器忙于处理先前的更改,然后跳过一个更改以移到另一个更改。有时,遗漏了整个更改,然后在可能的情况下进行了备份。

我是否使用错误的技术来捕获更改?我可以做些什么来确保申请每次启动Onchange事件?

我已经使用IE8/9&FF24对此进行了测试。我已经查看了其他建议使用“ onkeyup”事件的帖子。我认为在我的情况下这不起作用,因为用户可能会订购两位数的数量。

任何/所有建议都将不胜感激!

有帮助吗?

解决方案

特里,您需要重新审视架构。如果在提交时处理更新,那么为什么不愿将它们单独发送到服务器 - 正如蒂姆(Tim)很好地指出的那样。我会做什么:

  • 创建2个Java类:一个“订单”一个“ lineItem”
  • 让订单类实现地图接口地图
  • 将订单类用于重复控制(它将为您提供每个LineItem的键,作为重复变量)
  • 将重复中的字段绑定到订单[retoke] .fieldName
  • 在对象数据源中使用订单
  • 在订单类中实现保存方法,并在对象数据源的保存方法中调用它

非常划算,让我知道您是否需要我详细说明。 Java Collections框架是您的朋友。

它比看起来容易:

   public class LineItem {

private String unid;
private String partno;
private int quantity;
private long unitprice;

/**
 * Constructor for new items
 */
public LineItem() {
    this.unid = null;
}

/**
 * Constructor for existing items
 */
public LineItem(Document doc) {
    this.unid = doc.getUniversalId();
    // more here
}


/**
 * @return the unid
 */
public String getUnid() {
    return this.unid;
}

/**
 * @return the partno
 */
public String getPartno() {
    return this.partno;
}
/**
 * @param partno the partno to set
 */
public void setPartno(String partno) {
    this.partno = partno;
}
/**
 * @return the quantity
 */
public int getQuantity() {
    return this.quantity;
}
/**
 * @param quantity the quantity to set
 */
public void setQuantity(int quantity) {
    this.quantity = quantity;
}
/**
 * @return the unitprice
 */
public long getUnitprice() {
    return this.unitprice;
}
/**
 * @param unitprice the unitprice to set
 */
public void setUnitprice(long unitprice) {
    this.unitprice = unitprice;
}

public void save(Database db) {
    Document doc = null;
    if (this.unid == null) {
        doc = db.createDocument();
        doc.replaceItem("Form", "LineItem");
    }
    doc.replaceItem("PartNo", this.partno);
    // More here
    doc.save();
}
}

对于订单 - 假设您从文档集合中加载。

public class Order implements Map<String, LineItem> {

// You might want to have a stack here to keep order
private final Map<String, LineItem> backingMap          = new LinkedHashMap<String, LineItem>();
private final Set<String>           deletedItemKeys     = new HashSet<String>();

// The key we use for new items when unid is null
private int                         lastNewItemNumber   = 0;

@Override
public int size() {
    return this.backingMap.size();
}

@Override
public boolean isEmpty() {
    return this.backingMap.isEmpty();
}

@Override
public boolean containsKey(Object key) {
    return this.backingMap.containsKey(key);
}

@Override
public boolean containsValue(Object value) {
    return this.backingMap.containsValue(value);
}

@Override
public LineItem get(Object key) {
    return this.backingMap.get(key);
}

@Override
public LineItem put(String key, LineItem value) {
    // Here it gets a little special
    // We need to prevent null keys
    if (key == null) {
        key = String.valueOf(this.lastNewItemNumber);
        lastNewItemNumber++;
    }
    this.deletedItemKeys.remove(key);
    return this.backingMap.put(key, value);
}

@Override
public LineItem remove(Object key) {
    this.deletedItemKeys.add(key.toString());
    return this.backingMap.remove(key);
}

@Override
public void putAll(Map<? extends String, ? extends LineItem> m) {
    for (Map.Entry<? extends String, ? extends LineItem> me : m.entrySet()) {
        this.put(me.getKey(), me.getValue());
    }
}

@Override
public void clear() {
    this.deletedItemKeys.addAll(this.backingMap.keySet());
    this.backingMap.clear();
}

@Override
public Set<String> keySet() {
    return this.backingMap.keySet();
}

@Override
public Collection<LineItem> values() {
    return this.backingMap.values();
}

@Override
public Set<java.util.Map.Entry<String, LineItem>> entrySet() {
    return this.backingMap.entrySet();
}

public void load(NotesDocumentCollection dc) throws NotesException {
    Document doc = dc.getFirstDocument();
    Document nextDoc;
    while (doc != null) {
        nextDoc = dc.getNextDocument(doc);
        LineItem li = new LineItem(doc);
        this.put(doc.getUniversalId(), li);
        doc.recycle();
        doc = nextDoc;
    }

    doc.recyle();
}

public void save(Database db) {
    for (LineItem item : this.backingMap.values()) {
        item.save(db);
    }

    // Now kill the left overs - needs error handling
    for (String morituri : this.deletedItemKeys) {
        Document delDoc = db.getDocumentByUnid(morituri);
        if (delDoc != null) {
            delDoc.remove(true);
        }
    }       
}
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top