Does PrimeFaces has anything like o:param (solution to add complex parameter for outputFormat)? - jsf

The given problem is that passing complex parameter (see code example below) doesn't work in JSF.
<h:outputFormat value="Final result is: {0}">
<f:param>
<h:outputFormat value="{0} to {1}">
<f:param value="#{mngr.lowerBound}"/>
<f:param value="#{mngr.upperBound}"/>
</h:outputFormat>
</f:param>
</h:outputFormat>
I'm NOT looking for the solution that uses the ManagedBean, like this:
<h:outputFormat value="Final result is: {0}">
<f:param value="mngr.formattedParams />
</h:outputFormat>
However there is a proper solution that works in OmniFaces:
JSF-2. h:outputFormat. Complex f:param
I'm wondering if there is also a solution in PrimeFaces?

No PrimeFaces does not have this. There is no reason to either since OmniFaces has it. And they both target different aspects of JSF: ui component suite vs utility suite so fully complementary

Related

How to pass f:param to multiple h:link in composite?

I want to build a simple paginator component using GET link support and we can pass f:param to a composite using cc:insertChildren. see answer
The problem is i have multiple h:link which should all receive the params. But only the first one receives it in Mojarra. Even the documentation says its possible but may create duplicate id's which is not relevant with f:param
Rendering a facet is not working. Anyone knows why?
Site
<comp:paginator>
<f:param name="category" value="#{bean.category}/>
</comp:paginator>
Composite
<h:link rel="prev">
<cc:insertChildren/>
</h:link>
<h:link rel="next">
<cc:insertChildren/>
</h:link>
It seems not to be possible so I can at least create something ugly like this:
<comp:paginator
param1Name="" param1Value="" param1Converter=""
param2Name="" param2Value="" param2Converter=""
param3Name="" param3Value="" param3Converter=""
param4Name="" param4Value="" param4Converter=""
param5Name="" param5Value="" param5Converter=""
/>

How to use JSF navigation rules with ResourceBundle content

I have a multi-lingual site with content managed by ResourceBundles. How can I use JSF navigation to insert links to website sections using paragraph content.
Example 1: Desired HTML output
<p>Simply contact us to find out more.</p>
Example 2: Simple facelt to achieve the above
<p>Simply <h:link outcome="contact" value="contact us"/> to find out more.</p>
Desired result: Same but with ResourceBundle
Facelet
<p>
<h:outputText value="${template['paragraph']}">
<f:param>
<h:link outcome="contact" value="${template['contactUs']}"/>
</f:param>
</h:outputText>
</p>
ResourceBundle
paragraph=Simply {0} to find out more.
contactUs=contact us
The problem is not exactly the JSF navigation rules, but that you cannot use <f:param> to specify JSF components as bundle parameter, let alone plain vanilla HTML children. Also, please note that you cannot use <f:param> in <h:outputText>, but only in <h:outputFormat>.
In order to achieve the functional requirement anyway, you've to write down the HTML in escaped flavor as <f:param value> yourself.
<h:outputFormat value="#{template['paragraph']}" escape="false">
<f:param value="<a href='#{request.contextPath}/contact.xhtml'>#{template['contactUs']}</a>" />
</h:outputFormat>
or, if you'd like to utilize JSF ViewHandler#getBookmarkableURL() like as <h:link> is doing for its outcome attribute,
<h:outputFormat value="#{template['paragraph']}" escape="false">
<f:param value="<a href='#{facesContext.application.viewHandler.getBookmarkableURL(facesContext, '/contact', null, false)}'>#{template['contactUs']}</a>" />
</h:outputFormat>
Since you're not the first one who stumbled upon this and the workarounds are awkward, the JSF utility library OmniFaces has recently updated its <o:param> component with support to encode children as param value when no value is specified. From OmniFaces 1.5 on, you should be able to use it as follows:
<h:outputFormat value="#{template['paragraph']}" escape="false">
<o:param><h:link outcome="contact" value="#{template['contactUs']}" /></o:param>
</h:outputFormat>

Passing EL method expression as attribute of custom Facelets tagfile

I created a custom JSF tag:
<ui:composition>
<h:panelGroup>
<rich:dataScroller id="#{id}" for="#{table}" execute="#{table}"
page="#{scrollerPage}" render="#{table}-sc1" maxPages="5"
fastControls="hide" oncomplete="#{onCompl}" scrollListener="#{scrollListenerBean[scrollListenerMethod]}" />
<h:inputText value="#{scrollerPage}" id="#{table}-sc1" size="2">
<f:convertNumber integerOnly="true" />
</h:inputText>
<h:outputText styleClass="outputText"
value=" of #{scrollPagesCount} " />
<h:commandButton value="GO! " />
</h:panelGroup>
</ui:composition>
To pass the listener method, I used the solution suggested in a quite old blog:
<my:dataScroller id="idDS1" table="table1"
scrollerPage="#{bean.navigationHelper.scrollerPage}"
scrollPagesCount="#{bean.navigationHelper.scrollPagesCount}"
onCompl="initForm();"
scrollListenerBean="#{bean}"
scrollListenerMethod="aMethod" />
My questions are: is this the best way to do this? How can I make the method optional?
Thanks a lot for any Help! bye!
My questions are: is this the best way to do this?
That's the only way anyway, provided that you can only use standard JSF/EL facilities and you cannot create a custom taghandler.
You could however create a custom taghandler to convert the value expression to a method expression. The OmniFaces JSF utility library has a <o:methodParam> for exactly this purpose. See also the <o:methodParam> demo page.
You could then end up like:
<my:dataScroller ... scrollListener="#{bean.aMethod}" />
and
<o:methodParam name="scrollListenerMethod" value="#{scrollListener}" />
<rich:dataScroller ... scrollListener="#{scrollListenerMethod}" />
See also:
Dynamic ui include and commandButton
How can I make the method optional?
Theoretically, you could use JSTL tags to build the view conditionally. Something like:
<h:someComponent>
<c:if test="#{not empty fooAttribute}">
<f:attribute name="foo" value="#{fooAttriubte}" />
</c:if>
</h:someComponent>
But that's in the particular case of a special method expression listener attribute unfortunately not possible. There's no such thing as <rich:scrollListener> or something which allows you binding a RichFaces specific scrollListener as a separate tag to the <rich:dataScroller>. Best what you could do without creating custom taghandlers is duplicating the whole <rich:dataScroller> in two <c:if>s (or a <c:choose>); one with and other without scrollListener. This is too clumsy. You'd really better create a custom <my:richScrollListener> taghandler for this which you could then place in a <c:if>.

f:param tag attribute 'disable' is not work

I try to use <f:param> tag to build output link URL with parameters depending on some my conditions.
When I place this tag inside h:output link and try to set different values for 'disable' I see no effect.
Here the my code
<h:outputLink value="/WebApplication10/faces/index.xhtml">
Link1
<f:param disable="#{true}" name="name1" value="value1"/>
<f:param disable="#{false}" name="name2" value="value2"/>
</h:outputLink>
I expect to see only one param in url but I see both.
Using disable="true" instead of disable="#{true}" works for me.
So, it's either a bug in the tag documentation that it supports ValueExpression or a bug in the UIParameter class that it does not resolve it as a ValueExpression. I have at least reported issue 2102 for this.
Update: As a temporary hack/workaround, you could use <c:if> to control the inclusion of the <f:param> tag during view build time.
<h:outputLink value="/WebApplication10/faces/index.xhtml">
Link1
<c:if test="#{!true}"><f:param name="name1" value="value1"/></c:if>
<c:if test="#{!false}"><f:param name="name2" value="value2"/></c:if>
</h:outputLink>
Note that this is not going to work when this piece is embedded in a JSF iterated component such as <ui:repeat>, <h:dataTable> and on and the test condition depends on the iterated variable.
Use 'disble' instead 'disable'.
The reason is described here:
http://markmail.org/message/bmb2lek5mcx4ofp7

How to pass rich params to jsf for i18n?

I am using jsf to render my html pages and I am using the nifty resource bundle loading to add i18n to the various pages. The problem I am having is that with outputFormat you can not pass in any "rich" parameters. For instance this sentance:
This my favorite search engine, you should check it out.
It would be nice to do something like this:
<h:outputFormat value="#{bundle.favItemLineWithParam}>
<f:param>
<h:outputFormat value="#{bundle.searchEngine}>
<f:param>
<h:link value="http://google.com">
</f:param>
</h:outputFormat>
</f:param>
</h:outputFormat>
but that is not allowed, it would seem like the only option is to render the links in java with a backing bean or something. Any Ideas?
That's not possible. You need to use plain HTML in the bundle value and set escape="false".
favItem = This is my favourite {0}, you should check it out.
with
<h:outputFormat value="#{bundle.favItem}" escape="false">
<f:param value="search engine" />
<f:param value="http://google.com" />
</h:outputFormat>
Update:
Since version 1.5, it's possible with <o:param> of JSF utility library OmniFaces:
favItem = This is my favourite {0}, you should check it out.
searchEngine = search engine
with
<h:outputFormat value="#{bundle.favItem}" escape="false">
<o:param>#{bundle.searchEngine}</o:param>
</h:outputFormat>

Resources