Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to Jakarta Faces 4 #82

Merged
merged 14 commits into from
Nov 11, 2022
22 changes: 13 additions & 9 deletions jsft/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Copyright (c) 2014, 2020 Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2022 Contributors to the Eclipse Foundation. All rights reserved.
Copyright (c) 2014, 2022 Oracle and/or its affiliates. All rights reserved.

This program and the accompanying materials are made available under the
terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -37,6 +38,10 @@
<groupId>jakarta.el</groupId>
<artifactId>jakarta.el-api</artifactId>
</dependency>
<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>jakarta.enterprise.cdi-api</artifactId>
</dependency>
</dependencies>

<build>
Expand All @@ -58,14 +63,13 @@
com.sun.jsft.event;version="${project.osgi.version}",
com.sun.jsft.facelets;version="${project.osgi.version}",
com.sun.jsft.util;version="${project.osgi.version}",
jakarta.el;version="[2.1.2,4.0)",
jakarta.faces;version="[2.0.0,3.0)",
jakarta.faces.application;version="[2.0.0,3.0)",
jakarta.faces.bean;version="[2.0.0,3.0)",
jakarta.faces.component;version="[2.0.0,3.0)",
jakarta.faces.context;version="[2.0.0,3.0)",
jakarta.faces.event;version="[2.0.0,3.0)",
jakarta.faces.view.facelets;version="[2.0.0,3.0)",*
jakarta.el;version="[5.0.0,6.0)",
jakarta.faces;version="[4.0.0,5.0)",
jakarta.faces.application;version="[4.0.0,5.0)",
jakarta.faces.component;version="[4.0.0,5.0)",
jakarta.faces.context;version="[4.0.0,5.0)",
jakarta.faces.event;version="[4.0.0,5.0)",
jakarta.faces.view.facelets;version="[4.0.0,5.0)",*
</Import-Package>
</configuration>
</execution>
Expand Down
12 changes: 6 additions & 6 deletions jsft/src/main/java/com/sun/jsft/commands/JSFTCommands.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2011, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022 Contributors to the Eclipse Foundation. All rights reserved.
* Copyright (c) 2011, 2022 Oracle and/or its affiliates. All rights reserved.
* Portions Copyright (c) 2011 Ken Paulsen
*
* This program and the accompanying materials are made available under the
Expand All @@ -24,17 +25,16 @@
package com.sun.jsft.commands;

import com.sun.jsft.event.Command;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.faces.context.FacesContext;
import jakarta.inject.Named;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.List;
import java.util.Map;

import jakarta.faces.bean.ManagedBean;
import jakarta.faces.bean.ApplicationScoped;
import jakarta.faces.context.FacesContext;


