重定向到显示特定对象的页面 [英] Redirecting to a page displaying a specific object

查看:106
本文介绍了重定向到显示特定对象的页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

UPDATE



由于问题本身已经发生了一些变化(原来这是更多关于列表/下拉列表的问题,所以我开始了一个关于问题的新问题,数据传递:新问题






我正在尝试编写一个应用程序,首先创建一个对象列表,然后导航到仅显示其中一个对象的页面。其他几个对象列表(在我的程序中列出了一系列考试,每个考试都有一个问题列表),然后按下一个按钮导向第三个页面,我可以填写一个表格来创建一个新的附件对象



保存附加的对象时,我希望被重定向到显示与之前相同的对象的第二页。这是我的问题。我返回的页面上的表单域是空的。



现在,当调用t他SaveAttachedObject行动(AttachedObjectAction,方法保存)我被重定向到object.jsp。但是,没有选择任何对象,并且收到我通常在我点击 objectlist.jsp 中的editbutton并未选择对象时调用的错误消息。这个消息是在 ObjectAction 的validate方法中产生的,它通常会检查object或attachedObject是否为null。



我怀疑,object.jsp的输入丢失。



在我的struts.xml中我有SaveAttachedObject操作,它具有attachedObject。 jsp作为输入,所以attachedObject(包括它的变量对象)应该存在。
因为我调用显示对象的ShowObject动作。

$ p $ < action name =SaveAttachedObjectclass = de.example.project.action.AttachedObjectAction
method =save>
< result name =successtype =redirect> ShowObject.action< / result>
< result type =tilesname =input> attachedObjectForm< / result>
< / action>

method =load>
< result type =tiles> objectForm< / result>
< / action>

(所有图块都在tiles.xml中定义)

如果我添加一个

 < result name =inputtype =tiles> attachedObjectForm< /导致> 

添加到ShowObject动作。我总是收到dropdown-list无法解析为集合/数组/映射/枚举/迭代器类型的错误:

  HTTP状态500  - 包含路径'/layout/mainLayout.jsp'的ServletException。 b 



$ b $ p

code> tag'select',field'list',name'attachedObject.type':请求的列表键'objectTypes'不能被解析为一个collection / array / map / enumeration / iterator类型。示例:people或people。{name} - [unknown location]

这是attachedObject.jsp导致错误的选择字段:

我不知道是否可以将对象(id)赋予ShowObject动作而不是整个attachObjectForm?

或者,我不打扰:为什么它要读取整个objectTypes列表?我只想使用attachedObject(仅将列表中选定的项目用作attachedObject的新参数)。

如果您需要更多代码或信息,请让我知道。



以下是我的项目主要类的相关代码部分:

ObjectAction:< a href =http://pastebin.com/q080N1NB =nofollow noreferrer> http://pastebin.com/q080N1NB

attachedObjectForm : http://pastebin.com/m2HMXHwP

解决方案

我并不完全关注你; +1为一个非常好的第一个问题,但可能过于冗长。你可以添加你想要的所有细节,但是你应该总是将真正的问题(预期结果,获得的结果,问题)缩小到一行或者短句中,的细节可能对问题更深入的调试有用。



从我得到的结果来看,至少有一个问题是您在 load()方法中填充列表(未遇到 INPUT 拦截器返回的结果)。通过使用 prepare()方法更改,如下所示:

  public void prepare()throws Exception {
objectTypes = new ArrayList< String>();
ObjectType [] allTypes = ObjectType.values();
for(ObjectType objectType:allTypes){
objectTypes.add(objectType.toString());
}
}

public String load(){
Long id = 0l;
if(objectId!= null){
id = objectId;
} else if(attachedObject.getObject()!= null){
id = attachtObject.getObject()。getId();
}
if(id ==(long)0){
return ERROR;
} else {
exam = objectService.loadObject(id);
返回SUCCESS;
}
}

我不确定您的工作流程究竟是什么,但这是方式。

如果您还需要在 INPUT c考试 >结果,然后将 load()方法的所有内容放入 prepare()方法中,并确保您正在使用 paramsPrepareParamsStack 而不是 defaultStack

>

您可能发现您的ObjectAction已不再需要,并将其所有业务放在 prepare()另一个动作的方法。



请注意,在发布的代码中(很可能在发布之前将其清除),您缺少 objectTypes


UPDATE

As the question itself has changed a little (this turned out to be more about the list/dropdown list, I started a new question concerning the problem with the data passing: new question


I am trying to write an application where I first have a list of objects, then navigate to a page where only one of the objects is displayed. Each object has a list of several other objects (in my program its a list of exams and each exam has a list of questions). I then press a button to be directed to a third page where I can fill a form to create a new attached object.

When saving the attached Object, I want to be redirected to the second page displaying the same object as before. And this is my problem. The form fields on the page to which I return are empty.

Now, when calling the SaveAttachedObject Action (AttachedObjectAction, method "save") I get redirected to the object.jsp. However, no object is selected and I receive my error message that I usually invoke when I click on the editbutton in objectlist.jsp and have not selected an object. This message is produced in the validate method of the ObjectAction which usually checks if either object or attachedObject is null.

I suspect, the input for the object.jsp is missing.

in my struts.xml I have the SaveAttachedObject action which has the attachedObject.jsp as input, so the attachedObject (including its variable object) should exist. In that I call the ShowObject Action which shows the object.

<action name="SaveAttachedObject" class="de.example.project.action.AttachedObjectAction"
        method="save">
        <result name="success" type="redirect">ShowObject.action</result>
        <result type="tiles" name="input">attachedObjectForm</result>
</action> 

<action name="ShowObject" class="de.example.project.action.ObjectAction"
        method="load">
        <result type="tiles">objectForm</result>
</action>    

(all tiles are defined in the tiles.xml)

If I add an

<result name= "input" type="tiles">attachedObjectForm</result>     

to the ShowObject action. i always receive the error that the "dropdown-list" could not be resolved as a collection/array/map/enumeration/iterator type:

HTTP Status 500 - ServletException including path '/layout/mainLayout.jsp'.

Stacktrace:

tag 'select', field 'list', name 'attachedObject.type': The requested list key 'objectTypes' could not be resolved as a collection/array/map/enumeration/iterator type. Example: people or people.{name} - [unknown location]

Here is the attachedObject.jsp with the select field that causes the error:

I dont know whether I can just give the object(id) to the ShowObject action instead of the whole attachedObjectForm?
Or, which I dont unterstand: why does it want to read the whole objectTypes list? I just want to use the attachedObject (only using the selected item of the list as the new parameter of attachedObject).

If you need any futher code or information, please let me know.

Here are the concerning code parts of the main classes of my project:

ObjectAction: http://pastebin.com/q080N1NB

attachedObjectForm: http://pastebin.com/m2HMXHwP

解决方案

I'm not completely following you; +1 for a very nice first question, though probably excessively verbose. You can add all the details you want, but you should always contract the real question (the expected result, the obtained result, the problem) in a "one-liner", or short sentence(s), separated by all the other bunch of details potentially useful for a more deep debugging of the problem.

From what I've got, at least one of your problems is that you are populating the list in your load() method (not reached in case of INPUT result returned by an Interceptor). Change that by using the prepare() method like follows:

public void prepare() throws Exception{
    objectTypes = new ArrayList<String>();
    ObjectType[] allTypes = ObjectType.values();
    for (ObjectType objectType : allTypes) {
            objectTypes.add(objectType.toString());
    }
}

public String load() {
    Long id = 0l;
    if (objectId != null) {
        id = objectId;
    } else if (attachedObject.getObject() != null) {
        id = attachtObject.getObject().getId();
    }
    if (id == (long) 0) {
        return ERROR;
    } else {
        exam = objectService.loadObject(id);
        return SUCCESS;
    }
}

I'm not sure which your workflow exactly is, but this is the way.

If you need also exam populated in case of INPUT result, then put all the stuff of your load() method in the prepare() method, and ensure you are using the paramsPrepareParamsStack instead of the defaultStack.

You might discover that your ObjectAction is not even needed anymore, and put all its business in a prepare() method of another action.

Note that in the posted code (most likely cleaned up before publishing it), you are missing the getter for objectTypes.

这篇关于重定向到显示特定对象的页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