Java, JSF, PrimeFaces

Submit on Enter in JSF

Hi,

if you want to make a form submit with executing your action in JSF, what you can do is as follows:

<h:commandButton id="hidden" style="width:0px;height:0px;border:none" action="#{bean.doSth}" />

this is a hidden button and will execute your method.

Btw, if you use style=”display:none;”, it does not work in ie 🙂

Java, JSF, Spring

Remember me in Spring Security

Hi,

I love Spring when it is very easy to add new stuff to your current projects. Recently I was asked to add Remember me checkbox to login page. If you are using Spring Security what you just need to do is as follows:

add this to your spring xml : <remember-me key="Your_key_with_values_like*!casAA='0401./e;2009NrI"/>

and add a checkbox to your login page ( id is important here ) : <h:selectBooleanCheckbox id="_spring_security_remember_me" />

and that is. Spring will do all the work for you.

Just remember if you have an exception about transactions, just add a @Transactional to your method which loads the user from the DB.

Java, Other

Comparing texts based on a locale

Hi,

if you want to sort your text based on a local like in my case it was turkish, you can use Collator class.
for example, in turkish ç character is between c and d, but if you use regular search, or use java.util.String’s compare method, ç will come after z.

so what you can do is as follows:

Collator collator = Collator.getInstance(new Locale("tr"));
return collator.compare(name,otherObject.name);

this should do the trick.

Java, JSF, PrimeFaces, Seam, Spring

Integrating JBoss EL with JSF

JBoss EL is a powerful tool if you are using JSF. You can pass parameters to methods in JSF with it. It is my favorite tool right now while developing with JSF. I thought it was coming with Seam only, I mean I thought that you cannot use it without Seam but then in a PrimeFaces-Spring-Hibernate project I needed this. It turns out that you can use JBoss el w/o Seam also and it is very easy to integrate.

1. Just download JBoss EL jar to your web-ing/lib folder, or add it as a dependency in your pom.xml file ( if you’re using maven)

and put this in your web.xml file:

<context-param>
<param-name>com.sun.faces.expressionFactory</param-name>
<param-value>org.jboss.el.ExpressionFactoryImpl</param-value>
</context-param>

that is it. now you can do a lot of tricks like :

<ui:repeat var="day"  value="#{bean.user.getWorkingDays(bean.periodStartDate, bean.periodEndDate)}">
<p:commandButton value="#{day}" action="#{bean.selectDay(day)}"/>
</ui:repeat>

yes, like above all kind of tricks can be done now.