spring mvc - Getting ModelAttribute value in POST request handler -



spring mvc - Getting ModelAttribute value in POST request handler -

i have form bean follows

public class questionpagebean { private string statement; private string options; // getters , setters }

below request handler creates object 'question' , sets field 'statement'. populates list of values shown check-box 'options' field. page displays 'statement' , list of check-boxes.

@requestmapping(value = "/question", method = requestmethod.get) public modelandview initform() { logger.debug("received request show question page"); list<string> optionlist = new arraylist<string>(); modelandview model=new modelandview("question"); questionpagebean question=new questionpagebean(); question.setstatement("this question"); optionlist.add("option1"); optionlist.add("option2"); optionlist.add("option3"); optionlist.add("option4"); model.addobject("optionlist", optionlist); model.addobject("command", question); homecoming model; }

below post method handler page user selects value of 'options' field check boxes , submits form. problem modelattribute 'question' gets value 'options' 'statement' remains null.

how can value of 'statement' field (which set when page loads through method above) in below controller. there spring mvc construct?

@requestmapping(value = "/question", method = requestmethod.post) public void questionformsubmit(@modelattribute("question")questionpagebean question) { logger.debug("question page subimtted"); system.out.println(question.getstatement()); // prints null system.out.println(question.getoptions()); // prints right value selected user }

statement field not populated unless passed form. create hidden field statement within form , should populated.

spring-mvc

Comments

Popular posts from this blog

php - How to pass multiple values from url -

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

database - php search bar when I press submit with nothing in the search bar it shows all the data -