这是我的方式。我添加了占位符和数据主题属性。如果要添加更多属性,则应仅将其名称添加到attribute数组。
import javax.faces.component.UIComponent;import javax.faces.context.FacesContext;import javax.faces.context.ResponseWriter;import com.sun.faces.renderkit.html_basic.TextRenderer;public class InputRender extends TextRenderer { @Override protected void getEndTextToRender(FacesContext context, UIComponent component, String currentValue) throws java.io.IOException{ String [] attributes = {"placeholder","data-theme"}; ResponseWriter writer = context.getResponseWriter(); for(String attribute : attributes) { String value = (String)component.getAttributes().get(attribute); if(value != null) { writer.writeAttribute(attribute, value, attribute); } } super.getEndTextToRender(context, component, currentValue); }}您应该将此添加到faces-config.xml文件。
<render-kit> <renderer> <component-family>javax.faces.Input</component-family> <renderer-type>javax.faces.Text</renderer-type> <renderer-class>your.package.InputRenderer</renderer-class> </renderer></render-kit>



