2

I have looked over the previous posts in here on this and I can't seem to find my issue with how it is setup. My control does populate on initial load but not on failed validations. If I go to the index page it loads fine, if I go to the action defined in the struts xml file it is fine. The only problem is after validation reloading.

relevation pieces from jsp file.

<s:form action="CreateReq" method="post" validation="true" theme="simple">
    <s:select name="measurementList" 
              list="measurementList" 
              listKey="Name" listValue="Id" 
              class="quantitydropdown">
    </s:select>
</s:form>

validation class

@Override
public void prepare(){
    prepareRequisitionInformation();
}



public String prepareRequisitionInformation(){
        PrepareCreateRequisitionAction prepare = new PrepareCreateRequisitionAction();
        setMeasurementList(prepare.getMeasurementList());
        loadAwaitingRequisitions();

        return success;
    }

PrepareCreateRequisitionAction class

public ArrayList<Measurement> getMeasurementList() {
    if (measurementList==null || measurementList.isEmpty()){
    this.createMeasurementList();   
    }

    return measurementList;
}

private void createMeasurementList() {
measurementList = new ArrayList<Measurement>();

measurementList.add(new Measurement("Bag", "Bag"));
measurementList.add(new Measurement("Box", "Box"));
measurementList.add(new Measurement("Cubic decimeter", "Cubic decimeter"));
}

index.jsp

<head>
<META HTTP-EQUIV="Refresh" CONTENT="0;URL=CreateReq.action">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>HTML 5 with Struts 2</title>
</head>

struts.xml

<action name="CreateReq" method="execute" class="com.te.sss.action.CreateRequisitionAction">
  <result name="success">/success.jsp</result>
  <result name="input">/createRequisition.jsp</result>
</action>
Pratik Shah
  • 1,782
  • 1
  • 15
  • 33
  • Does the action `implement Prepareable`? Things like that matter. Also, don't specify the `execute` method; it's the default. – Dave Newton Nov 08 '13 at 19:04
  • Yes it does implement Preparable. I specified execute because I am going to change it in the future since it will have multiple actions. – Ken Leiphart Nov 08 '13 at 19:34
  • Please create a minimally-failing example and put it on github. That's pretty hard to follow, btw; instantiating an action just to get some service-level functionality is pretty unusual, as is returning a value from a `prepareXxx` method. – Dave Newton Nov 08 '13 at 19:56
  • My apologies, I should have done this first. I really didn't think my post would get this long until after I was almost done. https://github.com/antibound/struts2tests – Ken Leiphart Nov 08 '13 at 20:54
  • Code seems fine, although the design is not good as Dave suggested. 1. `loadAwaitingRequisitions()` what does this method do ? 2. Enable struts2 devMode to see more logs. – coding_idiot Nov 09 '13 at 02:55
  • It is just another method to load an object with data I need for my jsp. Its not in the git example. I will try devMode. – Ken Leiphart Nov 09 '13 at 03:58
  • @KenLeiphart Do you have any troubles with displaying dropdowns? – Roman C Nov 09 '13 at 10:13
  • Its the repopulation that isn't working. The git code is simpled down from my actual project. It loads the dropdown fine on first load. I use the prepare statement and implement preparable so I am unsure what it is doing. – Ken Leiphart Nov 09 '13 at 19:19

1 Answers1

0
  1. In web.xml, you are using FilterDispatcher, that is deprecated. You need to use StrutsPrepareAndExecuteFilter
  2. In your struts.xml (on the github project) the only result handled is input. Here instead you have written the rule for success result too. If the real code is the one on github, your code would work only in case of failed validation... check your settings carefully.

Note that you don't need to instantiate another Action from within your Action; use a Pojo for that.

Community
  • 1
  • 1
Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
  • I do have that filter in the real app. I made the change though just to make sure and it didn't affect the behavior. Also the app on git is not the real app, Dave asked for a minimally failing one so I pulled out what wasn't needed. – Ken Leiphart Nov 11 '13 at 13:23