apache / netbeans

Apache NetBeans
https://netbeans.apache.org/
Apache License 2.0
2.6k stars 835 forks source link

Some jsf wizards are completely messed up #7532

Open AdolfGalland opened 1 week ago

AdolfGalland commented 1 week ago

Apache NetBeans version

Apache NetBeans 22

What happened

New web application selecting jakarta 10 EE web with jakarta.faces-4.0.4.jar. "Entity classes from database" wizard is selected. If Jakarta EE 10 API Library has already been added the imported packages are the correct ones: jakarta.persistence. , otherwise they are javax.persistence. and lots of errors are reported. "JSF pages from entity classes" wizard is selected. Here are some lines extracted from generated controller class:

import jakarta.faces.bean.ManagedBean; import jakarta.faces.bean.SessionScoped; @ManagedBean(name = "badgeController") @SessionScoped

Non existent packages and deprecated annotations are inserted

Controller code not compatible with generated jsf pages: public String next() { getPagination().nextPage(); recreateModel(); return "List"; }

<h:commandLink action="#{badgeController.next}"

next is not a property, so its should be next() In generated jsf pages most functions are called as they were properties so there are runtime errors.

Language / Project Type / NetBeans Component

No response

How to reproduce

Use the wizards and check produced code

Did this work correctly in an earlier version?

No / Don't know

Operating System

Windows 11 pro

JDK

openjdk version "17.0.4.1"

Apache NetBeans packaging

Apache NetBeans provided installer

Anything else

No response

Are you willing to submit a pull request?

No

matthiasblaesing commented 1 week ago
  1. Don't put multiple issues into a single report
  2. "How to reproduce" means: What are the exact steps, starting from a clean NetBeans installation to reproduce the issue

Please adjust and it might be actionable.

For the only thing that I could place

If Jakarta EE 10 API Library has already been added the imported packages are the correct ones: *jakarta.persistence. *, otherwise they are javax.persistence. ** and lots of errors are reported."

Yes. We can discuss whether missing libraries should default to jakarta or javax namespace, but in any case we need to guess. So from my POV: Works as expected.

AdolfGalland commented 1 week ago

Works as expected.

Don't think it is a good idea to automatically generate code which is marked all red.

  1. "How to reproduce" means: What are the exact steps, starting from a clean NetBeans installation to reproduce the issue

Create an entity class with "Entity classes from database" wizard After that cerate jsf pages, controllers and what else is needed with "JSF pages from entity classes" wizard

According to me nobody has checked these wizards since their first release years ago and after the transitions from javax to jakarta, they generate wrong code.

Here is my netbeans project wizard2.zip

matthiasblaesing commented 1 week ago

I just generated a maven web application with the JakartaEE 10 selected. Then I did what you said and get a cleanly generated code. This was also done when the code templates for support of the jakarta namespace was added.

According to me nobody has checked these wizards since their first release years ago and after the transitions from javax to jakarta, they generate wrong code.

I strongly suggest, that you keep such accusations to yourself.

You claim that this generated code:

<h:commandLink action="#{badgeController.next}"

is invalid. On what do you base that? Reading this:

https://jakarta.ee/learn/docs/jakartaee-tutorial/current/web/faces-el/faces-el.html#_parameterized_method_calls

It explicitly gives this sample:

<h:commandButton action="#{trader.buy}" value="buy"/>

You can argue, that method references should always be generated with parantheses, but apparently they are not required.

I validated that with a trivial JSF page on Glassfish 7.0.11.

matthiasblaesing commented 1 week ago

What remains for me is, that the JSF Controller seems to generate JSF ManagedBeans and not CDI beans in the ant project.

AdolfGalland commented 1 week ago

I strongly suggest, that you keep such accusations to yourself.

Keep in mind that English is not my first language, I'm sorry if what I wrote may sound rude or impolite.

I wanted to try the maven project way as suggested above to verify the results, but I'm completely stuck. If I use latest Payara server, 6.2024.6, I cannot even add jsf framework.

Cannot add jsf

Cannot select anything in that dialog window. Don't know if it is a Payara problem.

I then installed latest Glassfish, I can add jsf framework, but I'm not familiar with maven project and finally I cannot deploy due to a persistence unit problem. In fact there is no @PersistenceContext(unitName = "myPU") annotation and I don't know how to tell the name of the Persistence unit. Probably I will have no time for further investigation, I tried my best, I wrote this bug report to improve Netbeans, but due to my limited knowledge I cannot give much help.

AdolfGalland commented 1 week ago

I finally found the @PersistenceUnit annotation, I was looking in the wrong class. Application is correctly deployed but when I click the first link to list all items I get the same error: The class 'm2.mavenw2.BadgeController' does not have the property 'previous'. So generated code doesn't work in Glassfish 7.0.15 too.

In my first post I forgot another problem I saw. In the generated index.xhtml the namespace is: xmlns:h="jakarta.faces.html" and Glassfish correctly renders it as a jsf page. In all the other generated classes, such as List.xhtml, the namespace is: xmlns:h="jakarta.faces/jsf/html" and Glassfish renders it as plain html.

UPDATE After changing the namespaces to the form: xmlns:h="jakarta.faces.html" methods can be called without parantheses.

matthiasblaesing commented 1 week ago

For the code generation issues, this PR should help: #7539. A dev build is available from the checks page of the PR or directly: https://github.com/apache/netbeans/suites/25564462784/artifacts/1661001646.