Skip to content

Conversation

evie-lau
Copy link
Contributor

@evie-lau evie-lau commented Jun 2, 2025

What's changed?

New recipe to migrate @ManagedBean from JSF/Jakarta Faces to the recommended CDI-based approach using @jakarta.inject.Named

What's your motivation?

ManagedBean is removed from EE10/Faces 4.0, and the existing recipe doesn't migrate the @ManagedBean annotation.
It seems using the CDI @Named is the general approach to replacing @ManagedBean.

Anything in particular you'd like reviewers to focus on?

Anyone you would like to review specifically?

Have you considered any alternatives or workarounds?

Any additional context

This current recipe converts both javax and jakarta ManagedBean to the jakarta CDI Named annotation, making this appropriate for EE9/10 migration, but not for EE8 users wanting to switch to CDI.

Should this be made more flexible to maintain either javax or jakarta based on the original code?

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've read and applied the recipe conventions and best practices
  • I've used the IntelliJ IDEA auto-formatter on affected files

@github-project-automation github-project-automation bot moved this to In Progress in OpenRewrite Jun 2, 2025
Copy link
Member

@timtebeek timtebeek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple quick comments; great to see already! Ought to be quick to address and then merge.

maybeRemoveImport("javax.faces.bean.ManagedBean");
maybeRemoveImport("jakarta.faces.bean.ManagedBean");
}
return annotation;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there's any chance of these appearing in nested annotations, then it might make sense to call super.visitAnnotation here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there's any chance of nested annotations here.

@timtebeek timtebeek added the recipe Recipe requested label Jun 2, 2025
Review suggestions

Co-authored-by: Tim te Beek <tim@moderne.io>
Copy link
Member

@timtebeek timtebeek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick fixes!

Should org.openrewrite.java.migrate.jakartaUpdateManagedBeanToNamed be added to any larger declarative migration recipe before we merge?

@github-project-automation github-project-automation bot moved this from In Progress to Ready to Review in OpenRewrite Jun 3, 2025
@evie-lau
Copy link
Contributor Author

evie-lau commented Jun 3, 2025

Yes, it would for sure be in the EE10/Faces 4.x migration, where ManagedBean is removed.

It could be called manually for EE9/Faces 3.0.

But I am wondering if it should also be available to run in EE8/Faces 2.3 where ManagedBean was already deprecated in favor of CDI. The recipe would have to change slightly to allow migrating to the javax inject

@timtebeek
Copy link
Member

Thanks for that context! Maybe best to for now add it to EE9 then?

Optional to also add it to EE8, but I imagine that'd need a different classpathFromResources, so perhaps not worth making that option available.

Copy link
Member

@timtebeek timtebeek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again!

@evie-lau
Copy link
Contributor Author

evie-lau commented Jun 3, 2025

Just to clarify the final decision:

  • added this recipe into the Faces 4.0 migration, where ManagedBean is removed and migration is required.
  • followed up on Create Faces 3.0 migration #742 and removed the Faces Bean -> CDI bean recipe list from Faces 3.0 migration

The managed bean migration recipe can still be invoked separately for anyone on EE9 wanting to get off the deprecated package.

@timtebeek timtebeek merged commit 6ed76d1 into openrewrite:main Jun 3, 2025
2 checks passed
@github-project-automation github-project-automation bot moved this from Ready to Review to Done in OpenRewrite Jun 3, 2025
@evie-lau evie-lau deleted the managedBeanToNamed branch June 3, 2025 20:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
recipe Recipe requested
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants