Skip to content

Commit

Permalink
Adapting Logging
Browse files Browse the repository at this point in the history
  • Loading branch information
cuioss committed Jul 2, 2024
1 parent 450f4d5 commit 5be9301
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import de.cuioss.jsf.bootstrap.BootstrapFamily;
import de.cuioss.jsf.bootstrap.notification.NotificationBoxComponent;
import de.cuioss.jsf.bootstrap.waitingindicator.WaitingIndicatorComponent;
import de.cuioss.tools.logging.CuiLogger;
import de.cuioss.tools.string.MoreStrings;
import de.cuioss.uimodel.nameprovider.IDisplayNameProvider;
import jakarta.el.MethodExpression;
Expand Down Expand Up @@ -55,6 +56,7 @@
@ListenerFor(systemEventClass = PostAddToViewEvent.class)
public class LazyLoadingComponent extends UICommand implements ComponentBridge, NamingContainer {

private static final CuiLogger LOGGER = new CuiLogger(LazyLoadingComponent.class);
private static final String INITIALIZED_KEY = "initialized";

private static final String CHILDREN_LOADED_KEY = "childrenLoaded";
Expand Down Expand Up @@ -108,15 +110,19 @@ public LazyLoadingComponent() {
public void processEvent(final ComponentSystemEvent event) {
if (event instanceof PreRenderViewEvent) {
if (!oneTimeCheck.readAndSetChecked()) {
LOGGER.debug("Handling PreRenderViewEvent %s after OneTimeCheck", event);
var startInitialize = getStartInitialize();
if (null != startInitialize) {
LOGGER.debug("Invoking startInitialize");
startInitialize.invoke(getFacesContext().getELContext(), new Object[]{});
}
if (!evaluateInitialized() && null != getViewModel()) {
if (evaluateNotInitialized() && null != getViewModel()) {
LOGGER.debug("Adding actionListener");
super.addActionListener(getViewModel());
}
}
} else if (event instanceof PostAddToViewEvent) {
LOGGER.debug("Handling PostAddToViewEvent %s", event);
createWaitingIndicator();
createNotificationBox();
}
Expand Down Expand Up @@ -238,11 +244,11 @@ public boolean isInitialized() {
return state.getBoolean(INITIALIZED_KEY, false);
}

public boolean evaluateInitialized() {
public boolean evaluateNotInitialized() {
if (null != getViewModel()) {
return isInitialized() || getViewModel().isInitialized();
return !isInitialized() && !getViewModel().isInitialized();
}
return isInitialized();
return !isInitialized();
}

/**
Expand Down Expand Up @@ -289,7 +295,7 @@ public boolean getChildrenLoaded() {
}

/**
* Remember that childs were already rendered or trigger loading in the next
* Remember that children were already rendered or trigger loading in the next
* request.
*
* @param childrenLoaded true when the children should be rendered in the next
Expand All @@ -300,7 +306,7 @@ public void setChildrenLoaded(final boolean childrenLoaded) {
}

public boolean shouldRenderWaitingIndicator(FacesContext facesContext) {
return !evaluateInitialized() && !getChildrenLoaded() && !isContentLoadRequest(facesContext);
return evaluateNotInitialized() && !getChildrenLoaded() && isNotContentLoadRequest(facesContext);
}

public boolean evaluateRenderContent() {
Expand All @@ -317,7 +323,7 @@ public boolean evaluateRenderContent() {
*/
@Override
public void processValidators(FacesContext context) {
if (!isContentLoadRequest(context)) {
if (isNotContentLoadRequest(context)) {
super.processValidators(context);
}
}
Expand All @@ -329,7 +335,7 @@ public void processValidators(FacesContext context) {
*/
@Override
public void processUpdates(FacesContext context) {
if (!isContentLoadRequest(context)) {
if (isNotContentLoadRequest(context)) {
super.processUpdates(context);
}
}
Expand All @@ -342,48 +348,37 @@ public void processUpdates(FacesContext context) {
* @return true if the current request was triggered by the ajax request to
* reload the lazy loading content
*/
public boolean isContentLoadRequest(FacesContext context) {
public boolean isNotContentLoadRequest(FacesContext context) {
var componentWrapper = new ComponentWrapper<>(this);
return context.getExternalContext().getRequestParameterMap()
return !context.getExternalContext().getRequestParameterMap()
.containsKey(componentWrapper.getSuffixedClientId(ID_SUFFIX_IS_LOADED));
}

/**
* Create a waiting indicator based on the composite component if not already
* existing.
*
* @return the waiting indicator as {@link UIComponent}.
*/
UIComponent createWaitingIndicator() {
var result = retrieveWaitingIndicator();

if (result.isEmpty()) {
var waitingIndicator = WaitingIndicatorComponent.createComponent(FacesContext.getCurrentInstance());
void createWaitingIndicator() {
if (retrieveWaitingIndicator().isEmpty()) {
var waitingIndicator = WaitingIndicatorComponent.createComponent(getFacesContext());
if (!MoreStrings.isEmpty(getWaitingIndicatorStyleClass())) {
waitingIndicator.setStyleClass(getWaitingIndicatorStyleClass());
}
waitingIndicator.setId(WAITING_INDICATOR_ID);
getChildren().add(waitingIndicator);
return waitingIndicator;
}
return result.get();
}

/**
* Create a result notification box if not already existing.
*
* @return the notification box as {@link UIComponent}.
*/
NotificationBoxComponent createNotificationBox() {
var result = retrieveNotificationBox();
if (result.isEmpty()) {
void createNotificationBox() {
if (retrieveNotificationBox().isEmpty()) {
var notificationBoxComponent = new NotificationBoxComponent();
notificationBoxComponent.getPassThroughAttributes().put(DATA_RESULT_NOTIFICATION_BOX,
DATA_RESULT_NOTIFICATION_BOX);
getChildren().add(0, notificationBoxComponent);
return notificationBoxComponent;
}
return (NotificationBoxComponent) result.get();
}

public Optional<UIComponent> retrieveWaitingIndicator() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import de.cuioss.jsf.bootstrap.BootstrapFamily;
import de.cuioss.jsf.bootstrap.CssCuiBootstrap;
import de.cuioss.jsf.bootstrap.notification.NotificationBoxComponent;
import de.cuioss.tools.logging.CuiLogger;
import jakarta.faces.component.UIComponent;
import jakarta.faces.context.FacesContext;
import jakarta.faces.event.ActionEvent;
Expand All @@ -38,6 +39,7 @@
@FacesRenderer(rendererType = BootstrapFamily.LAZYLOADING_RENDERER, componentFamily = BootstrapFamily.COMPONENT_FAMILY)
public class LazyLoadingRenderer extends BaseDecoratorRenderer<LazyLoadingComponent> {

private static final CuiLogger LOGGER = new CuiLogger(LazyLoadingRenderer.class);
static final String DATA_LAZY_LOADING_CONTENT = "data-lazy_loading-content";

private static final String LAZY_LOADING_CONTENT_ID = "content";
Expand Down Expand Up @@ -131,13 +133,16 @@ protected void doEncodeChildren(final FacesContext context,
@Override
protected void doDecode(final FacesContext context, final ComponentWrapper<LazyLoadingComponent> componentWrapper) {
final var component = componentWrapper.getWrapped();
final var map = context.getExternalContext().getRequestParameterMap();
LOGGER.debug("Decoding lazy loading component for %s", component);

final var map = context.getExternalContext().getRequestParameterMap();
final var isLoadedValue = map.get(componentWrapper.getSuffixedClientId(ID_SUFFIX_IS_LOADED));
LOGGER.debug("isLoadedValue: %s", isLoadedValue);
if (isLoadedValue != null) {
var loadedValue = Boolean.parseBoolean(isLoadedValue);
if (loadedValue && !component.getChildrenLoaded()) {
component.setChildrenLoaded(true);
LOGGER.debug("Queuing ActionEvent for %s", component);
component.queueEvent(new ActionEvent(component));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import de.cuioss.test.jsf.component.AbstractComponentTest;
import de.cuioss.test.jsf.config.component.VerifyComponentProperties;

@VerifyComponentProperties(of = { "initialized", "notificationBoxValue", "notificationBoxState", "renderContent",
"viewModel", "ignoreAutoUpdate" })
@VerifyComponentProperties(of = {"initialized", "notificationBoxValue", "notificationBoxState", "renderContent",
"viewModel", "ignoreAutoUpdate", "async", "childrenLoaded", "waitingIndicatorStyleClass"})
class LazyLoadingComponentTest extends AbstractComponentTest<LazyLoadingComponent> {

}

0 comments on commit 5be9301

Please sign in to comment.