Madhusudan Joshi
Madhusudan Joshi

Reputation: 4476

struts 2 action error : retrieves values of form properties

Problem

I am using jsp to submit a form and struts 2 action class takes care of it. If there is some problem, then i am sending the result to same page with an error message.

Along with the error message, i want to display property values that he had provided while submitting the request.

Source code

Form contains few text fields and few file type inputs.

My CreateRequest.jsp file:

<input type="file" name="attachment" id="myFile1" />
<input type="file" name="attachment" id="myFile2" />
<input type="file" name="attachment" id="myFile3" />
<input type="text" name="operationName" id="operation1" />
<input type="text" name="operationName" id="operation2" />
<input type="text" name="operationName" id="operation3" />

My Action class :

public class CreateRequest extends ActionSupport {

private List<File> attachment;

private List<String> attachmentContentType;

private List<String> attachmentFileName;


private List<String> operationName

// contains getter and setter for each property

public string execute(){
    // some logic
    //returns error if it fails otherwise success
}
}

struts.xml (Action Servlet) file:

<action name="createRequest"
        class="action.CreateRequest">
        <result name="success">RequestStatus.jsp
        </result>
        <result name="input" >CreateRequest.jsp</result>
        <result name="error" >CreateRequest.jsp</result>
 </action>

HELP

How do i get all those values displayed in CreateRequest.jsp page, when the action class returns error.

Upvotes: 0

Views: 695

Answers (1)

Pankaj Sharma
Pankaj Sharma

Reputation: 1853

use ognl value=" %{operationName[0]}" for text box

Upvotes: 1

Related Questions