Package dyntabs
Class JsfUtils
java.lang.Object
dyntabs.JsfUtils
Static utility class providing common JSF and PrimeFaces helper methods.
Includes utilities for:
- EL expression evaluation (
getExpressionValue(java.lang.String)) - Component tree traversal (
findComponent(jakarta.faces.component.UIComponent, java.lang.String),findComponentInDynamicTab(java.lang.String, java.lang.String)) - Parent component lookup (
findParentNamingContainer(jakarta.faces.component.UIComponent),findParentForm(jakarta.faces.component.UIComponent)) - PrimeFaces dialog management (
openPFDialog(org.primefaces.component.dialog.Dialog)) - Resource bundle access (
getStringFromAppResourceBundle(java.lang.String, java.lang.String)) - File download (
downloadFile(byte[], java.lang.String, java.lang.String)) and upload (readFileBytes(org.primefaces.model.file.UploadedFile))
- Author:
- DynTabs
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic jakarta.el.ValueExpressioncreateValueExpression(String exprStr, Class cls) static voiddownloadFile(byte[] fileBytes, String mimeType, String fileName) static jakarta.faces.component.UIComponentfindComponent(jakarta.faces.component.UIComponent base, String id) static jakarta.faces.component.UIComponentfindComponentByClientId(String clientId) Removes the visibility attribute for a p:dialog from the viewScope.static jakarta.faces.component.UIComponentfindComponentInDynamicTab(String componentId, String dynTabId) static Collection<String> findComponentsClientId(jakarta.faces.component.UIComponent base, String id) static jakarta.faces.component.UIComponentfindComponentWithIdInNamigContainer(jakarta.faces.component.UIComponent component, String ncIdPrefix, String Id) Within the first parent NamingContainer of the given component (whose ID starts withncIdPrefix), finds and returns the child component with the specified ID.static jakarta.faces.component.UIComponentfindParentComponentOfClass(jakarta.faces.component.UIComponent component, Class clazz) static jakarta.faces.component.UIComponentfindParentForm(jakarta.faces.component.UIComponent component) static jakarta.faces.component.UINamingContainerfindParentNamingContainer(jakarta.faces.component.UIComponent component) static jakarta.faces.component.UINamingContainerfindParentNamingContainerWithIdPrefix(jakarta.faces.component.UIComponent component, String idPrefix) Finds the first parent NamingContainer of the given component whose ID starts with the given prefix.static jakarta.faces.component.UIComponentfindParentWithIdPrefix(jakarta.faces.component.UIComponent component, String idPrefix) static jakarta.faces.application.Applicationstatic ResourceBundlegetAppResourceBundle(String rbName) static ObjectgetExpressionValue(String jsfExpression) static StringgetStringFromAppResourceBundle(String rbName, String key) static Stringstatic voidopenPFDialog(org.primefaces.component.dialog.Dialog dlg) Opens a PrimeFaces dialog by setting its visibility condition in the viewScope.static byte[]readFileBytes(org.primefaces.model.file.UploadedFile file) static voidrefreshComponentInDynamicTab(String compId, String dynTabId)
-
Field Details
-
DEFAULT_ERROR_MSG
-
NO_RESOURCE_FOUND
- See Also:
-
-
Constructor Details
-
JsfUtils
public JsfUtils()
-
-
Method Details
-
refreshComponentInDynamicTab
-
getExpressionValue
-
getApplication
public static jakarta.faces.application.Application getApplication() -
findParentNamingContainer
public static jakarta.faces.component.UINamingContainer findParentNamingContainer(jakarta.faces.component.UIComponent component) -
findParentNamingContainerWithIdPrefix
public static jakarta.faces.component.UINamingContainer findParentNamingContainerWithIdPrefix(jakarta.faces.component.UIComponent component, String idPrefix) Finds the first parent NamingContainer of the given component whose ID starts with the given prefix.- Parameters:
component- the starting componentidPrefix- the ID prefix to match- Returns:
- the matching parent NamingContainer, or null if not found
-
findParentWithIdPrefix
public static jakarta.faces.component.UIComponent findParentWithIdPrefix(jakarta.faces.component.UIComponent component, String idPrefix) -
findParentForm
public static jakarta.faces.component.UIComponent findParentForm(jakarta.faces.component.UIComponent component) -
findParentComponentOfClass
public static jakarta.faces.component.UIComponent findParentComponentOfClass(jakarta.faces.component.UIComponent component, Class clazz) -
findComponent
public static jakarta.faces.component.UIComponent findComponent(jakarta.faces.component.UIComponent base, String id) -
findComponentsClientId
public static Collection<String> findComponentsClientId(jakarta.faces.component.UIComponent base, String id) -
findComponentInDynamicTab
-
findComponentWithIdInNamigContainer
public static jakarta.faces.component.UIComponent findComponentWithIdInNamigContainer(jakarta.faces.component.UIComponent component, String ncIdPrefix, String Id) Within the first parent NamingContainer of the given component (whose ID starts withncIdPrefix), finds and returns the child component with the specified ID.- Parameters:
component- the starting componentncIdPrefix- the ID prefix for the parent NamingContainerId- the ID of the component to find- Returns:
- the found component, or null if not found
-
createValueExpression
-
openPFDialog
public static void openPFDialog(org.primefaces.component.dialog.Dialog dlg) Opens a PrimeFaces dialog by setting its visibility condition in the viewScope.Each CRUD dialog has a visible condition expression:
"#{viewScope." + dlg.getClientId().replace(":", "_") + "}"which is set up insolveDlgVisible(). This method makes that condition evaluate to true, making the dialog visible.NOT WORKING
- Parameters:
dlg- the PrimeFaces dialog to open
-
findComponentByClientId
Removes the visibility attribute for a p:dialog from the viewScope.Each CRUD dialog has a visible expression set up via
f:event listener="#{drugiBean.solveDlgVisible}" type="postAddToView", specifically inadjustVisibleForDialog(), in the form:"#{viewScope." + dlg.getClientId().replace(":", "_") + "}"To make the dialog visible,
crudListener()sets this viewScope attribute to true. To hide the dialog, this method removes the attribute so the expression evaluates to false.NOT WORKING
- Parameters:
dlgClientId- public static void removePFDialogVisibleCondition(String dlgClientId) { Mapinvalid input: '<'String, Object> viewMap = FacesContext.getCurrentInstance().getViewRoot().getViewMap(); String dlgClId_rep = dlgClientId.replace(":", "_"); viewMap.remove(dlgClId_rep); System.out.println(" -removed viewScope attribute: " + dlgClientId.replace(":", "_")); System.out.println("_DIALOG CLOSED " + dlgClientId + ", REMOVED viewAttr: " + dlgClId_rep); }
-
getStringFromAppResourceBundle
-
getAppResourceBundle
-
downloadFile
public static void downloadFile(byte[] fileBytes, String mimeType, String fileName) throws IOException - Throws:
IOException
-
readFileBytes
public static byte[] readFileBytes(org.primefaces.model.file.UploadedFile file) -
getURLBase
- Returns:
-