Struts + EJB.
I want to keep as much biz logic as possible on EJB tier.
and I hope retrieve as detail notification as possible from
EJB tier.
Here is an example requirement :
[User Login]
if (can find user by username) {
notificate client
} else if (password is error) {
notificate client
} else {
notificate client
}
For every "notificate client", a i18n string should be
returned.
How should I do?
1> If implementing at EJB tier, I have to do it manually,
and cannot get any benefit from Struts
2> If implementing at Struts tier, I have to invoke EJB
tier for more times.
Pls give some advice! 3x
-
How should I process the i18n? (Struts+EJB) (4 messages)
- Posted by: vic liu
- Posted on: November 01 2004 03:37 EST
Threaded Messages (4)
- How should I process the i18n? (Struts+EJB) by Duncan Mills on November 05 2004 00:30 EST
- thanks, but.. by vic liu on November 05 2004 21:26 EST
- thanks, but.. by Dennis Cheung on November 07 2004 10:59 EST
- thanks, but.. by vic liu on November 05 2004 21:26 EST
- How should I process the i18n? (Struts+EJB) by vic liu on November 23 2004 21:13 EST
-
How should I process the i18n? (Struts+EJB)[ Go to top ]
- Posted by: Duncan Mills
- Posted on: November 05 2004 00:30 EST
- in response to vic liu
If implementing at Struts tier, I have to invoke EJB tier for more times.
Can you clarify that - surely from your Struts Action you'll just be invoking your connection method in the Session Bean and that will return the result - you'll not be going back and forth asking the bean if the username was wrong, then if the password was wrong and so on.
The EJB should just return an error state that you then convert into a readable internationalised message in Struts. -
thanks, but..[ Go to top ]
- Posted by: vic liu
- Posted on: November 05 2004 21:26 EST
- in response to Duncan Mills
thank for your reply.
I give another example:
----------------------------------------------------------
Place Order :
if (creator is forbidden) {
stop here and notificate user
}
if (order has no item) {
stop here and notificate user
for each item {
if (product has no inventory) {
stop here and notificate user
}
}
}
more biz validation..
save order and do more..
----------------------------------------------------------
Placing order must be performed in a transaction and
if failing to place it, I should return user a detail
information instead of a simple notification, such as
"Failed to place order"
A session beans method placeOrder(OrderDTO order, Local local)
encapsulates this logic ,and struts tier will invoke it
But use this approach, at each "stop here and notificate user"
point, I have to generate and return corresponding i18n message
to struts tier. So I say I cannot get any benefit from Struts.
If I using Struts process i18n, the struts tier must know all the
biz logic, so my struts code almost like:
----------------------------------------------------------
ActionErrors errors = new ActionErrors();
MessageResources defaultBundle = getDefauleBundle();
if (UserEJB.isForbidden(sessionUserId)) {
errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("key.user.forbidden"));
} else if (order has no item) {
errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("key.order.no.item"));
} .....
return errors;
----------------------------------------------------------
Obviously, this approach is not good enough.
What's the better way? -
thanks, but..[ Go to top ]
- Posted by: Dennis Cheung
- Posted on: November 07 2004 22:59 EST
- in response to vic liu
How about this?
-------------
ActionErrors errors = new ActionErrors();
try{
// do something with EJB here
}catch(Exception e){
if (e......) {
errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("key.user.forbidden"));
} else if (e.....) {
errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("key.order.no.item"));
}
}
------------
Build you own exception case. even pass the error id from EJB
--------
String errorid=EJB.dosomething();
if(errorid!=null){
errors.add(ActionErrors.GLOBAL_ERROR,new ActionError(errorid));
}
------- -
How should I process the i18n? (Struts+EJB)[ Go to top ]
- Posted by: vic liu
- Posted on: November 23 2004 21:13 EST
- in response to vic liu
Thanks
I think maybe the best way is:
In our customize exception, we add 2 methods
- List getErrorMessageKeys()
- List getMessageKeys()
Thus, we donot have to create too detail exceptions for
each case.
In struts tier, we can use these keys do i18n.