How to reference JSF image resource as CSS background image url

When importing CSS stylesheets by <h:outputStylesheet>, the stylesheet is imported and processed by the FacesServlet through /javax.faces.resource/*. Look at the generated <link> element pointing to the stylesheet in question and you’ll understand. You have to change all url() dependencies to use #{resource[‘library:location’]} instead. JSF will then auto-substitute it with the right path. Given your folder … Read more

Are @ManagedBeans obsolete in JavaEE6 because of @Named in CDI/Weld?

In short, @ManagedBean makes sense for applications that use JSF but do not use JSR 299 (whatever the reason is). Below a longer explanation from Gavin King: Re: Comparisons to @ManagedBean annotations in JSF2?: While looking through the Weld examples, and the older WebBeans documentation, it looks like a competitor to the new @ManagedBean JSF … Read more

Redirect to external URL in JSF

Either just mention the URL directly in <a> or <h:outputLink>. <a href=”https://stackoverflow.com”>Go to this site!</a> <!– or –> <h:outputLink value=”https://stackoverflow.com”>Go to this site!</h:outputLink> Or, if you need to to invoke a bean action using <h:commandLink> like below, <h:form> <h:commandLink value=”Go to this site!” action=”#{bean.redirect}” /> </h:form> then use ExternalContext#redirect() in action method. public void redirect() … Read more

Defer loading and parsing of PrimeFaces JavaScript files

Use <o:deferredScript> Yes, it is possible with the <o:deferredScript> component which is new since OmniFaces 1.8.1. For the technically interested, here’s the involved source code: The UI component: DeferredScript The HTML renderer: DeferredScriptRenderer The JS helper: deferred.unminified.js Basically, the component will during the postAddToView event (thus, during the view build time) via UIViewRoot#addComponentResource() add itself … Read more

Conversion Error setting value for ‘null Converter’ – Why do I need a Converter in JSF?

Introduction JSF generates HTML. HTML is in Java terms basically one large String. To represent Java objects in HTML, they have to be converted to String. Also, when a HTML form is submitted, the submitted values are treated as String in the HTTP request parameters. Under the covers, JSF extracts them from the HttpServletRequest#getParameter() which … Read more

Load images from outside of webapps / webcontext / deploy folder using or tag

To the point, it has to be accessible by a public URL. Thus, the <img src> must ultimately refer a http:// URI, not something like a file:// URI or so. Ultimately, the HTML source is executed at enduser’s machine and images are downloaded individually by the webbrowser during parsing the HTML source. When the webbrowser … Read more

Display Current Date on JSF Page

You could register an instance of java.util.Date as a request scoped bean in faces-config.xml. <managed-bean> <managed-bean-name>currentDate</managed-bean-name> <managed-bean-class>java.util.Date</managed-bean-class> <managed-bean-scope>request</managed-bean-scope> </managed-bean> This way it’s available as #{currentDate} without the need for a custom backing bean class. Update: the JSF utility library OmniFaces has such a bean already registered as #{now}. So if you happen to use OmniFaces … Read more

Session timeout and ViewExpiredException handling on JSF/PrimeFaces ajax request

Exceptions which are thrown during ajax requests have by default totally no feedback in the client side. Only when you run Mojarra with project stage set to Development and use <f:ajax>, then you will get a bare JavaScript alert with the exception type and message. But other than that, and in PrimeFaces, there’s by default … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)