Category Archives: Primefaces

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

Primefaces Tree in a layout or panel doesn’t work

I must be losing more hair than anything. The tree function in a layout doesn’t work, although the backing bean is called the selectedItems array passed to it is empty. So here’s the fix.

Your code now looks like this probably (or something like it).

<p:panel style="height:80%">   <p:tree selection="#{indextree.selectedNodes}"
 update="Map" propagateSelectionUp="true" propagateSelectionDown="true"
 nodeSelectListener="#{indextree.onNodeSelect}" id="tree"
 style="font-size:12pt" selectionMode="checkbox" value="#{indextree.root}" var="node"> <p:treeNode> <h:outputText value="#{node}"/> </p:treeNode>
</p:tree>
</p:panel>

So simply create another xhtml file and put the tree in it on it’s own. In this case I called it treeTest.xhtml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:p="http://primefaces.prime.com.tr/ui" xmlns:h="http://java.sun.com/jsf/html"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:f="http://java.sun.com/jsf/core">
<f:view contentType="text/html"><h:head>
<title>Tracking</title>
</h:head>
<h:body style="font-size:8pt" >
<h:form id="boris" enctype="multipart/form-data">
<p:tree selection="#{indextree.selectedNodes}" update="Map" propagateSelectionUp="true" propagateSelectionDown="true" nodeSelectListener="#{indextree.onNodeSelect}" id="tree" style="font-size:12pt" selectionMode="checkbox" value="#{indextree.root}" var="node">
<p:treeNode>
<h:outputText value="#{node}"/>
</p:treeNode>
</p:tree></h:form></h:body>
</f:view>
 </html>

Now in your original file replace your tree code with an iframe! Tada, it all works! (note it should have < at the start and > at the end but wordpress goes a bit mad if I do that.

iframe src="treeTest.xhtml" style="height:80%;border-style:none;border-width:1px;" ></iframe

By the way this is fixed in the latest V3.0M