JSF resource versioning - jsf

I am trying to put versioning around the resources in an application.
If I do like this resources/js/1_0_0/mainscript.js
It does not work. It says RESOURCE_NOT_FOUND
but when I do like this
resources/js/mainscript.js/1_0_0.js
It works. I do not like the way it is organized in the second way. First one looks cool. Any Idea?
I am using Tomcat 7.0, JSF 2.0.9
Update: I was checking primefaces-2-2.1.jar. Since when I checked the page source, I saw this
/javax.faces.resource/jquery/jquery.js.xhtml?ln=primefaces&v=2.2.1">
Then I looked at META-INF/resources/primefaces/jquery/jquery.js
They did not have any versioning in there but how did it append v=2.2.1 in the head

If I do like this resources/js/1_0_0/mainscript.js
It does not work. It says RESOURCE_NOT_FOUND
This will work if you specify js as library name.
<h:outputScript library="js" name="mainscript.js" />
However, this is not the proper usage of a resource library. Rather introduce one.
resources/default/1_0_0/js/mainscript.js
Then you can specify it as follows:
<h:outputScript library="default" name="js/mainscript.js" />
They did not have any versioning in there but how did it append v=2.2.1 in the head
It's done by PrimeResource which kicks in on resource requests with ln=primefaces parameter. Its getRequestPath() has the following implementation:
#Override
public String getRequestPath() {
return super.getRequestPath() + "&v=" + Constants.VERSION;
}
Where Constants is the PrimeFaces specific constants file which is updated with every PF version.

Related

Custom addon component not found

I'm trying to create a component within an addon. Everything works fine during impex process (contentslot, pagetemplate etc.) but it doesn't get rendered when accessing the page.
I've followed these steps but my controller isn't even get called.
#Controller("ConfirmationComponentController")
#RequestMapping(value = ControllerConstants.Actions.Cms.ConfirmationComponent)
public class ConfirmationComponentController extends AbstractCMSAddOnComponentController<ConfirmationComponentModel> {
#Override
protected void fillModel(HttpServletRequest request, Model model, ConfirmationComponentModel component) {
}
}
I've added the component's jsp in "WEB-INF/views/responsive/cms/.." from the addon module but I keep getting this error:
File [/WEB-INF/views/addons/trainingcore/responsive/cms/confirmationcomponent.jsp] not found
P.S.: I've managed to get the component controller to be called, but the getView() is returning a wrong path and that's why the component is not getting called. Any help? Thank you very much:)
Should this component to be created in addon *-items.xml?
What you need to know first
Using addons is a complicated endeavor in hybris. You need to know, that the resources are not used in the addon, but they are copied (during build process) to your storefront, where they are used.
All classes in
myaddon/acceleratoraddon/web/src/
will be copied to:
mystorefront/web/addonsrc/myaddon/
All resources in
myaddon/acceleratoraddon/web/webroot/
will be copied to corresponding folders:
mystorefront/web/webroot/WEB-INF/_ui-src/addons/myaddon
mystorefront/web/webroot/WEB-INF/tld/addons/myaddon
mystorefront/web/webroot/WEB-INF/messages/addons/myaddon
mystorefront/web/webroot/WEB-INF/tags/addons/myaddon
mystorefront/web/webroot/WEB-INF/views/addons/myaddon
That means
That means, that the effective path to your component jsp will not be something like:
/WEB-INF/views/cms/...
but will be something like:
/WEB-INF/views/myaddon/cms/...
The path myaddon will depend on the extension your component is declared in. So if you declare it in trainingcore-items.xml it will be
/WEB-INF/views/trainingcore/...
If you declare it in myaddon-items.xml it will be
/WEB-INF/views/myaddon/...

Double call to action - prettyfaces - jsf

