• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Bear Bibeault
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • salvin francis
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
Bartenders:
  • Jj Roberts
  • Carey Brown
  • Scott Selikoff

How to bind to an object inside HashMap.

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a text box in a JSP.
Value of the textbox is present in a DO.
DO is present inside a HashMap.

How do I write the expression in the textbox {#.. blah blah..} to point to the value and display it? Below is my code:

DataObject:
public class PageNameDO {

private String whereAmI = "";

public PageNameDO(String val){
whereAmI = val;
}
//getters and setters
}

BackingBean with HashMap inside it:
public class HashBind extends PageCodeBase {

private HashMap<String, PageNameDO> hash1 = null;

public HashBind(){
hash1 = new HashMap<String, PageNameDO>();
hash1.put("A", new PageNameDO("Apple"));
}

//getters and setters for hashmap
}

JSP Page:
<h:inputText styleClass="inputText"
id="text1"
value="#{pc_HashBind.hash1[0].pageNameDO.whereAmI}">
</h:inputText>

How to display the value inside the text box?

Help!!
 
Saloon Keeper
Posts: 23284
158
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm going to simplify that request a little to make it clearer, but you should be able to build it up from there.

Let's say you want to display/modify the element in Map myMap in your backing bean that's stored under the key "fruit".

First, you define the property "myMap" with its setter and getter methods. Actually probably just a getter since you probably don't want to replace the whole map.

Now in the input control, you code the value attribute using Java EL:

value="#{myMap['fruit']}"

That's all there is to it.

The unified Expression Language is fairly well documented in the Sun JEE reference documents. A lot of J(2)EE systems use an open-source EL interpreter: the jakarta commons EL project (http://commons.apache.org/el/), which is based on the Jakarta BeanUtils. The BeanUtils are used to resolve property references, so their documentation can be especially helpful.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic