Implicit expression language object "component" not working in jsf 2.2.6 - validation

I'm migrating a jsf 2.0 application to jsf 2.2.6. There is a extensive use of implicit EL object component as styleClass="#{component.valid?'':'err'}".
In jsf 2.2.6 (jsf-impl-2.2.6-jbossorg-4.jar) valid is not recognized, throwing "ServletException: The class 'javax.faces.component.html.xxx' does not have the property 'valid".
Is this functionality deprecated in jsf 2.x.x?
Can be related to JBoss EL?

It seems that you trying the component.valid on element that does not support it at all, for example the h:panelGroup does not have the isValid getter , while h:inputText does.
A workaround could be to abuse the validation status of another element in your page in order to apply the styleClass of another, see example:
<h:panelGroup styleClass="#{myComponent.valid ? '' : 'error'}">
<h:inputText id="input" value="#{myBean.myValue}" binding="#{myComponent}">
</h:inputText>
</h:panelGroup >

Finally found the reason of the exception. The problem was that I had a comment in the code containing "component.valid". Removing the comment resolves the problem.
<!-- styleClass="#{component.valid ? '': 'err' }" -->
It's tricky. The exception was not clear about the line of code.

Related

Custom JSF f:validateLenght message without using #FacesValidator class

In this example
<h:inputSecret value="#{contact.password}">
<f:validator validatorId="passwordValidator"/>
<f:validateLength minimum="8"/>
</h:inputSecret><br/>
If i put a password shorter than 8 letters i have j_idt10: Validation Error: Length is less than allowable minimum of '8' which is exactly what i want but i would like to rewrite the error message. I can do it using a custom #FacesValidator and i checked if there are some attribute in f:validateLength to do this but i didn't find any. Is writing a FacesValidator the only solution ?
Use message-bundle (similar but not same as resource-bundle) to override default conversion and validation messages:
https://stackoverflow.com/a/2668602/1072089

Apache Camel: How to properly nest a function?

In Camel's Simple documentation they say :
From Camel 2.9 onwards you can nest functions, such as shown below:
<setHeader headerName="myHeader">
<simple>${properties:${header.someKey}}</simple>
</setHeader>
Here is what I am trying to do:
<simple>${property.${property.prefix}variableName}</simple>
I am trying to access the exchange property whose name is:
exchange.getProperty("prefix", String.class) + "variableName"
But I'm getting this exception:
Caused by: org.apache.camel.language.simple.types.SimpleIllegalSyntaxException: ${ cannot accept or at location 22
${property.${property.prefix}variableName}
What am I doing wrong here?
I'm using Camel version 2.13.0.
I confirm the following code works fine with Camel 2.13.0:
from("...")
.setProperty("prefix", constant("pre-"))
.setProperty("pre-variable", constant("value"))
.setHeader("myHeader", simple("${property.${property.prefix}variable}"))
You may have special character in the prefix property that prevents proper resolution.

How to override OmniFaces default validation/conversion error messages?

I'm using some OminFaces (1.8.1) validators as for example,
<o:validateAllOrNone components="a b c d" showMessageFor="someComponent"/>
If at least one of the specified fields is left blank in which case it displays a default message like as shown below.
a, b, c, d: Please fill out all or none of those fields
I want to override such error messages in resource bundles especially to get a localized message.
Unlike JSF, no resource bundles are found in OmniFaces. Is this still possible to override this error message somehow?
You can use the message attribute for that.
<o:validateAllOrNone components="a b c d" showMessageFor="someComponent"
message="#{i18n['some.bundle.key']}" />
where i18n is the <resource-bundle><var> of your resource bundle.
Indeed, the OmniFaces ValidateMultipleFields components do not support providing those messages via <message-bundle> without the need to declare the message attribute everytime.
Coincidentally, 3 days ago I've for the upcoming OmniFaces 2.0 committed several changes in those validators which should make it possible to override the default message via <message-bundle> when using the component type as key. So in case of <o:validateAllOrNone> which has a component type of "org.omnifaces.component.validator.ValidateAllOrNone", you should be able to override it in the resource bundle as identified by <message-bundle> as follows:
org.omnifaces.component.validator.ValidateAllOrNone = {0} all or none!

EL in <sec:authorize> access attribute

Is it not possible to use EL in access attribute? I dislike to hardcode the role names in the tag, instead would like to use a constant. But it is throwing an exception saying:
org.apache.jasper.JasperException: abc.jsp(19,4) According to TLD or
attribute direc tive in tag file, attribute access does not accept
any expressions
Here is what I have in jsp(using unstandard taglib for constants):
<%#taglib uri="http://jakarta.apache.org/taglibs/unstandard-1.0" prefix="un"%>
<un:useConstants className="com.xxx.PrivilegeConstants" var="privilege" />
.....
<sec:authorize access="hasRole('${privilege.USER_ROLE}')"> // throwing ex here
security content here....
</sec:authorize>
Is there any other alternative? Thanks in advance...
Looks like the support was added later on. See the JIRA here. Using the version which adds this support should work, I guess.

Spring 2.5.6/WPS 6.1: < in an input field gets turned into < in the mapped field

A friend of mine asked me to take a look at a portlet he was developing.
The issue he's having is that when he enters a value like
1 < 2 > 3
in an input field he gets
1 < 2 > 3
in the mapped String field.
While a decent bit of his code is dubious I couldn't find any instances of him using a .replace function / setting defaultHtmlEscape to true.
I did debug his portlet, and it's already changed before it even enters the Controller.
I put a breakpoint in Springs dispatcherportlet and in the processAction it's already transformed.
> only gets parsed to < if it's preceded by < so it is most likely an escaping issue because it gets handled as an html tag but I couldn't find any code influencing that.
I'm not that familiar with Spring 2.5.6 (I use version 3), but I can't recall any similar issues.
It might be an issue with websphere portal 6.1 but that would surprise me since I can't find any similar issues. (I'm going to try and make a similar scenario tomorrow).
Any input would be appreciated.
(spring 2.5.6-SEC02, WebSphere Portal 6.1 without the latest feature pack)
Escaping XML refers to conversion of special characters like &, >, < and so on, into character entity codes like &, >, <, and so on. If a portlet relies on a URL generated by portlet tag library which is not XML escaped then set this container runtime option to false. In Portlet 2.0 specification, all URLs generated by portlet tag library are XML escaped by default.
your friend should have some escape feature in his portlet JSP like one below
<portlet:resourceURL var="inputURL" id="userValues" escapeXml="false" />

Resources