Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Using a managed property Map in JSF to show a status in aSelectOneMenu and OutputText

Reply
Thread Tools

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

 
 
andymconline
Guest
Posts: n/a
 
      01-18-2008
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:

<hutputText 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
 
Reply With Quote
 
 
 
 
Lew
Guest
Posts: n/a
 
      01-18-2008
andymconline wrote:
> 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:
>
> <hutputText 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 [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').

--
Lew
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Show a bean property in jsf....it's so difficult????? gbattine Java 2 07-11-2006 09:55 AM
Include JSF page within another JSF page BlackIce Java 1 07-05-2006 11:24 PM
JSF debugging / JSF newsgroup Sebastian Fey Java 1 04-07-2006 08:52 PM
[JSF]Need to deploy a jsf application on SunApplicationServer. dudu Java 0 03-03-2006 12:09 PM
getting around html encoding in outputText tag (JSF) nadlox@gmail.com Java 2 11-29-2005 12:50 PM



Advertisments