gpt4 book ai didi

java - 如何向网络应用程序添加功能,以便它可以同时被多个用户使用

转载 作者:行者123 更新时间:2023-11-30 10:34:49 25 4
gpt4 key购买 nike

我在 `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 session 类。谢谢enter image description here

最佳答案

此错误来自于将 1 个组件用于不同的页面。
最好的例子是向 View 添加静态组件。
人 1 可以看到它很好,但是人 2 和其他人都会有错误,因为该组件已经有它所属的桌面。
或者打个比喻:如果你租车,你可以把车1租给人1。
如果第 2 个人来了,你不能把汽车 1 租给那个人,因为它已经用过了,你需要再给一个人,即使他想要和第 1 个人一样的车。

我猜你需要看看这个方法:

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

如果两个输入相同,是否可能返回相同的对象?
如果是 => 那是你的问题。

关于java - 如何向网络应用程序添加功能,以便它可以同时被多个用户使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41500583/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com