Omnifaces无扩展名URL配置后<h:link>使用问题咨询
<h:link> Issues with OmniFaces FacesViews Extensionless URLs Let's walk through the most common fixes for your <h:link> problem when using OmniFaces FacesViews:
1. Fix Your <h:link> Outcome Value
The biggest mistake people make here is referencing the physical file path instead of the extensionless URL mapped by FacesViews. Since your entries.xhtml lives in /WEB-INF/faces-views, FacesViews exposes it at /context/entries — so your <h:link> should target this clean path directly.
Use either of these correct syntaxes:
<!-- Absolute path (most reliable, works from any page) --> <h:link value="View Entries" outcome="/entries" /> <!-- Relative path (works if current page is in the same logical root) --> <h:link value="View Entries" outcome="entries" />
Never include .xhtml or the /WEB-INF/faces-views prefix in the outcome — FacesViews handles the mapping behind the scenes automatically.
2. Double-Check FacesViews Defaults (If You Customized Them)
While your setup should work with default settings, confirm you haven't overridden critical parameters in web.xml:
- Ensure
org.omnifaces.FACES_VIEWS_SCAN_PATHSis either unset (defaults to/WEB-INF/faces-views) or explicitly set to your target directory. - Verify
org.omnifaces.FACES_VIEWS_EXTENSION_ACTIONis set toREDIRECT_TO_EXTENSIONLESS(the default) to enforce clean URL generation.
3. Rule Out URL Mapping Conflicts
Make sure no other servlets, filters, or custom mappings in your web.xml are handling the /entries path. Conflicting mappings can block FacesViews from resolving the URL generated by <h:link>.
4. Upgrade to the Latest OmniFaces Version
Older OmniFaces releases might have edge-case bugs with FacesViews and <h:link> URL generation. Upgrading to the latest stable version can resolve unexpected behavior.
5. Test with a Minimal Example
If the issue persists, narrow it down with a simple test:
- Add a
test.xhtmlfile to/WEB-INF/faces-views - Add
<h:link outcome="/test">Test Link</h:link>to your homepage - Check if the generated URL is
/context/test(correct) or something malformed (incorrect)
This helps you confirm if the problem is specific to your entries page or a broader configuration issue.
内容的提问来源于stack exchange,提问作者cpliu338

