How should I process the i18n? (Struts+EJB)

Discussions

General J2EE: How should I process the i18n? (Struts+EJB)

  1. How should I process the i18n? (Struts+EJB) (4 messages)

    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

    Threaded Messages (4)

  2. 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.
  3. thanks, but..[ Go to top ]

    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?
  4. thanks, but..[ Go to top ]

    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));
    }
    -------
  5. How should I process the i18n? (Struts+EJB)[ Go to top ]

    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.