Coder Social home page Coder Social logo

spring-guides / gs-handling-form-submission Goto Github PK

View Code? Open in Web Editor NEW
45.0 21.0 85.0 1.31 MB

Handling Form Submission :: Learn how to create and submit a web form with Spring.

Home Page: https://spring.io/guides/gs/handling-form-submission/

License: Apache License 2.0

Java 80.13% HTML 19.87%

gs-handling-form-submission's Issues

unable to call web application from the spring boot to send params through url.

I am try to using Angularjs2 with spring boot application every thing working fine with the small issue.

Description:

step1. if we have default router like router('') meaning localhost:8080/ it is calling index.html page with out having issues.

step2. if we have added context path like router('accountsummary') meaning localhost:8080/accountsummary its not working. when i give like below configuration in spring boot conf like below:

@configuration
public class WebController extends WebMvcConfigurerAdapter{
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/accountSummary").setViewName("index.html");
}
}

it was working fine.

  1. when i want to configure like route('accountsummary/:reqid). reqid is the parameter meaning i want to call like localhost:8080/accountsummary/abc it is not working. i have given like (/**)

@configuration
public class WebController extends WebMvcConfigurerAdapter{
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/accountSummary/**").setViewName("index.html");
}
}

its not working and giving like below:

Whitelabel Error Page

This application has no explicit mapping for /error, so you are seeing this as a fallback.

Thu Jun 30 15:11:38 EDT 2016
There was an unexpected error (type=Not Found, status=404).
No message available

Can any one pleae help me out

Conflict with Thymeleaf's th:insert

This isn't a "bug" with this tutorial per-se, but rather a gotcha that I was trying to solve which led me to this tutorial in an effort to figure out what I was doing wrong. If this should not be recorded here, please suggest another place to put it.

Problem: Certain Thymeleaf expressions seem to cause the page to only partially load.
Solution: Add the following to the application configuration (ie: application.properties")
spring.thymeleaf.servlet.produce-partial-output-while-processing=false

In my case, my template was taking advantage of the th:replace and th:insert attributes.

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="https://www.thymeleaf.org">

  <head th:replace="~{'fragments/headTagFragment'}"><title>Will Be Replaced</title></head>
  <body>
    <div th:replace="~{'fragments/navigation'}"></div>
    <form th:action="@{/contact}" th:object="${contactMessageDTO}" method="POST">
      <!-- boilerplate contact form -->
    </form>
    <div th:replace="~{'fragments/footer'}"></div>
  </body>
</html>

Experience:

  • When I inspected the page in the browser, I had the HTML tags and the HEAD tags, but the headTagFragment would only be partially rendered, and the degree of rendering was random.
  • The error messaging indicated a problem with the th:action in my form tag. This sent me down a rabbit hole looking for why the /contact endpoint could not be found.
  • When I removed the th:action the page would load (but of course, it would not have anywhere to submit to).
  • If I commented out my navigation fragment, the page would load (but it would not look as designed).

Setting the produce-partial-output-while-processing to false, forced the page to be fully created before rendering in the browser. That seems to have been key.

Feature request: An advanced form submission example

It would be nice to see an example of an advance form submission. We recently were working on a project that had a form that looked like this:

//example: for each $post in $posts
<li>
  <input name="post[$postId][title]" value="$post.title" />
</li>

We really struggled with the appropriate way to structure a controller request model that Spring WebMVC would bind to. Maybe help there is a guide, and maybe also it is improvement to the documentation on html form binding.

greetingSubmit method is quite confusing

In this project, the following code lead me to a great misunderstanding, I want to share it, and maybe I can help others.

// GreetingController.java
 @PostMapping("/greeting")
    public String greetingSubmit(@ModelAttribute Greeting greeting) {
        return "result";
    }

// result.html
<p th:text="'content: ' + ${greeting.content}"/>

At first glance in the result.html, I thought greeting object may refer to the @ModelAttribute Greeting greeting, then I tried to make some modification to use another model OtherModel, but it turned out to be exception.
After google quite a while, I found out that here the ${greeting.content} is linked to the name of the model class rather than the name of the key.
So I believe that the proper way to do this is like this.

    @PostMapping("/greeting2")
    public String greetingSubmit(@ModelAttribute OtherModel greeting, Model model) {
        model.addAttribute("greeting", greeting);
        return "result";
    }

Thanks

Update the Spring Boot version

Update the guide to use the most recent Spring Boot version.

To do so, update the Spring Boot version in:

initial/build.gradle
initial/pom.xml
complete/build.gradle
complete/pom.xml

Upgrade Spring Boot to the latest version

Update the guide to use the most recent Spring Boot version.

To do so, change the Spring Boot version in:

initial/build.gradle
initial/pom.xml
complete/build.gradle
complete/pom.xml

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.