Greeting Page | Table Page | New Node Page | Form Page |
This page shows how to use Enhydra with an form elements to display and retrieve data from a web page. For this sample the data is stored in a properties file. The same concepts can be used to update tables in a database. The html for the form is is:<form action="form" method="POST"> <table cellspacing="0" cellpadding="2"> <tr> <td align="right"><b>First Name</b></td> <td align="left"><input type="text" name="first" size="25" id="first"></td> </tr> <tr> <td align="right"><b>Last Name</b></td> <td align="left"><input type="text" name="last" size="25" id="last"></td> </tr> <tr> <td align="center" colspan="3"><input type="submit" value="Save"></td> </tr> </table> </form> Below is the form with data from the formdata.properties file. The method that sets the input values is: public FormHTML createPage(Properties data) { String first = null; String last = null; HTMLInputElement inputFirst = null; HTMLInputElement inputLast = null; FormHTML page = null; page = new FormHTML(); first = (String) data.get("first"); last = (String) data.get("last"); inputFirst = page.getElementFirst(); inputLast = page.getElementLast(); inputFirst.setValue(first); inputLast.setValue(last); return page; } The method that saves the input values is: private Properties saveParameters(HttpServletRequest request, Properties data) { String paramFirst = null; String paramLast = null; try { paramFirst = request.getParameter("first"); paramLast = request.getParameter("last"); } catch (Exception e) { paramFirst = null; paramLast = null; } if (paramFirst != null && paramLast != null) { data.put("first", paramFirst); data.put("last", paramLast); writePropertyFile(data); } return data; } |
Lutris | Enhydra |