1

I am trying to get values from a form to another form on the submit. As i need to pass info from one page to another using post. However I get null for the object.

here is my code:

form 1

<form:form id="user" modelAttribute="user" method="post" action="">
    <form:input type="text" placeholder="" id="name" path="name" maxLength="10" style="width:150px" />
    <form:input type="text" placeholder="" id="address" path="name" maxLength="32" style="width:150px" />
    <form:input type="text" placeholder="" id="phone" path="phone" maxLength="32" style="width:150px" />        
</form:form>

form 2

<form:form  id="selectRuleforuserForm" action="/myApp/selectRule" enctype="multipart/form-data" modelAttribute="rule" method="post">        
    <form:input type="hidden" name="name" id="major_Version" path="name"/>
    <form:input type="hidden" name="address" id="internal_TradeId" path="adress"/>
    <form:input type="hidden" name="phone" id="reporting_Party" path="phone"/>      
    <input type="submit" id="selectRules" class="ui-widget" value="Select Rules"/>
</form:form >

Javascript

$("#selectRuleforuserForm").submit(function(){

                    var user="${user.name}";
                    var add="${user.adress}";
                    var phone="${user.phone}";


                    $("name").val(user);
                    $("address").val(add);
                    $("phone").val(phone);

 });

Controller:

 @RequestMapping(value="/selectRule",method=RequestMethod.POST)
     public String updateRulesForUserRequest(Rule rule,BindingResult result,Model model,HttpServletRequest request,HttpServletResponse response){
        log.info("Select rules for user: "+rule.toString());


     }

logs:

2016-04-20 18:43:06,646 INFO  administrator - Select rules for user: Rule [name=, address=, phone=], org.springframework.validation.BindingResult.Rule=org.springframework.validation.BeanPropertyBindingResult: 0 errors - com.myApp.RuleController:112
fiddle
  • 1,095
  • 5
  • 18
  • 33

2 Answers2

0

ModelAttribute annotation should be used in method parameter instead of form : see What is Model Attribute

Community
  • 1
  • 1
Dongqing
  • 674
  • 1
  • 5
  • 19
  • tried using this: @ModelAttribute("rule") Rule rule in controller . but that didn't work as well. :( – fiddle Apr 20 '16 at 05:10
0

was missing "#" in :

   $("#name").val(user);
                    $("#address").val(add);
                    $("#phone").val(phone);
fiddle
  • 1,095
  • 5
  • 18
  • 33