问题
I am using the play framework 2.3.8 with twitter Bootstrap 3.3.4 and have several forms in my application, where you can enter input.
Sample:
@import models.Question
@import models.Answer
@import helper._
@import helper.twitterBootstrap._
@(questionForm: Form[Question], questionList: List[Question])
@main("Ask Question"){
@helper.form(action = routes.Application.sendQuestion()){
<fieldset>
@helper.inputText(questionForm("questionID"))
@helper.inputText(questionForm("questionText"))
@helper.inputText(questionForm("voteScore"))
@helper.inputText(questionForm("userID"))
@helper.inputText(questionForm("page"))
</fieldset>
<input type="submit" class="btn btn-default">
}
}
Now, if I compile, there are several warnings in the terminal:
[warn] @helper.inputText(questionForm("userID"))
[warn] ^
[warn] (...)\frageAntwort.scala.html:22:
value twitterBootstrapField in package twitterBootstrap is deprecated:
The twitter bootstrap field constructor will be removed from Play in 2.4
since the way Bootstrap must be used changes too frequently and too
drastically between versions for this to make sense to be in the core of Play
I've searched for the warning and only found this old SO post about it and an issue on github.
The SO post mentions to write his own template helper, but as my own is working I see no need yet to write one. So can I still use mine and ignore the warnings, or will I get into trouble later in my productive system or anywhere else? Also if the warnings have no consequences, is there a way to hide them?
回答1:
In the Play 2.3 migration guide there's a section intended to explain that issue. It says that:
The in-built Twitter Bootstrap field constructor has been deprecated, and will be removed in a future version of Play.
There are a few reasons for this, one is that we have found that Bootstrap changes too drastically between versions and too frequently, such that any in-built support provided by Play quickly becomes stale and incompatible with the current Bootstrap version.
Another reason is that the current Bootstrap requirements for CSS classes can’t be implemented with Play’s field constructor alone, a custom input template is also required.
Our view going forward is that if this is a feature that is valuable to the community, a third party module can be created which provides a separate set of Bootstrap form helper templates, specific to given Bootstrap versions, allowing a much better user experience than can currently be provided.
Even if it works now there can be a problem in the future. If I were you, I'd plunk for writing a custom solution. Only that way you can be sure that after framework upgrade in your project everything will still work fine.
回答2:
Now, there is Play-Bootstrap with support of Bootstrap 3 and Bootstrap 4 and Play 2.4 and Play 2.5.
The SNAPSHOT
builds cannot be directly loaded, you have to do
resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/"
libraryDependencies ++= Seq(
"com.adrianhurt" %% "play-bootstrap" % "1.1-P25-B3-SNAPSHOT"
)
(Source: https://github.com/adrianhurt/play-bootstrap/blob/master/play25-bootstrap3/sample/build.sbt)
来源:https://stackoverflow.com/questions/30452387/can-i-ignore-the-twitter-bootstrap-is-deprecated-warnings-in-my-code