Implementing in Struts2

前端 未结 1 1815
一个人的身影
一个人的身影 2021-01-24 02:06

I am currently working with a project, I have multiple select box in my application, each values should change according to the previous value selected in the first list, here i

相关标签:
1条回答
  • 2021-01-24 02:44

    There is a huge mess in your code. Keep in mind that:

    1. Each private property needs a Getter and a Setter (in some cases is possible to avoid them, but unless you know exactly what you are doing, always generate them); specifically, block in your bean and hospitalfloor in your action are missing them.
    2. I don't see your bean property defined anywhere, while in the JSP page you are referencing it several times (bean.state, bean.country etc).
    3. If you need to post something (and since you are posting the value from select1 to populate select2, you need it), you must put your elements inside a form. In the specific case of <sj:select/>, don't put an action attribute in the form itself, because you are already specifying an action url from the href attribute of <sj:select/>s:

      <s:form>
           <!-- stuff -->
           <sj:select ... />
           <!-- stuff -->
           <sj:select ... />
           <!-- stuff -->
      </s:form> 
      
    4. Your topics are not defined anywhere
    5. Your second select topics are recursively notifying the first select. This is wrong.

    The flow should be:

        <sj:select name = "bean.country" 
                   list = "countries" 
                listKey = "id"
              listValue = "description"
                   href = "%{loadCountriesAction}"
                  value = "%{bean.country}"
         onChangeTopics = "reloadState" 
       onCompleteTopics = "reloadState" />
    
        <sj:select name = "bean.state" 
                   list = "states" 
                listKey = "id"
              listValue = "description"
                   href = "%{loadStatesAction}"
                  value = "%{bean.state}" 
           reloadTopics = "reloadState" 
        deferredLoading = "true" />
    
    0 讨论(0)
提交回复
热议问题