简体   繁体   中英

onchange function using spring roo distribution (gvnix)

I am new to Spring roo( i am using gvnix spring roo distribution for jquery, bootstrap and databale). I have created 3 tables in mysql

CREATE TABLE `categories` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `Category_Name` varchar(50) NOT NULL,
  `Description` varchar(50) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;

insert  into `categories`(`id`,`Category_Name`,`Description`) values (1,'Facility','facility'),(2,'Ikare','Ikare');

CREATE TABLE `subcategories` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `subcategory_name` varchar(50) NOT NULL,
  `category_id` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `FK_md1atoxe8wd8bi2fhf9nnw4q0` (`category_id`),
  CONSTRAINT `FK_md1atoxe8wd8bi2fhf9nnw4q0` FOREIGN KEY (`category_id`) REFERENCES `categories` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;

insert  into `subcategories`(`id`,`subcategory_name`,`category_id`) values (1,'room service',1),(2,'store',1),(3,'server setup',2),(4,'Travel not working',2);

and used database reverse engineering command to create the bean file.

and used the for scaffold,jquery,bootstrap and dattable

now after deploying the app into tomcat7 I am able to create categories, subcategories.

My problem is while creating new service desk, the category is showing in dropdown and all sub category is showing in default. But I want when I select the specific category it should display the respective subcategory but not all subcategory for all category.

and also validation is not working means if I don't enter anything in mandatory field I am able to save the data.

Below is my code for create new service.

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<div xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:field="urn:jsptagdir:/WEB-INF/tags/jquery/form/fields" xmlns:form="urn:jsptagdir:/WEB-INF/tags/datatables" xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:spring="http://www.springframework.org/tags" version="2.0">
    <jsp:directive.page contentType="text/html;charset=UTF-8"/>
    <jsp:output omit-xml-declaration="yes"/>
    <form:create id="fc_com_arat_roo_domain_ServiceDesk" modelAttribute="serviceDesk" path="/servicedesks" render="${empty dependencies}" z="5rY4NJcP8nJ/t0tXbZs8XZLebzs=">
        <field:select field="categoryId" id="c_com_arat_roo_domain_ServiceDesk_categoryId" itemValue="id" items="${categorieses}" path="/categorieses" z="eTrZa7tDsB6IOgAA143b/eECzgs="/>
        <field:select field="subcategoryId" id="c_com_arat_roo_domain_ServiceDesk_subcategoryId" itemValue="id" items="${subcategorieses}" path="/subcategorieses" z="WLOZ5uG2O8vxZDxYu7Gg1q0Zx9w="/>
        <field:input field="comment" id="c_com_arat_roo_domain_ServiceDesk_comment" required="true" z="h/4gHQSwuY162Ci8qehagMY7ZUY="/>
    </form:create>
    <form:dependency dependencies="${dependencies}" id="d_com_arat_roo_domain_ServiceDesk" render="${not empty dependencies}" z="zpBtjtNE7E7oXm/3C5Dw9BagNsM="/>
</div>

and controller is as below:

@RequestMapping(params = "form", produces = "text/html")
    public String createForm(Model uiModel) {
        populateEditForm(uiModel, new ServiceDesk());
        return "servicedesks/create";
    }

void populateEditForm(Model uiModel, ServiceDesk serviceDesk) {
        uiModel.addAttribute("serviceDesk", serviceDesk);
        uiModel.addAttribute("categorieses", Categories.findAllCategorieses());
        uiModel.addAttribute("subcategorieses", Subcategories.findAllSubcategorieses());
    }

and below is the log.roo for command i used.

// Spring Roo 1.3.1.RELEASE [rev 8cb81a3] log opened at 2016-02-06 00:33:13
project --topLevelPackage com.arat.roo --projectName ssd --java 6 --packaging WAR
// Spring Roo 1.3.1.RELEASE [rev 8cb81a3] log closed at 2016-02-06 00:33:15
// Spring Roo 1.3.1.RELEASE [rev 8cb81a3] log opened at 2016-02-06 00:34:16
osgi start --url file:///C:/Users/Arat/.m2/repository/mysql/mysql-connector-java/5.1.20/mysql-connector-java-5.1.20.jar
hint
persistence setup --database MYSQL --provider HIBERNATE --databaseName learning --userName root --password Gayathri/?@123
osgi start --url file:///C:/Users/Arat/.m2/repository/mysql/mysql-connector-java/5.1.20/mysql-connector-java-5.1.20.jar
database introspect --schema no-schema-required
database reverse engineer --schema root --package ~.domain --includeTables "categories subcategories service_desk"
web mvc setup
web mvc all --package ~.web
web mvc jquery setup
web mvc jquery all
web mvc datatables setup
web mvc bootstrap setup
web mvc bootstrap update
web mvc datatables all 
jpa gvnix setup
jpa batch all
web mvc batch setup
web mvc batch all
web mvc datatables detail add --type ~.web.CategoriesController --property subcategorieses
web mvc datatables detail add --type ~.web.ServiceDeskController --property subcategorieses
web mvc datatables detail add --type ~.web.ServiceDeskController --property categorieses

Could you please help me on this?

Take a look to loupe field component . You can show a Datatable to allow select subcategories filtering by its categories.

Good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM