سؤال

We have UIInput component class and we wrote custom renderer for him.

@FacesRenderer(componentFamily = "javax.faces.Input", rendererType = "text")
public class TextFieldRenderer extends Renderer{
    @Override
    public void encodeBegin(FacesContext context, UIComponent component) throws IOException{
        String ClientId= component.getClientId(context);
        String hint= (String) component.getAttributes().get("placeholder");
        String styleClass= (String) component.getAttributes().get("styleClass");
        String value =(String) component.getAttributes().get("value");
        ResponseWriter writer= context.getResponseWriter();
        writer.startElement("input", component);
        writer.writeAttribute("type", "text", null);
        writer.writeAttribute("name", ClientId, null);
        writer.writeAttribute("placeholder", hint, "hint");
        writer.writeAttribute("class", styleClass, "styleClass");
        writer.writeAttribute("value", ((UIInput) component).getValue(), "value");
        writer.endElement("input");
    }
    @Override
    public void decode(FacesContext context, UIComponent component){
        ExternalContext external= context.getExternalContext();
        Map<String,String> request=external.getRequestParameterMap();
        UIInput txt= (UIInput)component;
        String clientId= component.getClientId(context);
        String submittedValue= (String) request.get(clientId);
        txt.setSubmittedValue(submittedValue);
    }
}

and index.xhtml snippet

<h:form>
    <text:hintText id="ht" placeholder="hint" styleClass="geomClass fieldMarginClass">
        <f:validateLength minimum="4"/>
    </text:hintText>
    <h:commandButton value="sub" styleClass="geomClass buttonMarginClass"/>
    <h:message for="ht"/>
</h:form>

component. As I understand after form submition value which typing to hintText will be assigned to a property submittedValue of UIInput instance by means of setSubmittedValue() method. Further at process_validation_phase we read value from submittedValue and apply our converter to him. If convertion success we passing converted value to method setValue(Objec o) and submittedValue will be null immideately. So my question is:

Where is converted value located? There is no value property of UIInput.

هل كانت مفيدة؟

المحلول

UIInput has a getConvertedValue() method that retrieves the converted value. You can optionally override this method in your renderer to perform any additional conversion on the submittedValue. Otherwise, the method returns the raw submittedValue

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top