@Override public Object getConvertedValue(FacesContext context, UIComponent component, Object submittedValue) throws ConverterException { Converter converter = ComponentUtils.getConverter(context, component); if (converter != null) { String convertableValue = submittedValue == null ? null : submittedValue.toString(); return converter.getAsObject(context, component, convertableValue); } else { return submittedValue; } }
public static String getValueToRender(FacesContext context, UIComponent component) { return getValueToRender(context, component, UNDEFINED_VALUE); }
public <T extends UIComponent & RTLAware> void renderRTLDirection(FacesContext context, T component) throws IOException { if (ComponentUtils.isRTL(context, component)) { context.getResponseWriter().writeAttribute("dir", "rtl", null); } }
protected String escapeText(String text) { return ComponentUtils.escapeText(text); }
@Override public String resolveWidgetVar() { return ComponentUtils.resolveWidgetVar(getFacesContext(), this); } }
@Override public void showMessageInDialog(FacesMessage message) { String summary = ComponentUtils.escapeText(message.getSummary()); summary = ComponentUtils.replaceNewLineWithHtml(summary); String detail = ComponentUtils.escapeText(message.getDetail()); detail = ComponentUtils.replaceNewLineWithHtml(detail); this.execute("PrimeFaces.showMessageInDialog({severity:\"" + message.getSeverity() + "\",summary:\"" + summary + "\",detail:\"" + detail + "\"});"); }
/** * Close the current dynamic dialog. * * @param data optional data to pass back to a dialogReturn event. */ public void closeDynamic(Object data) { FacesContext facesContext = getFacesContext(); Map<String, String> params = facesContext.getExternalContext().getRequestParameterMap(); String pfdlgcid = ComponentUtils.escapeEcmaScriptText(params.get(Constants.DIALOG_FRAMEWORK.CONVERSATION_PARAM)); if (data != null) { Map<String, Object> session = facesContext.getExternalContext().getSessionMap(); session.put(pfdlgcid, data); } executeScript("PrimeFaces.closeDialog({pfdlgcid:'" + pfdlgcid + "'});"); }
@Override protected String getContentDisposition(String filename) { return ComponentUtils.createContentDisposition("attachment", filename + ".xlsx"); }
public static PhaseInfo getPhaseInfo(PhaseId id, FacesContext facesContext) { Map<String, Object> session = facesContext.getExternalContext().getSessionMap(); Map<String, LinkedHashMap<Integer, PhaseInfo>> storePerView = (Map<String, LinkedHashMap<Integer, PhaseInfo>>) session.get(LifecyclePhaseListener.class.getName()); if (storePerView == null) { storePerView = new HashMap<>(); session.put(LifecyclePhaseListener.class.getName(), storePerView); } String viewId = ComponentUtils.calculateViewId(facesContext); LinkedHashMap<Integer, PhaseInfo> store = storePerView.get(viewId); if (store == null) { store = new LinkedHashMap<>(); storePerView.put(viewId, store); } PhaseInfo phaseInfo = store.get(id.getOrdinal()); if (phaseInfo == null) { phaseInfo = new PhaseInfo(); phaseInfo.setPhase(id.getOrdinal()); store.put(id.getOrdinal(), phaseInfo); } return phaseInfo; }
/** * Creates an RFC 6266 Content-Dispostion header following all UTF-8 conventions. * <p> * @param value e.g. "attachment" * @param filename the name of the file * @return a valid Content-Disposition header in UTF-8 format */ public static String createContentDisposition(String value, String filename) { try { return String.format("%s;filename=\"%2$s\"; filename*=UTF-8''%2$s", value, encodeURI(filename)); } catch (UnsupportedEncodingException e) { throw new FacesException(e); } }
protected String escapeChartData(Object value) { // default to "null" if null String result = String.valueOf(value); // do NOT quote numbers but quote all other objects if (value instanceof Number == false) { result = "\"" + ComponentUtils.escapeText(result) + "\""; } return result; } }
@Override public String resolveWidgetVar() { return ComponentUtils.resolveWidgetVar(getFacesContext(), this); } }
/** * Displays a message in a dynamic dialog. * * @param message the {@link FacesMessage} to be displayed. */ public void showMessageDynamic(FacesMessage message) { String summary = ComponentUtils.escapeText(message.getSummary()); summary = ComponentUtils.replaceNewLineWithHtml(summary); String detail = ComponentUtils.escapeText(message.getDetail()); detail = ComponentUtils.replaceNewLineWithHtml(detail); executeScript("PrimeFaces.showMessageInDialog({severity:\"" + message.getSeverity() + "\",summary:\"" + summary + "\",detail:\"" + detail + "\"});"); } }
url = ComponentUtils.escapeEcmaScriptText(url); pfdlgcid = UUID.randomUUID().toString(); pfdlgcid = ComponentUtils.escapeEcmaScriptText(pfdlgcid); sb.append("'").append(ComponentUtils.escapeEcmaScriptText((String) optionValue)).append("'");
protected String getContentDisposition(String filename) { return ComponentUtils.createContentDisposition("attachment", filename + ".xls"); }
/** * Builds the view if not already available. This is mostly required for ViewExpiredException's. * * @param context The {@link FacesContext}. * @param throwable The occurred {@link Throwable}. * @param rootCause The root cause. * @return The unwrapped {@link Throwable}. * @throws java.io.IOException If building the view fails. */ protected Throwable buildView(FacesContext context, Throwable throwable, Throwable rootCause) throws IOException { if (context.getViewRoot() == null) { ViewHandler viewHandler = context.getApplication().getViewHandler(); String viewId = viewHandler.deriveViewId(context, ComponentUtils.calculateViewId(context)); ViewDeclarationLanguage vdl = viewHandler.getViewDeclarationLanguage(context, viewId); UIViewRoot viewRoot = vdl.createView(context, viewId); context.setViewRoot(viewRoot); vdl.buildView(context, viewRoot); // Workaround for Mojarra // if UIViewRoot == null -> 'IllegalArgumentException' is throwed instead of 'ViewExpiredException' if (rootCause == null && throwable instanceof IllegalArgumentException) { rootCause = new javax.faces.application.ViewExpiredException(viewId); } } return rootCause; }
/** * Creates an RFC 6266 Content-Dispostion header following all UTF-8 conventions. * <p> * @param value e.g. "attachment" * @param filename the name of the file * @return a valid Content-Disposition header in UTF-8 format */ public static String createContentDisposition(String value, String filename) { try { return String.format("%s;filename=\"%2$s\"; filename*=UTF-8''%2$s", value, encodeURI(filename)); } catch (UnsupportedEncodingException e) { throw new FacesException(e); } }
public String toJS(StringBuilder sb) { sb.append("['Label',{label:\"").append(ComponentUtils.escapeText(label)).append("\""); if (styleClass != null) sb.append(",cssClass:'").append(styleClass).append("'"); if (location != 0.5) sb.append(",location:").append(location); sb.append("}]"); return sb.toString(); } }
private Object convertValue(FacesContext context, String submittedItemValue) { Converter converter = ComponentUtils.getConverter(context, this); if (converter == null) { return submittedItemValue; } else { return converter.getAsObject(context, this, submittedItemValue); } }
@Override public String resolveWidgetVar() { return ComponentUtils.resolveWidgetVar(getFacesContext(), this); } }