Is it possible to use <h:link> tag to link self in JSF? - jsf

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" />

Related

pass bean action as attribute in custom tag inside ui:repeat [duplicate]

In my JSF 1.2 project, I have created a facelet tag file and defined an inputText that has actionListener attribute to which I need to pass the backing bean method name.
I tried defining a variable actionListener="#{actionListener}" in the tag file. In my xhtml where I call the component, when I pass the value as
actionListener="#{myBean.preFillData}"
tag file treats it as a property and errors out indicating no property 'preFillData' found. If I change it to
actionListener="#{myBean.preFillData()}"
then there is a parse error in the tag file because it doesnot like parenthesis to indicate method name.
How do we pass method name to the tag file?
Thanks
PT
Passing method expressions is not supported in tag files. Only since JSF 2.0 it's possible with so-called composite components.
What you can do is to separate the bean reference and the method name so that you can use the brace notation to invoke the method. I'm only not sure if that works out for an actionListener, you normally don't use that to invoke actions, but it should definitely work for an action.
E.g.
<my:tag ... bean="#{myBean}" actionMethod="preFillData" />
with inside tag.xhtml
<h:commandButton ... action="#{bean[actionMethod]}" />
Only if you happen to use JSF 2.0 on Facelets, then you can use <o:methodParam> to pass a method expression to a tag file. See also a.o. Dynamic ui include and commandButton.

JSF h:link rendered span [duplicate]

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.

How to redirect to a page using Primefaces commadLink and bundle.properties file

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?

JSF set property on ManagedBean in included Faceltes page

I am new to JSF and getting very confused doing something trivial. I am making up this example here to elaborate what I am want to do:
I have a xhtml fragment, say, stockQuoteFragment.xhtml, which is backed by a ManagedBean, say, StockQuoteService.java. StockQuoteService.java has property stockID and a method getStockQuote() which has all the logic to get the stockQuote for the value set on stockID property. stockQuoteFragment.xhtml displays #stockQuoteService.stockQuote.
Now I have another page Home.xhtml page with backing bean HomeBackingBean.java with a method getUserFavoriteStockID(). I want to include content of stockQuoteFragment.xhtml in Home.xhtml passing in the value of #homeBackingBean.userFavoriteStockID to StockQuoteService.setStockID().
I am not sure how to do this in JSF/Facelets. With simple JSPs I could do this easily with a JSP include and include parameters
No.
...According to TLD or attribute directive in tag file, attribute var does not accept any expressions.
I have just tried it.
But if you use pure XML based JSF with tags, you can easily use <ui:param> as discussed here. I use JSF in JSP and for me there is no help (<c:set> is mostly useless).
Can I just do this in Home.xhtml before I ui:include stockQuoteFragment.xhtml into it:
<c:set var="#{StockQuoteService.stockID}" value="#homeBackingBean.userFavoriteStockID"/>
will that work?

Cannot match navigation case in JSF page

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.

Resources