Announcement Announcement Module
Collapse
No announcement yet.
how to i18n a table column with different messages? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • hammer
    started a topic how to i18n a table column with different messages?

    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"

  • lstreepy
    replied
    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.

    Leave a comment:


  • hammer
    replied
    oh,i got it!

    thanks a lot!

    Leave a comment:


  • jwray
    replied
    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

    Leave a comment:


  • hammer
    replied
    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

    Leave a comment:


  • jwray
    replied
    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?

    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!

    Leave a comment:


  • hammer
    replied
    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!

    Leave a comment:


  • jwray
    replied
    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

    Leave a comment:


  • hammer
    replied
    any one could help me !!??

    Leave a comment:

Working...
X