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 Servlet, JSF and EL #81

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions jsft/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,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 +62,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
9 changes: 4 additions & 5 deletions jsft/src/main/java/com/sun/jsft/commands/JSFTCommands.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2020 Oracle and/or its affiliates. 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 Down Expand Up @@ -31,10 +31,9 @@
import java.util.List;
import java.util.Map;

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

import jakarta.inject.Named;

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

/**
Expand Down
9 changes: 4 additions & 5 deletions jsft/src/main/java/com/sun/jsft/commands/UtilCommands.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2020 Oracle and/or its affiliates. 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 @@ -26,10 +26,9 @@
import java.util.Iterator;
import java.util.Map;

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

import jakarta.inject.Named;

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

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, 2020 Oracle and/or its affiliates. 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 @@ -20,6 +20,7 @@
import com.sun.jsftemplating.component.factory.ComponentFactoryBase;
import com.sun.jsftemplating.layout.descriptors.LayoutComponent;

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

Expand Down Expand Up @@ -58,7 +59,9 @@ public UIComponent create(FacesContext context, LayoutComponent descriptor, UICo
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}"));
ValueExpression ve = context.getApplication().getExpressionFactory()
.createValueExpression(context.getELContext(), "#{true}", Object.class);
comp.setValueExpression("primary", ve);
}

// Set all the attributes / properties
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, 2020 Oracle and/or its affiliates. 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 +16,30 @@

package com.sun.jsftemplating.el;

import java.beans.FeatureDescriptor;
import java.io.Serializable;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import jakarta.el.ELContext;
import jakarta.el.ELResolver;
import jakarta.el.PropertyNotWritableException;
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 +48,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 +57,24 @@ 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
* This first delegates to the original <code>ELResolver</code>, it then checks "page session" to see if the value
* exists.
* </p>
*/
@Override
public Object resolveVariable(FacesContext context, String name) throws EvaluationException {
public Object getValue(ELContext context, Object base, Object property) {
if (null != base || property == null || !property.equals(PAGE_SESSION)) {
return null;
}
Object result = null;
// Check to see if expression explicitly asks for PAGE_SESSION
if (name.equals(PAGE_SESSION)) {
// It does, return the Map
UIViewRoot root = context.getViewRoot();
result = getPageSession(context, root);
if (result == null) {
// No Map! That's ok, create one...
result = createPageSession(context, root);
}
} else {
if (_origVariableResolver != null) {
// Not explicit, let original resolver do its thing first...
result = _origVariableResolver.resolveVariable(context, name);
}

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);
}
}
FacesContext facesContext = (FacesContext) context.getContext(FacesContext.class);
UIViewRoot root = facesContext.getViewRoot();
Map<String, Serializable> map = getPageSession(facesContext, root);
if (map == null) {
map = createPageSession(facesContext, root);
}

return result;
context.setPropertyResolved(true);
return map.get(property.toString());
}

/**
Expand Down Expand Up @@ -138,5 +111,36 @@ public static Map<String, Serializable> createPageSession(FacesContext ctx, UIVi
return map;
}

@Override
public void setValue(ELContext context, Object base, Object property, Object value) {
if (base != null || property == null || value == null || !property.equals(PAGE_SESSION)) {
return;
}
throw new PropertyNotWritableException("PageSessionResolver doesn't support setValue. " +
"base=" + base + "property=" + property);
}

@Override
public Class<?> getType(ELContext context, Object base, Object property) {
if (base != null || property == null || !property.equals(PAGE_SESSION)) {
return null;
}
context.setPropertyResolved(true);
return String.class;
}

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

@Override
public Iterator<FeatureDescriptor> getFeatureDescriptors(ELContext context, Object base) {
return null;
}

@Override
public Class<?> getCommonPropertyType(ELContext context, Object base) {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, 2020 Oracle and/or its affiliates. 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 Down Expand Up @@ -1364,7 +1364,8 @@ public static class MethodBindingDataSource implements DataSource {
*/
@Override
public Object getValue(FacesContext ctx, LayoutElement desc, UIComponent component, String key) {
return ctx.getApplication().createMethodBinding(key, ACTION_ARGS);
return ctx.getApplication().getExpressionFactory()
.createMethodExpression(ctx.getELContext(), key, null, ACTION_ARGS);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, 2020 Oracle and/or its affiliates. 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,6 +16,9 @@

package com.sun.jsftemplating.layout;

import static jakarta.faces.application.StateManager.IS_SAVING_STATE;
import static java.lang.Boolean.TRUE;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStreamWriter;
Expand Down Expand Up @@ -48,7 +51,6 @@

import jakarta.faces.FactoryFinder;
import jakarta.faces.application.StateManager;
import jakarta.faces.application.StateManager.SerializedView;
import jakarta.faces.application.ViewHandler;
import jakarta.faces.component.UIComponent;
import jakarta.faces.component.UIViewRoot;
Expand All @@ -57,6 +59,7 @@
import jakarta.faces.context.ResponseWriter;
import jakarta.faces.render.RenderKit;
import jakarta.faces.render.RenderKitFactory;
import jakarta.faces.view.ViewDeclarationLanguage;
import jakarta.servlet.ServletRequest;
import jakarta.servlet.ServletResponse;
import jakarta.servlet.http.HttpServletRequest;
Expand Down Expand Up @@ -785,10 +788,23 @@ public void writeState(FacesContext context) throws IOException {
} else {
// b/c we pre-processed the ViewTree, we can just add it...
StateManager stateManager = context.getApplication().getStateManager();
SerializedView view = stateManager.saveSerializedView(context);

// New versions of JSF 1.2 changed the contract so that state is
// always written (client and server state saving)
// SerializedView view = stateManager.saveSerializedView(context);
// FIXME: Temporary change to the removal of the JSF's APIs
Object view = null;
String viewId = context.getViewRoot().getViewId();
ViewDeclarationLanguage vdl = context.getApplication().getViewHandler().getViewDeclarationLanguage(context, viewId);
if (vdl != null) {
Map<Object, Object> contextAttributes = context.getAttributes();
try {
contextAttributes.put(IS_SAVING_STATE, TRUE);
view = vdl.getStateManagementStrategy(context, viewId)
.saveView(context);
} finally {
contextAttributes.remove(IS_SAVING_STATE);
}
}
stateManager.writeState(context, view);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, 2020 Oracle and/or its affiliates. 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 Down Expand Up @@ -29,21 +29,26 @@
import com.sun.jsftemplating.layout.descriptors.handler.Handler;
import com.sun.jsftemplating.util.LogUtil;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.faces.component.UIComponent;
import jakarta.faces.component.UIViewRoot;
import jakarta.faces.context.FacesContext;
import jakarta.faces.event.ActionEvent;
import jakarta.faces.event.ActionListener;
import jakarta.inject.Named;

/**
* <p>
* The purpose of this class is to provide an <code>ActionListener</code> that can delegate to handlers (that are likely
* defined via XML). It is safe to register this class as a managed bean at the Application scope. Or to use it directly
* as an <code>ActionListener</code>.
* The "invokeCommandHandlers" ActionListener in this managed bean capable of dispatching "command" handlers.
* </p>
*
* @author Ken Paulsen (ken.paulsen@sun.com)
*/
@ApplicationScoped
@Named(value="lfCommand")
public class CommandActionListener implements ActionListener, Serializable {

/**
Expand Down
Loading