I want to rewrite this http address using JSF tag:
Home
Into this:
<h:link value="HOME" class="dir" outcome="/module1/page/UserNavigation.xhtml" />
But when I test the page I get warning message Cannot match navigation case. That's because the address is pointing outside the module but it's correct.
Can I suppress that warning somehow?
<h:link> tag is used to generate plain anchor elements for JSF navigation cases only, by referring to a navigation case outcome in its outcome attribute, and is not intended to (can't) be used to navigate to any other resouces, even be them within the same web applcation, for which there is <h:outputLink> tag.
So, a navigation case in your example should be /module1/page/UserNavigation. On the other hand, you could change the tag to <h:outputLink> and change outcome for value attribute and it'll work smoothly.
Related
I'm getting this warning in my application
JSF1090: Navigation case not resolved for component j_idt51
What is the reason for this warning and how can I resolve it? The strange thing is that the component id j_idt51 is not in the rendered page. If I look to the HTML of the generated page there is no element with id j_idt51.
This warning will occur whenever you use an (implicit) navigation outcome in the outcome attribute of <h:link> or <h:button>, which does not represent a valid view ID.
E.g.
<h:link ... outcome="viewIdWhichDoesNotExist" />
<h:button ... outcome="viewIdWhichDoesNotExist" />
Additionally, the <h:link> will render a <span> element instead of an <a> element.
The solution is obvious: use a valid view ID, or make at least sure that the desired view is resolveable by ConfigurableNavigationHandler#getNavigationCase().
Note that some starters use for an unknown reason even a full URL like http://google.com as outcome value of <h:link>:
<h:link value="Go to Google" outcome="http://google.com" />
This abuse would then also yield exactly this warning. You should be using <h:outputLink> or just <a> instead.
As to the absence of a HTML element with the same ID as the JSF component, this may happen when you didn't explicitly specify the JSF component's id attribute. The JSF component ID does then not necessarily end up in the generated HTML output. Assigning those components a fixed ID should help better in nailing down the cause.
What is the proper value of outcome attribute of tag <h:link> to reference the current page (the page the tag h:link is written in)?
Following rules for return values of action methods i tried
outcome=""
outcome="#{null}"
outcome="#{''}"
but all of them ends up with error message This link is disabled because a navigation case could not be matched.
I use JSF 2.2 and I want to use default navifation (i.e. my faces-config.xml file contains just the root tag).
The outcome attribute should be completely omited:
<h:link value="self link" />
I have a Primefaces commandLink which I have used it many times in my application. Now I want to store it's URL in a bundle.property file to make it maintainable. which xhtml attribute should I use to redirect it?
I already tried things like:
actionListener="#{bundle.Myurl}"
action="#{bundle.Myurl}"
target="#{bundle.Myurl}"
Myurl also contains this: sales/index.xhtml
but none of them run as I want!
You shouldn't use command links for page-to-page navigation in first place. Use a normal link.
If you have an internal URL / (implicit) navigation outcome:
<h:link value="link" outcome="#{bundle.Myurl}" />
Or if you have an external URL:
<h:outputLink value="#{bundle.Myurl}">link</h:outputLink>
Your attempts failed because the actionListener and action attributes are declared as MethodExpression attributes, meaning that any EL will be interpreted as a bean action method. The target attribute has an entirely different meaning, which is exactly the same as the generated HTML <a> element has.
See also:
When should I use h:outputLink instead of h:commandLink?
I use primefaces 3.1, in menubar i want to add icon .When user click the icon,it will be direct to the home.jsf page.Below,when user click the icon,page goes to index but its url seems different.Thanks for any helps.
<p:menuitem >
<p:commandLink action="home.jsf" >
<p:graphicImage height="24"
width="24"
value="resources/images/home.ico"
style="border:none" />
<p:commandLink>
</p:menuitem>
Upon submitting of <h:form> by any command components like <h/p:commandButton>, or <h/p:commandLink> JSF performs a forward and not a redirect. That is why your URL stays the same. Just append ?faces-redirect=true to your action attribute and it'll work as expected. For the distinction visit BalusC's answers to What is the difference between redirect and navigation/forward and when to use what? and How to navigate in JSF? How to make URL reflect current page (and not previous one).
That said, it's a poor practice to perform navigation by using command components. Use <h:link> or <h/p:button> components instead. They trigger a get request to the navigation case outcome, thus, your URL will change. Command components are designed to trigger server actions and not performing plain navigation. For more information consult BalusC's answer to When should I use h:outputLink instead of h:commandLink?.
I would like to understand what are the semantics behind appending the "?faces-redirect=true" in the action property of a <h:commandlink> tag in JSF2.0. Whether with it or with out it, the application indeed navigates to the target page specified in the action. So at first glance it seems that the only effect is cosmetic, i.e. to provide feedback to the user (if he is looking at the browser's visited URL) that he has moved to a new page. But if it is so innocuous and side-effects-free I cannot see why it is not the default behaviour. I suspect that it has to do with the post-based mechanism of JSF2.0. I 've noticed when browsing through a JSF application that the URLs one sees at his browser (when ?faces-redirect=true is not used) are the ones of the "previous" "page".
meta-NB. I am behind a firewall and plagued with the "SO requires external JavaScript from another domain" issue so I apologize for the absence of formatting. I will also provide feedback on your answers in a few hours, when I can access from another domain.
Page-to-page navigation should not be performed using POST at all. You should be using normal <h:link> or <h:button> for this instead of <h:commandLink> or <h:commandButton>.
So instead of
<h:commandLink value="Next page" action=nextpage.xhtml?faces-redirect=true" />
you should actually be using
<h:link value="Next page" outcome="nextpage.xhtml" />
This has the major benefit that the website is now SEO friendly. Searchbots namely doesn't index forms.
Use the <h:commandLink> only if you need to submit a form with some user input. But more than often the result is just presented in the same page, if necesary conditionally rendered/included. Only on successful submits which absolutely needs to go to a different page (e.g. login/logout), you should indeed be sending a redirect. This is the so-called Post-Redirect-Get pattern.
See also
How to navigate in JSF? How to make URL reflect current page (and not previous one)
When should I use h:outputLink instead of h:commandLink?