vineri, 17 aprilie 2015

[OmniFaces utilities (2.0)] Get the URL for an application resource mapped to the specified path


[OmniFaces utilities] The getResource() method returns a URL for an application resource mapped to the specified path, if it exists; otherwise, return null.

Method:
See also: Faces#getContext()
Usage:

import org.omnifaces.util.Faces;
import java.net.URL;
...
try {
    // e.g. file:/D:/wildfly/standalone/deployments/MyApp.war/resources/default/images/rafa.jpg
    URL url = Faces.getResource("/resources/default/images/rafa.jpg");
} catch (MalformedURLException ex) {
    Logger.getLogger(LoginBean.class.getName()).log(Level.SEVERE, null, ex);
}

Niciun comentariu:

Trimiteți un comentariu