本文整理匯總了Java中javax.faces.application.Application.createComponent方法的典型用法代碼示例。如果您正苦於以下問題:Java Application.createComponent方法的具體用法?Java Application.createComponent怎麽用?Java Application.createComponent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.faces.application.Application
的用法示例。
在下文中一共展示了Application.createComponent方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: loadCompositeComponent
import javax.faces.application.Application; //導入方法依賴的package包/類
public static void loadCompositeComponent(UIComponent parent, String libraryName, String resourceName, String id) {
// Prepare.
FacesContext context = FacesContext.getCurrentInstance();
Application application = context.getApplication();
FaceletContext faceletContext = (FaceletContext) context.getAttributes().get(FaceletContext.FACELET_CONTEXT_KEY);
// This basically creates <ui:component> based on <composite:interface>.
Resource resource = application.getResourceHandler().createResource(resourceName, libraryName);
UIComponent composite = application.createComponent(context, resource);
composite.setId(id); // Mandatory for the case composite is part of UIForm! Otherwise JSF can't find inputs.
// This basically creates <composite:implementation>.
UIComponent implementation = application.createComponent(UIPanel.COMPONENT_TYPE);
implementation.setRendererType("javax.faces.Group");
composite.getFacets().put(UIComponent.COMPOSITE_FACET_NAME, implementation);
// Now include the composite component tmpFileUploadPart in the given parent.
parent.getChildren().clear();
parent.getChildren().add(composite);
parent.pushComponentToEL(context, composite); // This makes #{cc} available.
try {
faceletContext.includeFacelet(implementation, resource.getURL());
} catch (IOException e) {
throw new FacesException(e);
} finally {
parent.popComponentFromEL(context);
}
}
示例2: includeCompositeComponent
import javax.faces.application.Application; //導入方法依賴的package包/類
public static void includeCompositeComponent(final UIComponent parent,
final String libraryName, final String resourceName,
final String id,
final Map<String, ValueExpression> mapValueExpression) {
// Prepare.
FacesContext context = FacesContext.getCurrentInstance();
Application application = context.getApplication();
FaceletContext faceletContext = (FaceletContext) context
.getAttributes().get("javax.faces.FACELET_CONTEXT");
// This basically creates <ui:component> based on <composite:interface>.
Resource resource = application.getResourceHandler().createResource(
resourceName, libraryName);
UIComponent composite = application.createComponent(context, resource);
// Mandatory for the case composite is part of
// UIForm! Otherwise JSF can't find inputs.
composite.setId(id);
// This for set the attribute and the action
for (Map.Entry<String, ValueExpression> entry : mapValueExpression
.entrySet()) {
composite.setValueExpression(entry.getKey(), entry.getValue());
}
// This basically creates <composite:implementation>.
UIComponent implementation = application
.createComponent(UIPanel.COMPONENT_TYPE);
implementation.setRendererType("javax.faces.Group");
composite.getFacets().put(UIComponent.COMPOSITE_FACET_NAME,
implementation);
// Now include the composite component file in the given parent.
parent.getChildren().add(composite);
// This makes #{cc} available.
parent.pushComponentToEL(context, composite);
try {
faceletContext.includeFacelet(implementation, resource.getURL());
} catch (IOException e) {
throw new FacesException(e);
} finally {
parent.popComponentFromEL(context);
}
}