Struts Iterate Tag with Form Validations

I have a scenario where I have to show some list of configuration items in the updatable listing format. That is the listing contains the configuration Item Name (uneditable display text), Configuration Item (editable text box).

I am getting the list from the database and when user hits save, I have to do some form validations and if valiadtion fails then I have to navigate back to the listing with the error message.

I am getting the configuration Items in the form of ConfigurationVo objects and holding the collection in request scope. In my Jsp I am using <logic:iterate> to loop through the collection and render information as static text or set value in a text field. Now, when user updates some data and clicks "Save" button and if the validation fails, then it is navigating back to the same page but there is nothing being showed in the listing. I guess, it is no more able to find the collection in request scope. When I try to add the collection in session scope I am able to see the listing upon validation error. But, the values are defaulted to the original values but not the one's which user has edited.

I would appreciate of someone could help me in showing the listing with values that user has edited by adding the collection to request scope.

I have also tried using index property of iterate tag. but I guess I not quitely confident in my approach. What is the correct approach of using indexed property?

In summary:
This is what is currently have:
SysConfigAction: Action class that gets the configuration Items from the database. Arraylist of ConfiguartionVO objects
-------------------------------------------
public class ConfigurationVO {

  public void setCode(String code) {
    this.code = code;
  }

  public void setItem(String item) {
    this.item = item;
  }

  public void setValue(String value) {
    this.value = value;
  }

  public void setUserId(String userId) {
    this.userId = userId;
  }

  public void setUserMaintainIndicator(boolean userMaintainIndicator) {
    this.userMaintainIndicator = userMaintainIndicator;
  }

  public String getCode() {
    return code;
  }

  public String getItem() {
    return item;
  }

  public String getValue() {
    return value;
  }

  public String getUserId() {
    return userId;
  }

  public boolean isUserMaintainIndicator() {
    return userMaintainIndicator;
  }
  public ConfigurationVO() {
  }

  private String code;
  private String item;
  private String value;
  private String userId;
  private boolean userMaintainIndicator;
------------------------------------------
SystemConfigForm:
-----------------------------------------
import java.text.*;
import javax.servlet.http.*;

import org.apache.struts.action.*;

/**
 *
 * <p>Title: SystemConfigForm</p>
 * <p>Description: This form is used to hold the values that are enterd by the
 * usr in the System Configuration User Interface.
 * The validate method of this class is used to validate the format of the data
 * that has been keyed by the user.
 * </p>
 * <p>Copyright: Copyright (c) 2004</p>
 * <p>Company: UPS</p>
 * @author Saritha Ventrapragada
 * @version 1.0
 */
public class SystemConfigForm
    extends ActionForm {
  public void setCode(String[] code) {
    this.code = code;
  }

  public void setItem(String[] item) {
    this.item = item;
  }

  public void setValue(String[] value) {
    this.value = value;
  }

  public void setUserMaintainIndicator(boolean[] userMaintainIndicator) {
    this.userMaintainIndicator = userMaintainIndicator;
  }

  public void setMethodToCall(String methodToCall) {
    this.methodToCall = methodToCall;
  }

  public String[] getCode() {
    return code;
  }

  public String[] getItem() {
    return item;
  }

  public String[] getValue() {
    return value;
  }
  public boolean[] getUserMaintainIndicator() {
    return userMaintainIndicator;
  }

  public String getMethodToCall() {
    return methodToCall;
  }

  /*default constructor*/
  public SystemConfigForm() {
  }

  private String[] code;
  private String[] item;
  private boolean[] userMaintainIndicator;

  private String methodToCall;

  public ActionErrors validate(ActionMapping mapping,
                         HttpServletRequest request) {
    ActionErrors errors = new ActionErrors();
    ActionError ae = null;
    int i = 0;
    try {

      for (i = 0; i < value.length; i++) {
      /*checking if the value of the configuration item is zero or empty*/
      if (value[i] == null) {
        ae = new ActionError(Constants.ERROR_FORM_TEXT_VALIDATION, value[i],
                         item[i]);
        errors.add(Constants.FORM_VALIDATION, ae);
      }
      else if ((Integer.parseInt(value[i])) < 1) {
        ae = new ActionError(Constants.ERROR_FORM_TEXT_VALIDATION, value[i],
                         item[i]);
        errors.add(Constants.FORM_VALIDATION, ae);
      }
      }
    }catch (Exception e) {
      logger.fatal("1000", e);
      ae = new ActionError(Constants.ERROR);
    }
    return errors;
  }
}
-----------------------------------------
SystemConfigAction
----------------------------------------
    SystemConfigSL scl = new SystemConfigSL();
      ConfigurationVO cfgvo = null;

      ArrayList sysConfig = scl.getConfig();
      (request.getSession()).setAttribute("sysConfig",sysConfig);
-----------------------------------------

Can you please help me in solving my problem. I should be able to show the user with the values he have updated on error conditions.

Thank you
vsaritha_9Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

vsaritha_9Author Commented:
seems no one knows solution to my problem or atleast knows approach to solve it
0
bloodredsunCommented:
Switch your validation from the frame work to the action e.g. set validation to false in the config and in the action call

ActionErrors ae = ( (ActionForm) form ).validate();

If ae != null, it has failed validation so you can forward back to the jsp but you can resave the collection in the request again and then forward.
0
bloodredsunCommented:
Did my recommendation work? Or do you need an example?
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

vsaritha_9Author Commented:
Hello,
I really appreciate your response.

I guess even if I call validate from Action class, I will not have my list in my request scope as a new request will be started when user clicks on some button.

Thank you
0
bloodredsunCommented:
Yes. In that case you may wish to put the list in the session scope for viewing over multiple pages.
0
vsaritha_9Author Commented:
And also I need to update the collection with the values that user has updated. Which I am currently doing. But I am not sure if this is the correct approach.

I was thinking of using indexed property and loop through the collection. But I am not sure how this can be acheived.
0
bloodredsunCommented:
An ArrayList or other datastruture would be fine for you. Arraylist is good as it implements the Collections interface as well as List

All you do if do a quick check for updated values and if so, enter them into the object stored in session and that's it.

as for looping over a structure, here's a fragment

         ArrayList employees = new ArrayList();
         employees.add("Fred");
         employees.add("Jen");
         employees.add("Henry");
         for(Iterator iter = employees.iterator(); iter.hasNext();) {
           String emp = (String)iter.next();
           System.out.println(emp);
         }
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.