java - Spring MVC form submit: view to controller pass not put form attribute -


i have portlet able display form , allow pass controller in object set user. , works well. want app able set additional attribute jsp not coming input of forms.

the model

public class person {     string firstname;     string middlename;     string attributesetstatically;      // setters , getters      public void setattributesetstatically(string attributefromjsp)     {         system.out.println("call setattributesetstatically  "+attributefromjsp);         this.attributesetstatically=attributefromjsp;     } } 

the controller

@controller(value = "myfirstspringmvcportlet") @requestmapping("view") public class myfirstspringmvcportlet {      @rendermapping     public modelandview handlerenderrequest() {         modelandview modelandview = new modelandview("welcome");         modelandview.addobject("person", new person());         modelandview.addobject("msg", "hello spring mvc");         return modelandview;      }       @actionmapping(value = "handlesubmitperson")     public void submitperson(@modelattribute("person") person person,actionrequest actionrequest, actionresponse actionresponse,model model) {             system.out.println("firstname= "+person.getfirstname());             system.out.println("middlename= "+person.getmiddlename());             system.out.println("attributesetstatically= "+person.getattributesetstatically());     }  } 

view(welcome.jsp)

<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%> <%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %> <h1>${msg}</h1> <portlet:defineobjects /> <portlet:actionurl var="submitformurl" name="handlesubmitperson"/> <form:form name="person" method="post" modelattribute="person" action="<%=submitformurl.tostring() %>"> ${person.setattributesetstatically('attributesetstatically of person')} <br/>     <table style="margin-left:80px">         <tbody>             <tr>                 <td><form:label path="firstname">first name</form:label></td>                 <td><form:input path="firstname"></form:input></td>             </tr>             <tr>                 <td><form:label path="middlename">middle name</form:label></td>                 <td><form:input path="middlename"></form:input></td>             </tr>             <tr>                 <td colspan="2"><input type="submit" value="submit form">                 </td>             </tr>         </tbody>     </table> </form:form> 

the output got result in console is:

firstname= kallel middlename= omar attributesetstatically= null call setattributesetstatically  attributesetstatically of person 

so ${person.setattributesetstatically('attributesetstatically of person')} called after submit. why? there solution want?

the attributesetstatically can set in hidden input inside of form:

<form:input type="hidden" name="attributesetstatically" value="attributesetstatically of person"> 

Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -