0

I am working on an simple application which use Spray and Scala and I am beginner in this environment. I am working on a form which is used to send information through post method. Form is below

 lazy val formPage =
  <html>
  <body>
  <form id="register">
  <fieldset> 
  <legend>Dodaj sędziego</legend> 
  <div> 
  <label>Imię
  <input id="first-name" name="first-name" placeholder="Imię" required autofocus> 
  </label>
  </div>
  <div> 
  <label>Nazwisko
  <input id="last-name" name="last-name" placeholder="Nazwisko" required autofocus> 
  </label>
  </div>
  <div> 
  <label>Numer identyfikacyjny
  <input id="number" name="number" required>
  </label>
  </div> 
  </fieldset>
  </form>
  </body>
  </html>

and I call it

  path("judge" / "new"){
    respondWithMediaType(`text/html`) {
      complete {
        formPage
      }
    }
  }

and it causes a lot of problems during compilation, for example:

[error] /project/src/main/scala/pl/vectorotic/MyService.scala:45: in XML literal: '=' expected instead of 'a'
[error]   <input id="first-name" name="first-name" placeholder="Imię" required autofocus>

I would like to ask how to use html inside scala program.

MC2DX
  • 562
  • 1
  • 7
  • 19
  • I think the problem is that your `required` and `autofocus` attributes are not valid XML/XHtml syntax. Try `autofocus="autofocus"`, instead. E.g. see http://www.w3schools.com/tags/att_input_autofocus.asp – jrudolph Jan 19 '15 at 08:41
  • It doesn't work, but I am curious why. – MC2DX Jan 23 '15 at 03:52

1 Answers1

2

Your formPage is not a string, but an XML Elem . Use triple quotes:

  lazy val formPage =
    """<html>
      <body>
        <form id="register">
          <fieldset>
            <legend>Dodaj sędziego</legend>
            <div>
              <label>Imię
                <input id="first-name" name="first-name" placeholder="Imię" required autofocus>
                </label>
              </div>
              <div>
                <label>Nazwisko
                  <input id="last-name" name="last-name" placeholder="Nazwisko" required autofocus>
                  </label>
                </div>
                <div>
                  <label>Numer identyfikacyjny
                    <input id="number" name="number" required>
                    </label>
                  </div>
                </fieldset>
              </form>
            </body>
          </html>"""
edi
  • 3,112
  • 21
  • 16
  • Why `lazy val` here? Is it worth to use in every case? – MC2DX Nov 11 '15 at 10:31
  • It's just there because it was also included it the original question, but you don't need it in this case. Have a look at [this SO question](http://stackoverflow.com/questions/7484928/what-does-a-lazy-val-do), which clarifies what `lazy` acutally does. – edi Nov 11 '15 at 12:45