package e4s.tutorial; import e4s.html.*; import e4s.html.input.extended.*; import e4s.servlet.*; /** * Multiple form - a form with an input field that becomes visible depending on some other values. * * {@tutorial Example_MultipleForm} */ public class Example_MultipleForm extends E4ModuleImplementation { public static E4Method createMultipleForm = null; public static E4Method saveValues = null; public void createMultipleForm( HTML html, E4CgiParams p ) { FORM form = html.BODY().FORM(); // Add a non-editing TEXTAREA element to our form TEXTAREA tAreaSource = form.TEXTAREA(new E4InputFieldName("SRC"),"Translate this",60,3); tAreaSource.setValue("To be or not to be, this is the question."); tAreaSource.setReadOnly(true); // add a paragraph to give some look form.P(); // now, create an input field (in this case it is an text area with 60 columns, // 3 rows outside the form. Then create a input field of type MultiValue referenced // to the form, and give this new created TEXTAREA as parameter to the MultiValue // field. TEXTAREA tArea = new TEXTAREA(E4ID(),new E4InputFieldName("TRANS"),"Please enter a translation in several languages",60,3); E4InputMultiValue mVal = form.E4InputMultiValue(tArea); // add some multiple fields now. Internally, those fields later will be named // TRANS.DE, TRANS.FR and TRANS.IT. But this is not important at all. mVal.addExtension("DE","German"); mVal.addExtension("FR","French"); mVal.addExtension("IT","Italian"); mVal.addExtension("ES","Spanish"); // now, set some values for some of the fields mVal.setValue("DE","Sein oder nicht sein, das ist hier die Frage"); mVal.setValue("FR","Être ou ne pas être, c'est la question."); mVal.setValue("IT","Essere o non essere, questa è la domanda."); // define the callback function for Save form.setAction(saveValues); // add an Save-Button to that form form.FORM_Submit("Save"); } public void saveValues( HTML html, E4CgiParams p ) { html.print("TRANS.DE:"); html.BR(); html.print(p.get("TRANS.DE")); html.P(); html.print("TRANS.FR:"); html.BR(); html.print(p.get("TRANS.FR")); html.P(); html.print("TRANS.IT:"); html.BR(); html.print(p.get("TRANS.IT")); html.P(); html.print("TRANS.ES:"); html.BR(); html.print(p.get("TRANS.ES")); html.P(); p.toTable(html.TABLE()); html.HR(); A back = html.A(createMultipleForm); back.println("do it again"); } }