use of javax.faces.component.NamingContainer in project empire-db by apache.
the class WebApplication method findChildComponent.
/**
* finds a child component with the given id that is located below the given parent component
* @param parent the parent
* @param componentId the component id
* @return the component or null if no component was found
*/
public static UIComponent findChildComponent(UIComponent parent, String componentId) {
UIComponent component = null;
if (parent.getChildCount() == 0)
return null;
Iterator<UIComponent> children = parent.getChildren().iterator();
while (children.hasNext()) {
UIComponent nextChild = children.next();
if (nextChild instanceof NamingContainer) {
component = nextChild.findComponent(componentId);
}
if (component == null) {
component = findChildComponent(nextChild, componentId);
}
if (component != null) {
break;
}
}
return component;
}
use of javax.faces.component.NamingContainer in project primefaces by primefaces.
the class PrimePartialResponseWriter method startMetadataIfNecessary.
protected void startMetadataIfNecessary() throws IOException {
if (metadataRendered) {
return;
}
metadataRendered = true;
FacesContext context = FacesContext.getCurrentInstance();
PrimeApplicationContext applicationContext = PrimeApplicationContext.getCurrentInstance(context);
if (applicationContext != null) {
try {
// catch possible ViewExpired
UIViewRoot viewRoot = context.getViewRoot();
if (viewRoot != null) {
// portlet parameter namespacing
if (viewRoot instanceof NamingContainer) {
String parameterNamespace = viewRoot.getContainerClientId(context);
if (LangUtils.isNotEmpty(parameterNamespace)) {
String parameterPrefix = parameterNamespace;
if (applicationContext.getEnvironment().isAtLeastJsf23()) {
// https://java.net/jira/browse/JAVASERVERFACES_SPEC_PUBLIC-790
parameterPrefix += UINamingContainer.getSeparatorChar(context);
}
Map<String, Object> params = new HashMap<>();
params.put("parameterPrefix", parameterPrefix);
encodeCallbackParams(params);
}
}
// we also skip update=@all, as the head with all resources, will already be rendered
if (context.isPostback() && !context.getPartialViewContext().isRenderAll() && !applicationContext.getEnvironment().isAtLeastJsf23()) {
List<ResourceUtils.ResourceInfo> initialResources = DynamicResourcesPhaseListener.getInitialResources(context);
List<ResourceUtils.ResourceInfo> currentResources = ResourceUtils.getComponentResources(context);
if (initialResources != null && currentResources != null && currentResources.size() > initialResources.size()) {
List<ResourceUtils.ResourceInfo> newResources = new ArrayList<>(currentResources);
newResources.removeAll(initialResources);
boolean updateStarted = false;
for (int i = 0; i < newResources.size(); i++) {
ResourceUtils.ResourceInfo resourceInfo = newResources.get(i);
if (!updateStarted) {
((PartialResponseWriter) getWrapped()).startUpdate("javax.faces.Resource");
updateStarted = true;
}
resourceInfo.getResource().encodeAll(context);
}
if (updateStarted) {
((PartialResponseWriter) getWrapped()).endUpdate();
}
}
}
}
} catch (Exception e) {
throw new AbortProcessingException(e);
}
}
}
use of javax.faces.component.NamingContainer in project liferay-faces-alloy by liferay.
the class InputFileRenderer method encodeJavaScriptCustom.
@Override
public void encodeJavaScriptCustom(FacesContext facesContext, UIComponent uiComponent) throws IOException {
ResponseWriter responseWriter = facesContext.getResponseWriter();
InputFile inputFile = (InputFile) uiComponent;
// Determine the valid content-types and maximum file size from the validator (if specified).
String validContentTypesString = inputFile.getContentTypes();
JavaScriptFragment[] validContentTypes;
if ((validContentTypesString == null) || "".equals(validContentTypesString)) {
validContentTypes = new JavaScriptFragment[] {};
} else {
validContentTypes = AlloyRendererUtil.toEscapedJavaScriptStringArray(validContentTypesString.split("\\s*,\\s*"));
}
String clientId = inputFile.getClientId(facesContext);
Long maxFileSize = inputFile.getMaxFileSize();
if (maxFileSize == null) {
maxFileSize = Long.MAX_VALUE;
}
// If the component should render the upload progress table, then initialize the YUI progress uploader widget.
if (inputFile.isShowProgress()) {
String clientVarName = getClientVarName(facesContext, inputFile);
String clientKey = inputFile.getClientKey();
if (clientKey == null) {
clientKey = clientVarName;
}
UIViewRoot viewRoot = facesContext.getViewRoot();
Locale locale = viewRoot.getLocale();
String formClientId = getParentFormClientId(inputFile);
Application application = facesContext.getApplication();
ViewHandler viewHandler = application.getViewHandler();
String actionURL = viewHandler.getActionURL(facesContext, viewRoot.getViewId());
String partialActionURL = facesContext.getExternalContext().encodePartialActionURL(actionURL);
String namingContainerId = "";
if (viewRoot instanceof NamingContainer) {
namingContainerId = viewRoot.getContainerClientId(facesContext);
}
AjaxParameters ajaxParameters = new AjaxParameters(inputFile, clientId, formClientId);
String execute = ajaxParameters.getExecute();
String render = ajaxParameters.getRender();
ExternalContext externalContext = facesContext.getExternalContext();
I18n i18n = I18nFactory.getI18nInstance(externalContext);
String notStartedMessage = i18n.getMessage(facesContext, locale, "not-started");
JavaScriptFragment clientComponent = new JavaScriptFragment("Liferay.component('" + clientKey + "')");
encodeFunctionCall(responseWriter, "LFAI.initProgressUploader", 'A', clientComponent, validContentTypes, clientId, formClientId, namingContainerId, inputFile.isAuto(), execute, render, partialActionURL, maxFileSize, notStartedMessage);
} else // template and write it to the response.
if (inputFile.isShowPreview()) {
encodeFunctionCall(responseWriter, "LFAI.initPreviewUploader", 'A', validContentTypes, clientId, maxFileSize);
}
}
use of javax.faces.component.NamingContainer in project liferay-faces-alloy by liferay.
the class AutoCompleteRenderer method encodeJavaScriptCustom.
@Override
public void encodeJavaScriptCustom(FacesContext facesContext, UIComponent uiComponent) throws IOException {
// If the developer has specified a server-side filtering, then
if (isServerFilteringEnabled(uiComponent)) {
ResponseWriter responseWriter = facesContext.getResponseWriter();
ClientComponent clientComponent = (ClientComponent) uiComponent;
String clientVarName = getClientVarName(facesContext, clientComponent);
String clientKey = clientComponent.getClientKey();
if (clientKey == null) {
clientKey = clientVarName;
}
// J-
// var clientVarName = Liferay.component('clientKey');
// J+
encodeLiferayComponentVar(responseWriter, clientVarName, clientKey);
JavaScriptFragment clientVarNameJSFragment = new JavaScriptFragment(clientVarName);
String clientId = uiComponent.getClientId(facesContext);
String hiddenClientId = clientId + HIDDEN_SUFFIX;
String namingContainerId = null;
UIViewRoot viewRoot = facesContext.getViewRoot();
if (viewRoot instanceof NamingContainer) {
namingContainerId = viewRoot.getContainerClientId(facesContext);
}
// J-
// LFAI.setAutoCompleteEventListeners(A, clientVarName, 'escapedHiddenClientId', 'clientId',
// 'namingContainerId');
// J+
encodeFunctionCall(responseWriter, "LFAI.initAutoCompleteServerMode", clientVarNameJSFragment, hiddenClientId, clientId, namingContainerId);
}
}
Aggregations