Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2008

Tip: Looking for answers? Try searching our database.

Using a managed property Map in JSF to show a status in a     SelectOneMenu and OutputText

Thread view: 
andymconline - 18 Jan 2008 11:46 GMT
Hello,

I'm hoping someone can help me.  I am trying to use a map-entry to
store and display the status of an entity in the database.  I have the
following managed-bean defined in my faces-config.xml file:

<managed-bean>
 <managed-bean-name>RPHandler</managed-bean-name>
 <managed-bean-class>com.sett.backing.RPHandler</managed-bean-class>
 <managed-bean-scope>session</managed-bean-scope>
 <managed-property>
   <property-name>ratePlan</property-name>
   <value>#{ratePlanBean}</value>
 </managed-property>
 <managed-property>
   <property-name>statusMap</property-name>
   <property-class>java.util.HashMap</property-class>
   <map-entries>
     <map-entry>
       <key>In Development</key>
       <value>D</value>
     </map-entry>
     <map-entry>
       <key>Active</key>
       <value>A</value>
     </map-entry>
     <map-entry>
       <key>Not For Sale</key>
       <value>N</value>
     </map-entry>
   </map-entries>
 </managed-property>
</managed-bean>

In my ratePlanForm.jsp file I have the following code to display a
SELECT box:

<h:selectOneMenu id="status" value="#{RPHandler.ratePlan.status}">
 <f:selectItems value="#{RPHandler.statusMap}" />
<h:selectOneMenu>

Which creates the following HTML output:

<select id="status"><option value="D>In Development</option><option
value="A">Active</option><option value="N">Not For Sale</option></
select>

This is exactly what I want, however when I then try and show a list
of ratePlans and their associated status's I use:

<h:outputText value="#{RPHandler.statusMap[ratePlan.status]}" />

Which obviously shows nothing as ratePlan.status is set to the value
from the SELECT box ("A" for example) and their is no key equal to A
in the HashMap (as I have had to declare the HashMap with the
descriptions in the key field so that the selectItems JSF tag displays
the descriptions in the SELECT box).  How to I get the outputText to
show the textual description of A?  Do I need to declare two hashmaps?

Many Thanks

Andy
Lew - 18 Jan 2008 15:42 GMT
> Hello,
>
[quoted text clipped - 54 lines]
> the descriptions in the SELECT box).  How to I get the outputText to
> show the textual description of A?  Do I need to declare two hashmaps [sic]?

Nah, you need a List of a custom type that holds the attributes of interest
(name, for example).  Return the entire CustomType object as the value, or
keep a Map of the CustomType objects on the server only, indexed by the
returned letter (Map <String, CustomType>).  Then you display the returned
object's "name" attribute (or whatever you call it) wherever you need to.

By convention, attribute and variable names begin with a lower-case letter
('rpHandler').

Signature

Lew



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.