I am making a page in which I call a PrettyFaces page-load action method:
<url-mapping id="informes-perfil">
<pattern value="/informes/#{informesPerfilMB.codigo}" />
<view-id value="/faces/informes_perfil.xhtml" />
<action onPostback="false">#{informesPerfilMB.load()}</action>
</url-mapping>
For some reason, the informesPerfilMB.load() action is called twice, and the parameter value in the second call is 'null' or 'RES_NOT_FOUND'.
Here is my load method:
public void load() {
if (isPostBack) {
isPostBack = false;
try {
System.out.println(codigo);
informe = informeEJBServiceLocal.getByCodigo(codigo);
this.buscarInformeIngreso();
this.buscarInformeOtroIngreso();
} catch (EJBServiceException e) {
e.printStackTrace();
}
}
}
The isPostBack variable is initialized to false, so this should prevent the method from being called again, but for some reason it is.
This code first prints String: dcc509a6f75849b.
Then when the load is repeated, it prints this: RES_NOT_FOUND
I hope this code helps explain what is happening enough to solve my problem, Thanks.
I've seen this happen on my similar system in the past. I think it's an interaction between faces and prettyfaces with missing files. The RES_NOT_FOUND part comes from the network traffic. There's some likely faces resource (or stylesheet) that it's trying to find in libraries and when it can't, it essentially causes the browser to go to the URL /informes/RES_NOT_FOUND. For some reason, it would often find that resource if I refreshed the page and wouldn't issue a RES_NOT_FOUND URL.
First, I'd open up the page source, and you'll find RES_NOT_FOUND, likely along with the stylesheets. Given the position of it, you might be able to correlate it to the resources loaded in your xhtml files and see which one's missing. If that doesn't help, try the developer tools and see which resources are loaded and which are not. Then make sure the resource is present, deployed, and is in the correct location.
If it's not something that you can control (like a library resource), you can always make sure your setCodigo function ignores values of "RES_NOT_FOUND".
public void setCodigo(String value) {
if (!"RES_NOT_FOUND".equals(value)) {
this.codigo = value;
}
}
You may be able to modify your security or servlet-mapping settings (in WEB.XML) to prevent URLs ending in RES_NOT_FOUND from getting to the prettyfaces pages, but I don't know enough about it to do that.
First, the reason your isPostBack variable is called twice is most likely because you have two instances of the bean, not one singleton instance. There are a few reasons this could be happening:
Your bean is request scoped and multiple requests are being made to the page.
Your bean is being created multiple times by parts of your application that use it and call the load() method.
I also believe it is possible your method is being called twice because of the way you have written your EL expression (I'm not 100% sure):
<action onPostback="false">#{informesPerfilMB.load()}</action>
^^
Note the parenthesis at the end of your method expression. I believe this will force EL to evaluate the method when the expression is evaluated. Your method expression should look like this:
<action onPostback="false">#{informesPerfilMB.load}</action>
You should also check for other places in your application where this method might be called.
Please let me know if this helps.

Autoloading a class in Symfony 2.1

I'm porting a Symfony 1.2 project to Symfony 2.x. I'm currently running the latest 2.1.0-dev release.
From my old project I have a class called Tools which has some simple functions for things like munging arrays into strings and generating slugs from strings. I'd like to use this class in my new project but I'm unclear how to use this class outside of a bundle.
I've looked at various answers here which recommend changing app/autoload.php but my autoload.php looks different to the ones in the answers, maybe something has changed here between 2.0 and 2.1.
I'd like to keep my class in my src or app directories as they're under source control. My vendors directory isn't as I'm using composer to take care of that.
Any advice would be appreciated here.
Another way is to use the /app/config/autoload.php:
<?php
use Doctrine\Common\Annotations\AnnotationRegistry;
$loader = require __DIR__.'/../vendor/autoload.php';
$loader->add( 'YOURNAMESPACE', __DIR__.'/../vendor/YOURVENDOR/src' );
// intl
if (!function_exists('intl_get_error_code')) {
require_once _DIR__.'/../vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs/functions.php';
$loader->add('', __DIR__.'/../vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs');
}
AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
return $loader;
Just replace YOURNAMESPACE and YOURVENDOR with your values. Works quite well for me, so far.
You're correct, I stumbled upon the changes in autoload from 2.0 to 2.1. The above code works fine with the latest version, to which I upgraded my project ;-)
For a simple case like this the quickest solution is creating a folder (for example Common) directly under src and put your class in it.
src
-- Common
-- Tools.php
Tools.php contains your class with proper namespace, for example
<?php
namespace Common;
class Tools
{
public static function slugify($string)
{
// ...
}
}
Before calling your function do not forget the use statement
use Common\Tools;
// ...
Tools::slugify('my test string');
If you put your code under src following the proper folder structure and namespace as above, it will work without touching app/autoload.php.

Richfaces: NoSuchFieldElementException AjaxChildrenRenderer for HTML Tag

I use richfaces 3.3.3.Final with Seam and facelet.
I have plugged a profiler on my application and I have a weird behavior.
When I log all exceptions thrown by the application, I have more than 10 000 NoSuchFieldElementException in 10 minutes.
After many search, I found the problem:
When I started an ajax request by a4j:support, the NoSuchFieldElementException is thrown by the AjaxChildrenRenderer in these lines (199-202):
String componentType = (String) component.getClass().getField("COMPONENT_TYPE").get(null);
result = _specialComponentTypes.contains(componentType);
The component variable is a UIInstructions and it has no "COMPONENT_TYPE" field. So, the exception is normal.
This exception is thrown for each html block contained in my page. For example:
<h2>Test</h2>
<span></span>
When I reRender a block with html tag, the exception is thrown.
I have very complex page, so I get many of this exceptions.
How I can do to avoid this exception ? May be a parser option to avoid to go in this class for html block.
Thanks for your help.
As a temporary solution, you could modify the source code to add an instanceof check which should skip that block and then ship the modified source code with your webapp. Ship it either as a single class with identical package/class name in web project itself (javadoc-document it properly), which would always have preference in classloading over the one in the JAR, or as a modified and rebuild JAR file.
if (!(component instanceof UIInstructions)) {
String componentType = (String) component.getClass().getField("COMPONENT_TYPE").get(null);
result = _specialComponentTypes.contains(componentType);
}
As a lasting solution, you should report it as a performance issue to the RichFaces guys so that they get it fixed and release a new update, but I don't think that they will prioritize 3.3.x updates that much. I.e. it might take longer than you'd expect.

Bean Autowiring problem

I am starter in mutithreading. I am trying to index my data into solr.For that I was writing the following code
I am getting null pointer exception in the line highlighted
You need to add the following:
<context:annotation-config/>
You need to set the path for autowiring package scan and in your case it will be:
<context:component-scan base-package="a.b.c" />
After it you need to mark the class as candidate for autowiring:
#Component("indexTask")
#Scope("prototype")
IndexTask implements Callable<IndexObject>
{
//ommited
}
Next you can remove indexTask bean configuration from xml file. your package will be created automatically.
Hope it helps.
Autowiring doesn't happen automatically, you need to configure it. See the Spring docs for detail, but essentially you need to add
<context:annotation-config/>

Resources