Search in sources :

Example 1 with HttpPartWrapper

use of org.apache.myfaces.renderkit.html.util.HttpPartWrapper in project myfaces by apache.

the class HtmlInputFileRendererBase method decode.

@Override
public void decode(FacesContext facesContext, UIComponent component) {
    try {
        String clientId = component.getClientId();
        HttpServletRequest request = (HttpServletRequest) facesContext.getExternalContext().getRequest();
        Collection<Part> parts = request.getParts();
        Collection<Part> submittedValues = new ArrayList<>(parts.size());
        for (Part part : parts) {
            if (clientId.equals(part.getName())) {
                HttpPartWrapper wrapper = new HttpPartWrapper(part);
                submittedValues.add(wrapper);
            }
        }
        if (((HtmlInputFile) component).isMultiple()) {
            ((UIInput) component).setSubmittedValue(submittedValues);
        } else if (!submittedValues.isEmpty()) {
            ((UIInput) component).setSubmittedValue(submittedValues.iterator().next());
        }
    } catch (IOException | ServletException e) {
        throw new FacesException(e);
    }
    if (component instanceof ClientBehaviorHolder && !HtmlRendererUtils.isDisabled(component)) {
        ClientBehaviorRendererUtils.decodeClientBehaviors(facesContext, component);
    }
}
Also used : HtmlInputFile(jakarta.faces.component.html.HtmlInputFile) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ClientBehaviorHolder(jakarta.faces.component.behavior.ClientBehaviorHolder) UIInput(jakarta.faces.component.UIInput) FacesException(jakarta.faces.FacesException) HttpServletRequest(jakarta.servlet.http.HttpServletRequest) ServletException(jakarta.servlet.ServletException) HttpPartWrapper(org.apache.myfaces.renderkit.html.util.HttpPartWrapper) Part(jakarta.servlet.http.Part)

Aggregations

FacesException (jakarta.faces.FacesException)1 UIInput (jakarta.faces.component.UIInput)1 ClientBehaviorHolder (jakarta.faces.component.behavior.ClientBehaviorHolder)1 HtmlInputFile (jakarta.faces.component.html.HtmlInputFile)1 ServletException (jakarta.servlet.ServletException)1 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)1 Part (jakarta.servlet.http.Part)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HttpPartWrapper (org.apache.myfaces.renderkit.html.util.HttpPartWrapper)1