Blog Archives

Java EJB passing string parameters from the front end.

Firstly, my apologies I’ve not been very active writing for the blog, I have been building a huge enterprise application at my work  that handles billions of records of data, it’s been keeping me VERY busy.

Recently I’ve been working on a project which has a “CRUD” module as part of it (to save me time), the software generates a complete Grid, editing forms, adding ‘thing’.

I had real problems because I wanted to pass a joined string parameter.

It was called from a prime faces menu.

<p:menuitem value="Edit counterfiet serial numbers" 
 ajax="true" 
 update="CRUDDLGDIALOG"
 actionListener="#{cRUD.init(
'dateofreport=timestamp,reportedby='+srs.thisUser.username))}" 
 onclick="CRUDDIALOG.show();"/>

Ofcourse this did not work, for some reason the backing bean thought that I was trying to add two numbers together… WHY????

So the solution, write a new function in the backing bean to join the two strings together.

<p:menuitem value="Edit counterfiet serial numbers" 
 ajax="true" 
 update="CRUDDLGDIALOG"
 actionListener="#{cRUD.init(
cRUD.stringJoin('dateofreport=timestamp,reportedby=',srs.thisUser.username))}"
 onclick="CRUDDIALOG.show();"/>

Here is the backing bean code. Note that I have two backing beans cRUD for managing the CRUD form and SRS which is a general purpose backing bean for the application. I definitely did not want to have one mixed into the other because it was very useful to have a CRUD system I could use when generating any EJB application.

public String stringJoin(String string1,String string2) {
 return string1.concat(string2);
 }