/**
* <p> This class contains methods that perform common utility-type
Expand All @@ -43,7 +43,7 @@
* @author Ken Paulsen (kenapaulsen@gmail.com)
*/
@ApplicationScoped
@ManagedBean(name="jsft")
@Named("jsft")
public class JSFTCommands {

/**
Expand Down
13 changes: 7 additions & 6 deletions jsft/src/main/java/com/sun/jsft/commands/UtilCommands.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2011, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022 Contributors to the Eclipse Foundation. All rights reserved.
* Copyright (c) 2011, 2022 Oracle and/or its affiliates. All rights reserved.
* Portions Copyright (c) 2011 Ken Paulsen
*
* This program and the accompanying materials are made available under the
Expand All @@ -23,13 +24,13 @@
*/
package com.sun.jsft.commands;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.faces.component.UIComponent;
import jakarta.inject.Named;

import java.util.Iterator;
import java.util.Map;

import jakarta.faces.component.UIComponent;
import jakarta.faces.bean.ManagedBean;
import jakarta.faces.bean.ApplicationScoped;


/**
* <p> This class contains methods that perform common utility-type
Expand All @@ -38,7 +39,7 @@
* @author Ken Paulsen (kenapaulsen@gmail.com)
*/
@ApplicationScoped
@ManagedBean(name="util")
@Named("util")
public class UtilCommands {

/**
Expand Down
12 changes: 6 additions & 6 deletions jsft/src/main/resources/META-INF/jsft.taglib.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version = "1.0" encoding = "UTF-8"?>
<!--

Copyright (c) 2011, 2018 Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2022 Contributors to the Eclipse Foundation. All rights reserved.
Copyright (c) 2011, 2022 Oracle and/or its affiliates. All rights reserved.
Portions Copyright (c) 2011 Ken Paulsen

This program and the accompanying materials are made available under the
Expand All @@ -18,11 +19,10 @@

-->

<!DOCTYPE facelet-taglib PUBLIC
"-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN"
"http://java.sun.com/dtd/facelet-taglib_1_0.dtd">

<facelet-taglib>
<facelet-taglib xmlns="https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-facelettaglibrary_4_0.xsd"
version="4.0">

<namespace>http://jsftemplating.java.net/jsft</namespace>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2006, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022 Contributors to the Eclipse Foundation. All rights reserved.
* Copyright (c) 2006, 2022 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand All @@ -19,7 +20,8 @@
import com.sun.jsftemplating.annotation.UIComponentFactory;
import com.sun.jsftemplating.component.factory.ComponentFactoryBase;
import com.sun.jsftemplating.layout.descriptors.LayoutComponent;

import jakarta.el.ExpressionFactory;
import jakarta.el.ValueExpression;
import jakarta.faces.component.UIComponent;
import jakarta.faces.context.FacesContext;

Expand Down Expand Up @@ -56,9 +58,11 @@ public UIComponent create(FacesContext context, LayoutComponent descriptor, UICo

// Default to primary button
if (descriptor.getOption("primary") == null) {
// Use ValueBinding vs. property so we don't set the local value
// flag which will hide any future VB that is set on the component
comp.setValueBinding("primary", context.getApplication().createValueBinding("#{true}"));
// Use ValueExpression vs. property so we don't set the local value
// flag which will hide any future VE that is set on the component
ExpressionFactory factory = context.getApplication().getExpressionFactory();
ValueExpression valueExpression = factory.createValueExpression(context.getELContext(), "#{true}", Object.class);
comp.setValueExpression("primary", valueExpression);
}

// Set all the attributes / properties
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2006, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022 Contributors to the Eclipse Foundation. All rights reserved.
* Copyright (c) 2006, 2022 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand All @@ -16,26 +17,27 @@

package com.sun.jsftemplating.el;

import jakarta.el.ELContext;
import jakarta.el.ELResolver;
import jakarta.el.PropertyNotFoundException;
import jakarta.faces.component.UIViewRoot;
import jakarta.faces.context.FacesContext;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import jakarta.faces.component.UIViewRoot;
import jakarta.faces.context.FacesContext;
import jakarta.faces.el.EvaluationException;
import jakarta.faces.el.VariableResolver;

/**
* <p>
* This <code>VariableResolver</code> exists to resolve "page session" attributes. This concept, borrowed from
* This <code>ELResolver</code> exists to resolve "page session" attributes. This concept, borrowed from
* NetDynamics / JATO, stores data w/ the page so that it is available throughout the life of the page. This is longer
* than request scope, but usually shorter than session. This implementation stores the attributes on the
* <code>UIViewRoot</code>.
* </p>
*
* @author Ken Paulsen (ken.paulsen@sun.com)
*/
public class PageSessionResolver extends VariableResolver {
public class PageSessionResolver extends ELResolver {

/**
* <p>
Expand All @@ -44,13 +46,6 @@ public class PageSessionResolver extends VariableResolver {
*/
public static final String PAGE_SESSION = "pageSession";

/**
* <p>
* The original <code>VariableResolver</code>.
* </p>
*/
private VariableResolver _origVariableResolver = null;

/**
* <p>
* The attribute key in which to store the "page" session Map.
Expand All @@ -60,48 +55,66 @@ public class PageSessionResolver extends VariableResolver {

/**
* <p>
* Constructor.
* </p>
*/
public PageSessionResolver(VariableResolver orig) {
super();
_origVariableResolver = orig;
}

/**
* <p>
* This first delegates to the original <code>VariableResolver</code>, it then checks "page session" to see if the value
* exists.
* Checks "page session" to see if the value exists.
* </p>
*/
@Override
public Object resolveVariable(FacesContext context, String name) throws EvaluationException {
Object result = null;
public Object getValue(ELContext elContext, Object base, Object property) {
if (base != null) {
return null;
}

if (property == null) {
throw new PropertyNotFoundException();
}

FacesContext facesContext = (FacesContext) elContext.getContext(FacesContext.class);
UIViewRoot viewRoot = facesContext.getViewRoot();
Map<String, Serializable> pageSession = getPageSession(facesContext, viewRoot);

Object value = null;
// Check to see if expression explicitly asks for PAGE_SESSION
if (name.equals(PAGE_SESSION)) {
if (property.equals(PAGE_SESSION)) {
// It does, return the Map
UIViewRoot root = context.getViewRoot();
result = getPageSession(context, root);
if (result == null) {
if (pageSession == null) {
// No Map! That's ok, create one...
result = createPageSession(context, root);
pageSession = createPageSession(facesContext, viewRoot);
}
value = pageSession;
} else {
if (_origVariableResolver != null) {
// Not explicit, let original resolver do its thing first...
result = _origVariableResolver.resolveVariable(context, name);
if (pageSession != null) {
// Check page session
value = pageSession.get(property.toString());
}
}

if (result == null) {
// Original resolver couldn't find anything, check page session
Map<String, Serializable> map = getPageSession(context, (UIViewRoot) null);
if (map != null) {
result = map.get(name);
}
}
if (value != null || (pageSession != null && pageSession.containsKey(property.toString()))) {
elContext.setPropertyResolved(true);
}

return result;
return value;
}

@Override
public Class<?> getType(ELContext elContext, Object base, Object property) {
checkPropertyFound(base, property);
return null;
}

@Override
public void setValue(ELContext elContext, Object base, Object property, Object value) {
checkPropertyFound(base, property);
}

@Override
public boolean isReadOnly(ELContext elContext, Object base, Object property) {
checkPropertyFound(base, property);
return false;
}

@Override
public Class<?> getCommonPropertyType(ELContext elContext, Object base) {
return base == null ? String.class : null;
}

/**
Expand All @@ -111,11 +124,12 @@ public Object resolveVariable(FacesContext context, String name) throws Evaluati
* used.
* </p>
*/
public static Map<String, Serializable> getPageSession(FacesContext ctx, UIViewRoot root) {
if (root == null) {
root = ctx.getViewRoot();
@SuppressWarnings("unchecked")
public static Map<String, Serializable> getPageSession(FacesContext facesContext, UIViewRoot viewRoot) {
if (viewRoot == null) {
viewRoot = facesContext.getViewRoot();
}
return (Map<String, Serializable>) root.getAttributes().get(PAGE_SESSION_KEY);
return (Map<String, Serializable>) viewRoot.getAttributes().get(PAGE_SESSION_KEY);
}

/**
Expand All @@ -124,19 +138,24 @@ public static Map<String, Serializable> getPageSession(FacesContext ctx, UIViewR
* <code>Map</code>, so be careful.
* </p>
*/
public static Map<String, Serializable> createPageSession(FacesContext ctx, UIViewRoot root) {
if (root == null) {
root = ctx.getViewRoot();
public static Map<String, Serializable> createPageSession(FacesContext facesContext, UIViewRoot viewRoot) {
if (viewRoot == null) {
viewRoot = facesContext.getViewRoot();
}

// Create it...
Map<String, Serializable> map = new HashMap<>(4);
Map<String, Serializable> pageSession = new HashMap<>(4);

// Store it...
root.getAttributes().put(PAGE_SESSION_KEY, map);
viewRoot.getAttributes().put(PAGE_SESSION_KEY, pageSession);

// Return it...
return map;
return pageSession;
}


private static void checkPropertyFound(Object base, Object property) {
if (base == null && property == null) {
throw new PropertyNotFoundException();
}
}
}
Loading