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);
 }
Advertisements

About Paul C

I am a Senior Java programmer/Web Technologies, Play in a band called Mandolin Monday, I have a cat and I live on a boat.

Posted on October 25, 2013, in glassfish, Primefaces and tagged , , , , , , , , . Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: