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.po" 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.

First Name
Last Name

The method that sets the input values is:

private void fixupForm() {
  String first = (String) data.get("first");
  String last  = (String) data.get("last");
  HTMLInputElement inputFirst = page.getElementFirst();
  HTMLInputElement inputLast  = page.getElementLast();
  inputFirst.setValue(first);
  inputLast.setValue(last);
}

            

The method that saves the input values is:

private void saveParameters() {
  String paramFirst = null;
  String paramLast = null;
  try {
    paramFirst = comms.request.getParameter("first");
    paramLast =  comms.request.getParameter("last");
  } catch (Exception e) {
    paramFirst = null;
    paramLast  = null;
  }
  if (paramFirst != null && paramLast != null) {
    data.put("first", paramFirst);
    data.put("last", paramLast);
    writePropertyFile();
  }
}


            

Lutris | Enhydra

The Kelp Working Group