Skip to content

Lift and form’s

7 February 2011

Learning scala, or trying to learn scala, was the first step for trying out the scala lift web framework. There are a number of tutorials on lift on the web and they are very needed, since the initial code for a lift framework application is a bit daunting to say the least. On the liftweb website there are 2 books that you can download for free, exploring lift and simply lift. Exploring lift is complete but also steps over some nitty-gritty details, which are more complete in simply lift, so for best understanding you should try to read both books.

In simply lift, there are some examples for form processing. This starts out really simple and gets more complex as you progress. Initially in the html code a form tag was used. However once the example progresses towards a statefull snippet, the form tag is replaced by a div tag. See copied example:
<div id="main" class="lift:surround?with=default&at=content">
Using stateful snippets for a better
user experience
<div class="lift:Stateful?form=post">
Name: <input name="name"><br>
Age: <input name="age" value="0"><br>
<input type="submit" value="Submit">

If you don’t spot this difference and you continue using a form tag with your statefull snippet, then the parameters will not be shown again in case of errors on the page. This is probably due to the fact that somehow all the parameters are encoded in the url and take presedence over the submitted values.

So do not use a form tag anymore when using a simple form.

Also, on the same section is an example of how to display an error message on the appropiate field. The example puts it like:
<span class="lift:Msg?id=age&errorClass=error">error</span>

However, when trying this I received a cryptic xml error about some missing ‘;’ character. Since lift fancies xhtml and xml a lot, I figured that the ‘&’ character should be xml encoded so ‘&amp;’ for the best result and this did the trick

Concerning the lift form tag I have found the issue. If you create a form tag like this:
<form class="lift:SomeSnippet?form=post">

then a form inside a form will be generated. This works ok in IE6 but will not work correctly in Chrome or Firefox. As you press the submit button, you can see that the parameters you entered are added to the url. So it might be better to use the div tag for a lift form.


From → scala

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: