Pattern Matching?

Hi,

I have a query in rendering a dyanimc html object based on certain condition in a JSP page .I have follwing inputs

String myStr = " I am born in $$1$$ and my age is $$2$$";

In the above string , i have to replace the pattern $$<no>$$ with specific objects.

I have a sequence in which the objects should get displayed.

say for eg: an Hashmap holding the seq um and the object of the particular sequence...

HashMap myObjSequence.put( seqno,object_to_be_displayed)

ie. HashMap myObjSequence.put( 1,selectbox)

HashMap myObjSequence.put( 2,textbox)

i need to retrieve the sequence from the hashMap and find the sequence in the below string

ie for : $$1$$ - i need to replace this with a html droplist or selectbox object with the list of countries and $$2$$ should replace with a textbox.Is there any existing pattern for such an approach? if not, how it can be accomplished ?

Thanks,

kuil

[978 byte] By [kuila] at [2007-10-1 2:15:49]
# 1

A simple string replace would work;

String key = null;

for(Iterator i=map.keySet().iterator(); i.hasNext();){

key = (String) i.next();

org.apache.commons.lang.StringUtils.replace(str, "$$"+key+"$$", map.get(key));

}

make sure the objects that you put in has the "toString" method overridden with the appropriate html that you want to render

kksenjia at 2007-7-8 11:24:31 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...