Redirect to a page showing a specific object

UPDATE

Since the question itself has changed a bit (it ended up more in the list / dropdown list, I started a new question regarding the data transfer issue : new question


I am trying to write an application where I first have a list of objects and then navigate to a page that only displays one of the objects. Each entity has a list of several other entities (my program has a list of exams, and each exam has a list of questions). Then I click the button to go to the third page where I can fill out the form to create a new attached object.

When saving the attached object, I want to redirect to a second page displaying the same object as before. And that's my problem. The form fields on the page I return to are empty.

Now, when you call the SaveAttachedObject (AttachedObjectAction, "save" method), I am redirected to object.jsp. However, no object is selected and I get the error that I usually get when I click the edit button in objectlist.jsp

and have not selected an object. This message is generated in the validator method ObjectAction

, which usually checks if the object or attached object is null.

I suspect there is no input for the .jsp object.

in my struts.xml I have a SaveAttachedObject action that has an attachObject.jsp input file, so the attached object (including its variable object) must exist. In this, 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 tiles.xml file)

If I add

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

      

for the ShowObject action. I always get the error that "dropdown" cannot be resolved as type collection / array / map / enumeration / iterator:

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 attached Object.jsp file with the select box that is causing the error:

I don't know if I can just give the object (id) the ShowObject action instead of the whole attachObjectForm object?
Or, what I don't understand: why does he want to read the entire list of objectTypes? I just want to use the attached object (only using the selected list item as the new parameter of the attached object).

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

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

ObjectAction: http://pastebin.com/q080N1NB

attachObjectForm: http://pastebin.com/m2HMXHwP

+3


source to share


1 answer


I am not completely following you; +1 for a very nice first question, although probably too verbose. You can add whatever details you want, but you should always condense the real question (expected result, result obtained, problem) into a "one-line" or short sentence (s) separated by all other bunch of details that might be useful for deeper debugging problem.

From what I have, at least one of your problems is that you are filling the list in your method load()

( not reached in case of the result INPUT

returned by the interceptor
). Change with methodprepare()

like this:

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 what your workflow is, but it is.



If you need also exam

filled in the result case INPUT

, then put all the materials of your method load()

in a method prepare()

and make sure you use paramsPrepareParamsStack instead of defaultStack.

You may find that your ObjectAction is no longer needed and put all your activity in a method of prepare()

another activity.

Note that in the code you posted (most likely cleaned up before you posted it) you are missing a recipient for objectTypes

.

+1


source







All Articles