java - Component binding through MarkupWriter - Tapestry -
i'm in situation need use markupwriter
create checkbox instead of using .tml
. inside component , i'd bind checkbox's value parent's boolean value. in essence, it's following:
component
public class innercomponent { @parameter private boolean booleanvalue; void afterrender(final markupwriter writer) { writer.element("input", "type", "checkbox"); writer.end(); } }
calling page
public class outerpage { @property private boolean checkboxvalue; @injectcomponent private zone booleanzone; object ondisplayboolean() { return booleanzone.getbody(); } }
with .tml
<html t:type="layout" title="testproject index" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_4.xsd"> <t:innercomponent booleanvalue='checkboxvalue'/><br/> <t:eventlink event='displayboolean' zone='booleanzone'>update</t:eventlink> <t:zone t:id='booleanzone' id='booleanzone'> ${checkboxvalue} </t:zone> </html>
the component's markupwriter
writes out simple checkbox. receives boolean parameter. how go bind boolean parameter, checkbox markupwriter
generates?
in simple example, checking checkbox , updating zone
through eventlink
should show updated value of parent's checkboxvalue boolean
.
sifting through tapestry
's source code, have found a solution. component should first of extend abstractfield
, process submission of control. reassigning value updated one. edited, looks following:
public class innercomponent extends abstractfield { @property @parameter private boolean booleanvalue; @beginrender void begin(final markupwriter writer) { writer.element("input", "type", "checkbox", "name", getcontrolname(), "id", getclientid(), "checked", booleanvalue ? "checked" : null); writer.end(); } @override protected void processsubmission(string controlname) { string postedvalue = request.getparameter(controlname); booleanvalue = postedvalue != null; } }
this way i'm re-implementing checkbox logic. unlike in .tml
, using existing tapestry
checkbox
component. if there's better solution, using existing checkbox
component, i'd glad hear.
Comments
Post a Comment