facebook

How to modify Scaffold generated java code and JSP?

  1. MyEclipse IDE
  2.  > 
  3. Spring Development
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #345525 Reply

    cidy.long
    Member

    Actually, this is a quite popular question who is doing developing with Spring Hibernate applications.

    I just generated a set of application code tables maintenance UI from DB. I found there is no way to specify a DB table column to generate a drop down list from data type enum. It was matched input text field instead of drop down list.

    I tried to add some Mapped linked list from controller, and change form:input to form:select style in my generated jsp. I save it and redeploy application in internal embedded Tomcat server, it was take any effective, the UI is still save UI. Not reflect to any change. I tried to rebuild the application and export it to external Tomcat server. The application made my external Tomcat server crashed.

    Where is my wrong point, please point a direction to me to do the code modification on system generated code.

    Merry Christmas and Happy New Year!

    #345538 Reply

    cidy.long,

    In the JSP, you need to change the widgetType to “dijit.form.Select” instead of “dijit.form.ValidationTextBox” in the script tag which is under the <form:select tag. In the controller class, you need to add the list object to ModelAndView.

    For example, create a Web project and scaffold with Customer table (Derby database). In the CustomerController.java file, modify the editCustomer method with the following code

    public ModelAndView editCustomer(@RequestParam Integer customernumberKey) {
    ModelAndView mav = new ModelAndView();
    String[] state = new String[3];
    state[0] = “AP”;
    state[1] = “MP”;
    state[2] = “UP”;
    mav.addObject(“State”,state);
    mav.addObject(“customer”, customerDAO.findCustomerByPrimaryKey(customernumberKey));
    mav.setViewName(“customer/editCustomer.jsp”);

    return mav;
    }

    Then open the editCustomer.jsp file, modify the current_state code with the following :

    <form:select id=”customer_state” path=”state” cssStyle=”width:300px;”>
    <form:option value=”-1″ label=”—- Please Select —–” />
    <form:options items=”${State}”></form:options>
    </form:select>
    <script type=”text/javascript”>Spring.addDecoration(new Spring.ElementDecoration({elementId : “customer_state”,widgetType : “dijit.form.Select”,widgetAttrs : {promptMessage: “<fmt:message key=”customer.state.help”/>”}})); </script>

    After doing the above changes, redeploy the application and click on Edit Customer, you will get the edit Customer UI as shown in the below screenshot.

    Let us know how it works for you.

    #345556 Reply

    cidy.long
    Member

    Thank you Sir! It works for me.

    #345579 Reply

    cidy.long,

    Glad that you got it working.
    Do let us know if you see any issues in MyEclipse.

    #345737 Reply

    cidy.long
    Member

    Actually. I am doing a form submit with my eclipse for Spring 2014.

    There are about 14 fields need to be filled when I do a payment record for a customer payment. As most information already in the system, I don’t want to fill up everything from scratch again and again.

    The basic idea is, when I new payment record, system will generate a payment sequence number and then pop on a drop down list to show every custom in the system. I pick up one custom from the list (who is the payer). I need a short javascript code from here to listen on this field change, if the field value changed, javascript will trigger a submit action to submit the payment ID and Customer ID to my controller, the controller will based on submitted info to get lots more information from the record to shows what’s customer past payment looks like, and then I just change some value and press save button to submit whole payment, the system will save the new payment record.

    This is some ting like two steps submit, first step submit is a filter and auto filler without any button pressing. Last step will press save button to call save service to save the value.

    I have some code in my JSP like this:

    <form:select id=”payment_payerId” path=”payerId” cssStyle=”width:300px;”>
    <form:option value=”-1″ label=”—- Please Select —–” />
    <form:options items=”${AvailableUserList}”></form:options>
    </form:select>
    <script type=”text/javascript”>Spring.addDecoration(new Spring.ElementDecoration({elementId : “payment_payerId”,widgetType : “dijit.form.Select”,widgetAttrs : {promptMessage: “<fmt:message key=”payment.payerid.help”/>”}})); </script>
    last paragraph javascript is used to decoration the UI, I need some help to change this to call my controller method in my controller class as:

    @RequestMapping(“/autoFillPayment”)
    public ModelAndView autoFillPayment(@RequestParam String paymentIdKey, String payerID) {
    ModelAndView mav = new ModelAndView();
    /*add object to generate drop down list in UI*/
    /*String pisequence=getPaymentIDSequence(thsssequenceDAO);*/
    mav.addObject(“PISequence”,paymentIdKey);
    mav.addObject(“PayerID”, payerID);
    payername=getPayerNamebyCustomerID(customersDAO, payerID);
    mav.addObject(“PayerName”,payername);
    /*Map<String, String> availableUserList = getAvailableUserList(customersDAO);
    mav.addObject(“AvailableUserList”, availableUserList);*/
    /*End of adding*/
    mav.addObject(“payment”, new Payment());
    mav.addObject(“newFlag”, true);
    mav.setViewName(“payment/editAutoFillPayment.jsp”);

    return mav;
    }
    Any suggestion and help with many thanks!

    Happy New Year! GUYS!

Viewing 5 posts - 1 through 5 (of 5 total)
Reply To: How to modify Scaffold generated java code and JSP?

You must be logged in to post in the forum log in