簡體   English   中英

如何向 Web 應用程序添加功能,以便多個用戶可以同時使用它

[英]How to add capability to the web-app so that it can be used by multiple users at the same time

我在“zk-framework”中創建了網絡應用程序,如果只有一個用戶正在訪問它,它可以正常工作,但是當其他用戶開始訪問它時,屏幕顯示無法訪問組件。

我不能在這里粘貼整個代碼,所以我在這里給出了主頁的片段。

package in.net.usit.dbu.web.main;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletContext;

import org.zkoss.bind.annotation.AfterCompose;
import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.ContextParam;
import org.zkoss.bind.annotation.ContextType;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Sessions;
import org.zkoss.zk.ui.select.Selectors;
import org.zkoss.zk.ui.select.annotation.Wire;
import org.zkoss.zul.Button;
import org.zkoss.zul.Div;
import org.zkoss.zul.Image;
import org.zkoss.zul.Tabpanels;
import org.zkoss.zul.Tabs;
import org.zkoss.zul.Window;

import in.net.usit.dbu.common.to.dbadapter.DBAdapter;
import in.net.usit.dbu.common.util.DbuConstatns;
import in.net.usit.dbu.common.util.ViewConstatns;
import in.net.usit.dbu.web.dbadapter.DbAdapterModel;
import in.net.usit.dbu.web.framework.WindowManager;

public class MainViewModel {

//Variables
private List<DBAdapter> adapterList;

//
private String selectedAdapterName;
//
private DbAdapterModel adapterModel;
public WindowManager windowmanager;
public DBAdapter selectedAdapterObject;
ServletContext context;

//Wired Variables
@Wire("#mainWindow")
Window mainWindow;
@Wire("#mainDiv")
Div mainDiv;
@Wire("#mainTabs")
Tabs mainTabs;
@Wire("#tabPanels")
Tabpanels tabPanels;
/*@Wire("#btnName")
Button btnName;
@Wire("#btnSrc")
Button btnSrc;
@Wire("#btnDest")
Button btnDest;
@Wire("#btnTrans")
Button btnTrans;
@Wire("#btnExec")
Button btnExec;*/
@Wire("#imgNew")
Image imgNew;
@Wire("#imgSrc")
Image imgSrc;
@Wire("#imgDest")
Image imgDest;
@Wire("#imgTrans")
Image imgTrans;
@Wire("#imgExec")
Image imgExec;

@SuppressWarnings("deprecation")
@AfterCompose
public void init(@ContextParam(ContextType.VIEW) Component view){
    Selectors.wireComponents(view, this, false);
    context = (ServletContext) Sessions.getCurrent().getWebApp().getNativeContext();
    initializeData();   
}

public void initializeData(){       
    windowmanager = new WindowManager(mainWindow, mainTabs, tabPanels);
    mainWindow.getDesktop().setAttribute(ViewConstatns.WiNDOW_MANAGER, windowmanager);
    adapterModel = new DbAdapterModel();
    adapterList = new ArrayList<DBAdapter>();
    adapterList = adapterModel.getDBAList();
    selectedAdapterObject = new DBAdapter();
    WindowManager.tabs.clear();     
    /*context.setAttribute(ViewConstatns.BTN_NEW, btnName);
    context.setAttribute(ViewConstatns.BTN_TRANS, btnTrans);
    context.setAttribute(ViewConstatns.BTN_DEST, btnDest);
    context.setAttribute(ViewConstatns.BTN_SRC, btnSrc);
    context.setAttribute(ViewConstatns.BTN_EXEC, btnExec);*/
    context.setAttribute(ViewConstatns.IMG_NEW, imgNew);
    context.setAttribute(ViewConstatns.IMG_TRANS, imgTrans);
    context.setAttribute(ViewConstatns.IMG_DEST, imgDest);
    context.setAttribute(ViewConstatns.IMG_SRC, imgSrc);
    context.setAttribute(ViewConstatns.IMG_EXEC, imgExec);      
    ((Image) context.getAttribute(ViewConstatns.IMG_NEW)).setSrc("/img/dba1sel.png");

}

@SuppressWarnings("static-access")
@Command
public void onSelectAdapter(){
    mainDiv.setVisible(false);      
    //System.out.println("DBA LIST IS : "+adapterList.toString());
    for(DBAdapter adapter : adapterList){
        //System.out.println(adapter.getDbaName());
        if(adapter.toString().equals(selectedAdapterName)){
            //System.out.println("inside if");
            selectedAdapterObject = adapter;                
        }
    }
    context.setAttribute(DbuConstatns.DBA_OBJECT, selectedAdapterObject);
    //System.out.println("context name is " +selectedAdapterObject.getDbaName() );
    //btnSrc.setDisabled(false);
    windowmanager.createTabComponent(ViewConstatns.SRC_PATH,ViewConstatns.SRC_TAB_NAME);
    ((Image) context.getAttribute(ViewConstatns.IMG_NEW)).setSrc("/img/dba1.png");
    ((Image) context.getAttribute(ViewConstatns.IMG_SRC)).setSrc("/img/dba2sel.png");
    ((Image) context.getAttribute(ViewConstatns.IMG_DEST)).setSrc("/img/dba3.png");
    ((Image) context.getAttribute(ViewConstatns.IMG_TRANS)).setSrc("/img/dba4.png");
    ((Image) context.getAttribute(ViewConstatns.IMG_EXEC)).setSrc("/img/dba5.png");     
}

@SuppressWarnings("static-access")
@Command
public void onClickNewConnection(){
    mainDiv.setVisible(false);
    //btnName.setDisabled(false);
    windowmanager.createTabComponent(ViewConstatns.DB_NEW_PATH,ViewConstatns.DB_TAB_NAME);
}


//setter and getter methods

public List<DBAdapter> getAdapterList() {
    return adapterList;
}
public void setAdapterList(List<DBAdapter> adapterList) {
    this.adapterList = adapterList;
}
public String getSelectedAdapterName() {
    return selectedAdapterName;
}
public void setSelectedAdapterName(String selectedAdapter) {
    this.selectedAdapterName = selectedAdapter;
}



 }

和 main.zul 如下

  <?page title="" contentType="text/html;charset=UTF-8"?>
 <zk>
  <window contentStyle="overflow:auto" id="mainWindow"
    apply="org.zkoss.bind.BindComposer"
    viewModel="@id('vm')          @init('in.net.usit.dbu.web.main.MainViewModel')">
    <div class="wrapper">
        <div class="AppHeader">

            <div class="AppHeaderMenu">
                <div class="master_top_inner divider"></div>
            </div>
        </div>
        <space></space>
        <hlayout>
            <!-- <hbox>
                <image id="imgNew" src="/img/dba1.png" width="80px"
                    height="70px" tooltiptext="DB Adapter Details" />
                <image id="imgSrc" src="/img/dba2.png" width="80px"
                    height="70px" tooltiptext="Source DB Connection" />
                <image id="imgDest" src="/img/dba3.png" width="80px"
                    height="70px" tooltiptext="Destination DB Connection" />
                <image id="imgTrans" src="/img/dba4.png"
                    width="80px" height="70px" tooltiptext="Transformation Rules" />
                <image id="imgExec" src="/img/dba5.png" width="80px"
                    height="70px" tooltiptext="Copying data" />
            </hbox> -->
            <space></space>
            <vbox>                  
                <hbox>
                    <separator height="25px"></separator>

                    <image id="imgNew" src="/img/dba1.png" width="80px"
                    height="70px" tooltiptext="DB Adapter Details" />
                <image id="imgSrc" src="/img/dba2.png" width="80px"
                    height="70px" tooltiptext="Source DB Connection" />
                <image id="imgDest" src="/img/dba3.png" width="80px"
                    height="70px" tooltiptext="Destination DB Connection" />
                <image id="imgTrans" src="/img/dba4.png"
                    width="80px" height="70px" tooltiptext="Transformation Rules" />
                <image id="imgExec" src="/img/dba5.png" width="80px"
                    height="70px" tooltiptext="Copying data" />

                    <!-- <button id="btnName" label=" New Database Adapter" width="310px" height="80px" disabled="true"></button>                   

                    <button id="btnSrc" label="Source Connection Details" width="310px" height="80px" disabled="true"></button>                 

                    <button id="btnDest" label="Destination Connection Details" width="310px" height="80px" disabled="true"></button>

                    <button id="btnTrans" label="Transformation Rules" width="310px" height="80px" disabled="true"></button>

                    <button id="btnExec" label="Generate and Execute Query" width="310px" height="80px" disabled="true"></button>
                    -->
                    </hbox>
                <space></space>
                <div align="center" id="mainDiv" width="100%">
                    <hbox>
                        <label
                            style="font-size:18px; margin-right:10px">
                            Database Adapter :
                        </label>
                        <combobox width="300px"
                            model="@bind(vm.adapterList)"
                            selectedItem="@bind(vm.selectedAdapterName)"
                            onSelect="@command('onSelectAdapter')">
                            <template name="model">
                                <comboitem
                                    label="@bind(each.dbaName)" value="@bind(each.dbaName)">
                                </comboitem>
                            </template>
                        </combobox>
                        <space width="40px" />
                        <button sclass="" label="New Connection"
                            onClick="@command('onClickNewConnection')">
                        </button>
                    </hbox>
                </div>
                <div>
                    <tabbox>
                        <tabs id="mainTabs"></tabs>
                        <tabpanels id="tabPanels"></tabpanels>
                    </tabbox>
                </div>
            </vbox>
            <space></space>
        </hlayout>
    </div>

    <div class="AppFooter">
        <div class="AppFooterInner">

        </div>
    </div>
</window>

我在這里使用 zk 會話類。 謝謝在此處輸入圖片說明

此錯誤來自對不同頁面使用 1 個組件。
給出的最佳示例是向視圖添加靜態組件。
第 1 個人可以看到它,但是第 2 個人和所有其他人都會出現錯誤,因為該組件已經擁有它所屬的桌面。
或者用一個比喻:如果你租車,你可以把車 1 租給人 1。
如果人 2 來了,你不能把車 1 租給那個人,因為它已經用過了,你需要給另一輛車,即使他想要和人 1 一樣的車。

我想你需要看看這個方法:

windowmanager.createTabComponent(ViewConstatns.SRC_PATH,ViewConstatns.SRC_TAB_NAME);

如果 2 個輸入相同,是否有可能返回相同的對象?
如果是 => 那是你的問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM