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

Consider deprecating and dropping h:form prependId #1972

Open
BalusC opened this issue Sep 6, 2024 · 6 comments
Open

Consider deprecating and dropping h:form prependId #1972

BalusC opened this issue Sep 6, 2024 · 6 comments

Comments

@BalusC
Copy link
Member

BalusC commented Sep 6, 2024

Historically, h:form prependId=false was introduced in JSF 1.2 as sort of patch in order to be able to submit to j_security_check using a JSF form. Since introduction of programmatic login API HttpServletRequest#login() in Servlet 3.0, released at the same time as JSF 2.0, the prependId=false has become unnecessary as people can just use HttpServletRequest#login() instead of submitting to j_security_check. Moreover using prependId=false breaks the in JSF 2.0 introduced f:ajax and composite components as well as the in JSF 2.3 introduced f:websocket because it causes the findComponent to not anymore work within naming containers, see also among others #573.

These days, people don't anymore use h:form prependId=false specifically to be able to submit to j_security_check, but they abuse prependId=false generally to be able to use ids in CSS selectors without the need to escape them. But these people actually need to be re-educated about CSS best practices so they don't anymore need ids in CSS selectors for non-unique elements/components, see also among others https://stackoverflow.com/a/5882502.

All in all, using h:form prependId=false in JSF 2.x or newer is a red flag and is always discommended. We should deprecate the attribute and eventually remove it so people won't anymore fall into the trap. Do note that this attribute is absent in all naming container components other than UIForm and the community never reasonably requested for standardizing it in NamingContainer.

@melloware
Copy link

I still use this for PFE credit card component. There was a limitation in the JS library where the ids had to be exact like number, expiry, etc.

It only works with prependID false

@BalusC
Copy link
Member Author

BalusC commented Sep 11, 2024

Yeah I remember a similar case with a postcode/address autocomplete JS library. I just forked and rewrote it to allow specifying client IDs as option rather than adhering to predefined client IDs. Tight coupled libraries are bad. If it's public and open for support, post a issue / feature request. Else probably better look for another one allowing that option.

Note that it would still fail if your form is in turn nested in another naming container such as p:tabView. Or even when used in a (Liferay) Portlet where the UIViewRoot is a NamingContainer.

@melloware
Copy link

You are right i might look into just fixing the credit card JS which isn't really receiving updates anyway these days!

@BalusC
Copy link
Member Author

BalusC commented Sep 11, 2024

You are right i might look into just fixing the credit card JS which isn't really receiving updates anyway these days!

It would probably be cool if you simply pass client ID of a common parent component and let the script figure out it based on autocomplete="..." values which are already predefined by standard spec ;)

@volosied
Copy link
Contributor

volosied commented Oct 3, 2024

This seems fine to me. Although some of our tests use prependId=false, but they can be refactored.

Would the deprecation be targeted for 5.0 and removed in 6.0?

@BalusC
Copy link
Member Author

BalusC commented Oct 19, 2024

Yeah, deprecate as early as possible. Along with a WARN log when it's being used to make the developer aware.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants