Raj Bhandari

Ranch Hand
+ Follow
since Oct 19, 2005
Merit badge: grant badges
For More
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Raj Bhandari

Raza, tks for the reply.
Any other suggestions by anyone are welcome :-)
Hi everyone,
Perhaps a simple question.
Say for Example I have a createStudent method as follows in my bean:

Now when I call this method in my action(struts) everything works fine but what is bothering me is that I don't want the error from the EJB layer to come up one by one.
So, on the UI when I forget entering both name and age.
I get error saying "name is required" and when I fill that, I get "age is required". Is there a good way I can add up the messages and send it back to the client/action calling it. Should I be throwing Exception or something else? Is there a way to include lists in exceptions?

Note- I understand I can do validation on client side also for required fields. But this is a simple example; there could be business logic validations on EJB and I want to add them up and send all at once.

still stuck on this.. can anyone help?
15 years ago
Hey Karthik,

What you have mentioned is pretty common and people generally do that - what varies is where they do it or if they use any framework for that. What you can do is create a singleton converter/translator class which contains all the methods to do converting from your web tier objects to ejb objects and vice versa.
And this will clean up your action to something like this:

RegistrationBean regBean = getRegistrationBeanFromDB();
RegistrationForm regForm = Converter.getRegistrationFormFromBean(regBean);

I'll be following this thread to see if there are better ways.

[ August 20, 2008: Message edited by: Raj Bhandari ]
15 years ago
Ok, I've narrowed the problem down.
And its coming out that tiles insertDefinition and struts tag don't work together.


searchEmployee.jsp - This works

searchEmployee.jsp - This also works

searchEmployee.jsp - This does NOT work

Any suggestions?
[ August 08, 2008: Message edited by: Raj Bhandari ]
15 years ago
Hi Jesus,

Tks for the reply. The example link you gave above is for Struts 1.x and I've always done it myself (used solution 1) and it worked like a charm. However its not working when I apply the same approach for Struts 2.x using tiles:insertDefinition.
Thats where I'm stuck.
15 years ago
Any help please?
15 years ago
That tile will be applicable to only that package where it is in.
If you are using different packages, then the common practice is to have one package contain all the common things (like this result-type info) and let your other packages extend it.

not sure about the beta vesion thing..
15 years ago
Any help please?
15 years ago
It should go in struts.xml like this:

Hope this helps!
15 years ago
Hi everyone,

I have this wierd issue with tiles. Please let me know what could be wrong.

I want to insert a tile (a jsp page) into another tile (a jsp page) and so am using <tiles:insertDefinition name="status.index"/>

This is my config (simplified):

So now everything works fine and I can see the static contents of the status.jsp file which just contains text like ('this is a test').

But if I try to insert the line <tiles:insertDefinition name="status.index"/> in searchEmployee.jsp instead of the layout.jsp, things fail and I get nullpointerexceptions and all.

I'm now wondering can we use <tiles:insertDefinition name="status.index"/> in a jsp that is used for <tiles:insertAttribute name="body" />??

Basically then whats the equivalent of <tiles:insert> in tiles 1.x to be used in struts 2 tiles.

15 years ago
Hi everyone,

I have a design ques and I'm sure its very common.
Suppose I have a Entity which can contain a collection of other enitities. Eg:
<pre name="code" class="core">
public class Person implements Serializable {

private List<UserRole> userRoles;

@OneToMany(cascade=CascadeType.ALL, mappedBy="person")
public List<UserRole> getUserRoles() {
return userRoles;

public void setUserRoles(List<UserRole> userRoles) {
this.userRoles = userRoles;



How should my SessionBean interface look for adding/updating a person?

public long addPerson(Person p);
public long updatePerson(Person p);

where p contains list of userroles within it so that when I do em.persist(p), a person record and user roles record are created/updated?
(Here I wonder.. suppose I have 3 userroles added in db. Now I remove one from the list and try to persist; will the container know that one was deleted or it will just go and update the 2 which are there on the list?)

Basically here, the container takes care of adding the userroles for me.

or should I do this instead?

public long addPerson(Person p, List userRolesToAdd, List userRolesToDelete)?

In this case above, I add extra methods addUserRole(UserRole userRole), DeleteUserRole to the Person entity bean class.

And always in my session bean, I iterate thro' both the lists and call the addUserRoel and DeleteUserRole in the loop.

I'm not sure which approach to take and why do examples in books show these extra methods when really the container takes care of it for us when we do em.persist(p).

I'd appreciate your thoughts.

hey Amit,

I think you are being paid very less compared to the years of experience you have. It seems you have knowledge in most of the areas.
So I'd say enough of the learning.. look for something that pays you better. IMHO, people tend to learn when give a project.. so you'll be able to manage anywhere.. you can never learn everything.

15 years ago
Ok, I tried something now.. I removed the not null constraint from the phone table for customer_id column and it works.
But now I ask why.. can't I keep constraint there?
Looking at the example in Oreilly ejb3.0 book, a customer can have a collection of phones.
So lets take the implementation where the phone table includes a foreign key to the customer cable (no join table here).

My question is, when I want to save a customer (which has collection of phone objects in it), is just doing

manager.persist(customer) sufficient or I need to have a transaction and do this:

manager.persist(customer);//phones collection here is blank

I ask because I tried only doing this: manager.persist(customer) but I get an error saying ORA-01400: cannot insert NULL into PHONE.CUSTOMER_ID.