Hi,

 Is it possible to get the fields label name from jsp to Action/servlet for example,  
   My jsp has some fields like this,
             Label name:        Fields
             Search:               <html:text property="txtSearch"/>      
             Order:                <html:checkbox  property="chkOrder"/>
   Now I need to get these label names below mentioned format,
           HashTable<String,String> labelList=new  HashTable<String,String>()              
           lableList ={txtSearch=Search:, chkOrder=Order:}     
   Please someone help me.

why would you need that?

Hi stultuske,

 I need to edit some of the existing fields value and I want to pass the changed values as a string format to Data base. For example,

 Field label called Address1 and property name is txtAdddress1. 

If Address1 field changed from old state then I want pass a string to DB that should contain label name, old value and current value Like “Address1 changed from xxx to yyy \n” for maintaining history. Similarly I add reaming changed fields.

For achieve this result I used object deep copy functionality. I took a copy of current object and set name as old object at the time of page loading. So that, whatever user can edit in the current object. After click update button I compared two objects(old objcet and current object)dynamically by Apache Commons Beanutils. The comparing function I mentioned below.

Code,
public void compareObjects(Object oldObj, Object currentObj) 
        BeanMap map = new BeanMap(oldObj);
        PropertyUtilsBean propUtils = new PropertyUtilsBean();
        StringBuilder sb=new StringBuilder();

        for (Object proObject : map.keySet()) {
            String property = (String) proObject;
            Object value1 = propUtils.getProperty(oldObj, property);
            Object value2 = propUtils.getProperty(currentObj, property);
            if (!value1.equals(value2)) {
              sb.append(property).append("changed from").append(value1).append("To").append(value2);
            } 
        }

    }

By this function I can find out which fields value is changed. But the problem is am getting property value only instead of label name. So I can’t form my string like this format “Address1 changed from xxx to yyy n”. I don’t think it would be good program if I use some conditions like this

If (property ==”txtAddress1” ) 
             labelName=”Address1”    

If I have 100 fields in my page then I have to add 100 if conditions. And also If I add conditions like this I can’t re use same function from different page. Is it possible to get the label names in any other way without making hard code?

I have planned to create a property file, add all the fields name which are required to compare and corresponding field name I add label name also. So that, I can get the label name with the help of filed name. By reading properties file function I can form mentioned format,

labelList={ txtAddress1= Address1, txtOrder=Order } 

etc.

If some other way available for make labellist without creating properties file, please share how to do.

Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.