package pt.ist.renderers; import pt.ist.renderers.components.HtmlBlockContainer; import pt.ist.renderers.components.HtmlCheckBox; import pt.ist.renderers.components.HtmlComponent; import pt.ist.renderers.components.HtmlPasswordInput; import pt.ist.renderers.components.HtmlScript; import pt.ist.renderers.layouts.Layout; import pt.ist.renderers.utils.RenderUtils; public class AdvancedPasswordRenderer extends InputRenderer { @Override protected Layout getLayout(Object object, Class type) { return new Layout() { @Override public HtmlComponent createComponent(Object object, Class type) { HtmlBlockContainer container = new HtmlBlockContainer(); HtmlPasswordInput passwordInput = new HtmlPasswordInput(); container.addChild(passwordInput); passwordInput.setId(passwordInput.getName()); HtmlCheckBox checkBox = new HtmlCheckBox(); checkBox.setText(RenderUtils.getResourceString("RENDERER_RESOURCES", "renderers.AdvancedPasswordRenderer.showPassword")); checkBox.setId(checkBox.getName()); container.addChild(checkBox); HtmlScript script = new HtmlScript(); String passwordInputId = RenderUtils.escapeId(passwordInput.getId()); String checkBoxId = RenderUtils.escapeId(checkBox.getId()); script.setScript("$(\"#" + checkBoxId +"\").click( function() { " + "var password = $(\"#" + passwordInputId +"\").attr('value');" + "var id = '" + passwordInputId + "';" + "if ($(this).attr('checked')) { $(\"#" + passwordInputId +"\").after(\"\").remove(); }" + "else { $(\"#" + passwordInputId +"\").after(\"\").remove(); }" + "});"); container.addChild(script); return container; } }; } }