gpt4 book ai didi

java - 我可以在同一个操作中使用多种方法吗?

转载 作者:太空宇宙 更新时间:2023-11-04 11:27:10 24 4
gpt4 key购买 nike

我正在使用 Struts 2 (2.5.10.1) 和 struts2-json-plugin-2.5.10.1。在我的页面上,我有一个使用 ExtJs 4.2.2 的网格,该网格将填充项目,每行将有两个操作:编辑删除

问题是我遇到过:如果我尝试使用同一操作中的多个方法来执行上述所有操作,当我尝试填充网格时,我没有得到任何 JSON 响应。我想做的事情可能吗? (编辑删除功能尚未实现)

这是我的struts.xml:

   <package name="admin" extends="json-default">

<action name="requestProjectData"
class="administrator.ACTION_ProjectsGrid"
method="requestProjectData">
<result type="json" >
<param name="root">projectData</param>
</result>
</action>

<action name="requestDeleteProject"
class="administrator.ACTION_ProjectsGrid"
method="deleteProject">
<result type="json" >
<param name="root">success</param>
</result>
</action>

<action name="requestEditProject"
class="administrator.ACTION_ProjectsGrid"
method="editProject">
<result type="json" >
<param name="root">success</param>
</result>
</action>

这是我的 Action 类:

public class ACTION_ProjectsGrid extends ActionSupport {

private static final long serialVersionUID = 1L;

private List<Project> projectData;
private boolean success;

public void requestProjectData()
{
ProjectManager pm = new ProjectManager();
List<Project> listOfProjects = pm.getAllProjects();
projectData = listOfProjects;
}

public void deleteProject()
{
success = true;
}

public void editProject()
{
success = true;
}

public List<Project> getProjectData() {
return projectData;
}

public void setProjectData(List<Project> projectData) {
this.projectData = projectData;
}

public boolean isSuccess() {
return success;
}

public void setSuccess(boolean success) {
this.success = success;
}

}

还有我的 JSP 页面:

<body>
<script type="text/javascript">
Ext.define('Project', {
extend: 'Ext.data.Model',
fields: [ 'projectId', 'projectName' ]
});

var projStore = Ext.create('Ext.data.Store', {
model: 'Project',
proxy: {
type: 'ajax',
pageParam: false,
startParam: false,
limitParam: false,
noCache: false,
url: 'requestProjectData',
reader: {
type: 'json'
}
},
autoLoad: true
});

Ext.create('Ext.grid.Panel', {
renderTo: Ext.getBody(),
store: projStore,
width: 641,
height: 300,
title: 'Projects',
columns: [
{
text: 'ID',
width: 80,
dataIndex: 'projectId'
},
{
text: 'Project Name',
width: 80,
dataIndex: 'projectName'
},
{
xtype: 'actioncolumn',
width: 80,
items: [{
icon: '${pageContext.request.contextPath}/JavaScript/extjs/resources/user_edit.png',
tooltip: 'Edit',
handler: function(grid, rowIndex, colIndex) {
var rec = grid.getStore().getAt(rowIndex);
Ext.Ajax.request({
url: 'requestDeleteProject',
disableCaching: false,
params: {
projectId: rec.get("projectId").toString(),
},
success: function(response)
{
grid.getStore().load();
}
});
}
}]
}
]
});
</script>
</body>

最佳答案

Ext.Ajax.request({
url: 'requestDeleteProject',
disableCaching: false,
params: {
projectId: rec.get("projectId").toString(),
},
success: function(response){
grid.getStore().load();
}
});}

在您发出请求的那部分中...您应该在成功中解码“响应”,然后将数据加载到您的商店;制作grid.getStore().load()您正在发出另一个您想要的请求,类似于

var json = Ext.decode(response.wtv..); 

然后你想加载网格的存储,例如

grid.getStore().loadData(json); 

很喜欢

success: function(response){
var json = Ext.decode(response.wtv..);
grid.getStore().loadData(json);
}

关于java - 我可以在同一个操作中使用多种方法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44226202/

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