Results 1 to 9 of 9

Thread: how to i18n a table column with different messages?

  1. #1
    Join Date
    Jul 2005
    Location
    Beijing, China
    Posts
    35

    Question how to i18n a table column with different messages?

    Hi all!

    I create two tables(tableA,tableB), the columns of both are consist of some properties of the same javabean.

    now,I want to let a property of the javabean in the two tables render different messages, so how can I do it??

    for example :
    the property of the javabean is "name"

    in tableA,it render as "userName"
    while in tableB,it render as "clientName"
    sword in the hand but not mind

  2. #2
    Join Date
    Jul 2005
    Location
    Beijing, China
    Posts
    35

    Unhappy

    any one could help me !!??
    sword in the hand but not mind

  3. #3
    Join Date
    Aug 2004
    Location
    San Francisco
    Posts
    423

    Default

    It's not totally obvious from your question what the problem is, that's probably why there's no response.

    If I had two tables displaying the data from a bean in different ways I'd just write two instances of a table model that defines what's displayed. Nothing to do with i18n.

    If you do need i18n messages within a table then you can use the message services provides by Spring rich. These are the getMessage methods on the Application.services() static method, and various other view, command etc classes.

    Jonny

  4. #4
    Join Date
    Jul 2005
    Location
    Beijing, China
    Posts
    35

    Default

    Because I use a subclass of BeanTableModel to create two tables,and BeanTableModel will i18n the table column names for me using the method below:

    Code:
    public String[] createColumnNames() {
            String[] columnPropertyNames = getColumnPropertyNames();
            String[] columnNames = new String[columnPropertyNames.length];
            Assert.notNull(this.messages);
            for (int i = 0; i < columnPropertyNames.length; i++) {
                String className = ClassUtils.getShortNameAsProperty(beanClass);
                String columnPropertyName = columnPropertyNames[i];
                try {
                    columnNames[i] = messages.getMessage(className + "." + columnPropertyName);
                } catch(NoSuchMessageException e) {
                    columnNames[i] = messages.getMessage(columnPropertyName, columnPropertyName);
                }            
            }
            return columnNames;
        }
    so the column names of the two tables will get the same i18n messages!
    sword in the hand but not mind

  5. #5
    Join Date
    Aug 2004
    Location
    San Francisco
    Posts
    423

    Default

    Sorry, I'd like to help, but I still don't know what your problem is.

    What does the bean table model do that you think is wrong?

    Quote Originally Posted by hammer
    Because I use a subclass of BeanTableModel to create two tables,and BeanTableModel will i18n the table column names for me using the method below:

    Code:
    public String[] createColumnNames() {
            String[] columnPropertyNames = getColumnPropertyNames();
            String[] columnNames = new String[columnPropertyNames.length];
            Assert.notNull(this.messages);
            for (int i = 0; i < columnPropertyNames.length; i++) {
                String className = ClassUtils.getShortNameAsProperty(beanClass);
                String columnPropertyName = columnPropertyNames[i];
                try {
                    columnNames[i] = messages.getMessage(className + "." + columnPropertyName);
                } catch(NoSuchMessageException e) {
                    columnNames[i] = messages.getMessage(columnPropertyName, columnPropertyName);
                }            
            }
            return columnNames;
        }
    so the column names of the two tables will get the same i18n messages!

  6. #6
    Join Date
    Jul 2005
    Location
    Beijing, China
    Posts
    35

    Default

    sorry to trouble you so much,jwray

    becasuse the column names in the tables will render as Chinese, not English. So I will i18n the column names.

    And in the above method , the i18n messages will be handled as below:
    Code:
    try {
                    columnNames[i] = messages.getMessage(className + "." + columnPropertyName);
                } catch(NoSuchMessageException e) {
                    columnNames[i] = messages.getMessage(columnPropertyName, columnPropertyName);
                }
    because the "columnPropertyName" in the above will always be the same as they are properties of the same javabean, the i18n messages of the same column name will be the same too.

    hope that clear
    sword in the hand but not mind

  7. #7
    Join Date
    Aug 2004
    Location
    San Francisco
    Posts
    423

    Default

    I think that makes it clearer. It seems to be that you're trying to do something the bean table model wasn't designed to do. It assumes you always want to label a property by the same name and uses the bean property name as the key into the messages. You want to use message keys other than the property name, correct?

    I'd either just write my own table models (they aren't hard after all) or override the createColumnNames method to do what you want to do.

    Jonny

  8. #8
    Join Date
    Jul 2005
    Location
    Beijing, China
    Posts
    35

    Default

    oh,i got it!

    thanks a lot!
    sword in the hand but not mind

  9. #9
    Join Date
    Aug 2005
    Location
    Austin, TX
    Posts
    425

    Default

    Another option is to use GlazedTableModel. It allows you to configure the model Id used to generate the message keys. This would allow you to use a different model id for the two different tables and the message keys would then be unique.

    Larry.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •