2016-11-05 20 views
3

内のオプションタグをツバメ:Thymeleafは、私は次のHTMLを持っているデータリスト

<!DOCTYPE html> 
<html lang="es" xmlns:th="http://www.thymeleaf.org"> 
<head></head> 

<body> 

<input type = "text" name="city" id="city-selector" list="available-cities" autofocus/> 
    <datalist id="available-cities"> 
     <option value="1">Madrid</option> 
     <option value="2">Barcelona</option> 
     <option value="3">Sevilla</option> 
     <option value="4">Valencia</option> 

    </datalist> 

</body> 

</html> 

私は私の春のブートアプリケーションでこのよう静的なコンテンツを追加すると、それが動作し、私はデータリスト機能を使用することができています。

<datalist id="available-cities"> Madrid Barcelona Sevilla Valencia </datalist> 

タグがdissappearとそのすべての値が連結されているオプション:私はThymeleafのテンプレートとしてこのファイルを追加して、テンプレートにルーティングする要求を春のコントローラを使用する場合は、データリストは、次のようにレンダリングされます。オプションタグがないので、データリストはもはや機能しません。

これはThymeleafのバグですか、何か間違っていますか?

答えて

3

hereで説明されているように、この問題はThymeleafのLEGACYHTML5モードの使用に関連しているようです。

それはオプションではない場合の回避策は、nekohtmlを使用するか、または避けるためにuse Thymeleaf 3にapplication.propertiesに次の行を含めることによって、HTML5モードへの変更である:

1

Thymeleaf 3は、この問題を解決しました。デフォルトスプリングブーツが2 thymeleaf使用することにより、以下の手順では、仕事をする必要があります:あなたのapplication.propertiesで

追加:

spring.thymeleaf.mode=HTML 
spring.thymeleaf.cache=false 

とあなたのpom.xmlのアドオンで:

<properties> 
    <thymeleaf.version>3.0.2.RELEASE</thymeleaf.version> 
    <thymeleaf-layout-dialect.version>2.1.1</thymeleaf-layout-dialect.version> 
</properties> 
<dependencies> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-actuator</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-actuator-docs</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-cache</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-thymeleaf</artifactId> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-web</artifactId> 
     </dependency> 
</dependencies> 
関連する問題