Struts2 custom form

Source: Internet
Author: User

Custom forms must involve <s: iterator/> iterations. A complex custom form may nest n multi-layer iterations.

For example, a custom survey page involves three models: A survey represents a survey, a page represents a page, and a question represents a problem. Each question contains different form elements and involves iteration.


The three model classes are as follows:

Survey

Package COM. atguigu. surveypark. model; import Java. util. date; import Java. util. hashset; import Java. util. set;/*** investigation class */public class survey {private integer ID; private String title = "Untitled"; private string pretext = "previous "; private string nexttext = "Next"; private string exittext = "exit"; private string donetext = "complete"; private date createtime = new date (); // establish a one-to-one relationship between survey and user private user; // establish a one-to-multiple relationship between survey and page. Private set <page> pages = new hashset <page> (); Public set <page> getpages () {return pages ;} public void setpages (set <page> pages) {This. pages = pages;} public user getuser () {return user;} public void setuser (User user) {This. user = user;} public integer GETID () {return ID;} public void setid (integer ID) {This. id = ID;} Public String gettitle () {return title;} public void settitle (String title) {This. title = title;} Public String getpretext () {return pretext;} public void setpretext (string pretext) {This. pretext = pretext;} Public String getnexttext () {return nexttext;} public void setnexttext (string nexttext) {This. nexttext = nexttext;} Public String getexittext () {return exittext;} public void setexittext (string exittext) {This. exittext = exittext;} Public String getdonetext () {return donetext;} public void setdonetext (string donetext) {This. donetext = donetext;} public date getcreatetime () {return createtime;} public void setcreatetime (date createtime) {This. createtime = createtime ;}}

Page

Package COM. atguigu. surveypark. model; import Java. util. hashset; import Java. util. set;/*** page class */public class page {private integer ID; private String title = "Untitled"; private string description; // The multiple-to-one relationship between the resume from page to survey private survey Survey; // One-to-multiple relationship between the resume from page to question private set <question> Questions = new hashset <> (); Public integer GETID () {return ID ;} public void setid (integer ID) {This. id = ID;} Public String gettitle () {return title;} public void settitle (String title) {This. title = title;} Public String getdescription () {return description;} public void setdescription (string description) {This. description = description;} Public Survey getsurvey () {return survey;} public void setsurvey (survey Survey) {This. survey = survey;} public set <question> getquestions () {return questions;} public void setquestions (set <question> Questions) {This. questions = questions ;}}

Question

Package COM. atguigu. surveypark. model;/*** Question class */public class question {// Private integer ID; // question type 0-8private int questiontype; // Private String title; // option private string options; // other items private Boolean other; // other style items: 0-None 1-text box 2-drop-down list private int otherstyle; // other drop-down options private string otherselectoptions; // The matrix row title set Private string matrixrowtitles; // The matrix column title set Private string matrixcoltitles; // The matrix is the drop-down option set Private string matrixselectoptions; // establish a multiple-to-one association between question and page. Private page; Public integer GETID () {return ID;} public void setid (integer ID) {This. id = ID;} public int getquestiontype () {return questiontype;} public void setquestiontype (INT questiontype) {This. questiontype = questiontype;} Public String gettitle () {return title;} public void settitle (String title) {This. title = title;} Public String getoptions () {return options;} public void setoptions (string options) {This. options = options;} public Boolean isother () {return other;} public void setother (Boolean other) {This. other = Other;} public int getotherstyle () {return otherstyle;} public void setotherstyle (INT otherstyle) {This. otherstyle = otherstyle;} Public String getotherselectoptions () {return otherselectoptions;} public void setotherselectoptions (string otherselectoptions) {This. otherselectoptions = otherselectoptions;} Public String getmatrixrowtitles () {return matrixrowtitles;} public void setmatrixrowtitles (string matrixrowtitles) {This. matrixrowtitles = matrixrowtitles;} Public String getmatrixcoltitles () {return matrixcoltitles;} public void setmatrixcoltitles (string matrixcoltitles) {This. matrixcoltitles = matrixcoltitles;} Public String getmatrixselectoptions () {return matrixselectoptions;} public void setmatrixselectoptions (string matrixselectoptions) {This. matrixselectoptions = matrixselectoptions;} public page getpage () {return page;} public void setpage (page) {This. page = page ;}}


A custom form
<% @ Page Language = "Java" contenttype = "text/html; charset = UTF-8 "%> <% @ taglib uri ="/Struts-tags "prefix =" S "%> <! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en" "http://www.w3.org/TR/html4/loose.dtd"> <HTML> 

Header referenced on the previous page

<% @ Page Language = "Java" contenttype = "text/html; charset = UTF-8 "%> <% @ taglib uri ="/Struts-tags "prefix =" S "%> <Div class =" divouterframe "> <Div class =" divinnerframe"> welcome to the surveydoor survey system! </Div> <Div class = "divwhiteline"> </div> <Div class = "divnavigatorouterframe"> <Div class = "divnavigatorinnerframe"> <s: A action = "loginaction_tologinpage" namespace = "/"> [homepage] </s: A> <s: A action = "surveyaction_newsurvey" namespace = "/"> [Create a survey] </s: A> <s: A action = "surveyaction_mysurveys" namespace = "/"> [my survey] </s: A> [participate in the survey] <s: A action = "regaction_toregpage" namespace = "/"> [User Registration] </s: a> [user authorization management] [role management] [permission management] [log management] </div> <Div class = "divwhiteline"> </div>


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.