/** Test the built-in conversion for those renderers that have it. */ public void testEmptyStrings() { UIViewRoot root = Util.getViewHandler(getFacesContext()).createView(getFacesContext(), null); root.setLocale(Locale.US); UIInput text = new UIInput(), hidden = new UIInput(), secret = new UIInput(); text.setId("text"); hidden.setId("hidden"); secret.setId("secret"); text.setRendererType("Text"); hidden.setRendererType("Hidden"); secret.setRendererType("Secret"); root.getChildren().add(text); root.getChildren().add(hidden); root.getChildren().add(secret); TextRenderer textRenderer = new TextRenderer(); HiddenRenderer hiddenRenderer = new HiddenRenderer(); SecretRenderer secretRenderer = new SecretRenderer(); try { textRenderer.decode(getFacesContext(), text); hiddenRenderer.decode(getFacesContext(), hidden); secretRenderer.decode(getFacesContext(), secret); } catch (Throwable e) { assertTrue(false); } assertTrue(text.isValid()); assertTrue(hidden.isValid()); assertTrue(secret.isValid()); }
@Override protected void getEndTextToRender( FacesContext context, UIComponent component, String currentValue) throws IOException { final ResponseWriter originalResponseWriter = context.getResponseWriter(); context.setResponseWriter( new ResponseWriterWrapper() { @Override public ResponseWriter getWrapped() { return originalResponseWriter; } @Override public void startElement(String name, UIComponent component) throws IOException { super.startElement(name, component); if (name != null && name.equals("input")) { String attribute = (String) component.getAttributes().get("placeholder"); if (attribute != null && !attribute.equals("")) { super.writeAttribute("placeholder", attribute, "placeholder"); } } } }); super.getEndTextToRender(context, component, currentValue); context.setResponseWriter(originalResponseWriter); // Restore original writer. }