You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Shibi Thomas <sh...@gmail.com> on 2006/07/19 11:14:09 UTC

Displaying data from a map

Hi
I have a map called "details" with key as and values. i would like to
retrieve the value in the keys.
Currently this is how my code looks like:


<c:forEach items="#{sessionScope.request.details}" var="entry">

<tr>

<td>???</td>

<td>#{entry}</td>

</tr>

</c:forEach>






-- 
Kind Regards
Shibi Thomas

Rom 12:21  Do not be overcome by evil, but overcome evil with good.

Re: Displaying data from a map

Posted by Martin Beranek <ma...@i.cz>.
Shibi Thomas napsal(a):
> hi
> i am not familiar with witing your own functions for facelets. where do
> i read more about this??
> 
>  
> <ma...@i.cz>> wrote:
> 
>     Or if you are using facelets, you can write your own functions like:
> 
>     public Set keysFromMap(Map m)
> 
>     and
> 
>     public Object valueFromMap(Object key)
> 
>     --
>     Martin Beranek

http://www-128.ibm.com/developerworks/java/library/j-facelets2.html

it looks like dificult, but here is little example - function Concatenate

=== Concat.java ===

package my.package;

public class Concat {

    public static String concat(String s1, String s2) {
        return s1+s2;
    }

}

=== myfunctions.taglib.xml ===
<?xml version="1.0"?>
<!DOCTYPE facelet-taglib PUBLIC "-//Sun Microsystems, Inc.//DTD Facelet
taglib 1.0//EN" "http://java.sun.com/dtd/facelet-taglib_1_0.dtd">

<facelet-taglib>
  <namespace>http://www.my.tld/functions</namespace>
  <function>
    <function-name>concat</function-name>
    <function-class>cz.i.aprd.web1.jsf.function.Concat</function-class>
    <function-signature>java.lang.String concat (java.lang.String,
java.lang.String)</function-signature>
  </function>
</facelet-taglib>


then register taglib and load library in page with some prefix (e.g.
functions). you can use:

#{functions:concat('My long string',variable}

simple ;-)

-- 
Martin Beránek

Re: Displaying data from a map

Posted by Michael Meierhoff <Mi...@elitepartner.de>.
You don't need JavaScript for hover a tr.  You can do this with css only.

Example for that:
table.blub tbody tr:hover{
	background-color:#DEEAF6;
} 

RE: Displaying data from a map

Posted by Jorge Vásquez <jv...@3eyegroup.com>.
You can also use:  #{managedBean.beanMapAttribute.key}

JV

-----Mensaje original-----
De: Kuni [mailto:kuni@muschkoten-berlin.de] 
Enviado el: viernes, 28 de julio de 2006 15:43
Para: MyFaces Discussion
Asunto: Re: Displaying data from a map

try #{map['key']} if you have String-based key's.. that works. a

Shibi Thomas schrieb:
> hi
> i am not familiar with witing your own functions for facelets. where 
> do i read more about this??
>
>  
> On 7/27/06, *Martin Beránek* <martin.beranek@i.cz 
> <ma...@i.cz>> wrote:
>
>     CD napsal(a):
>
>     > It might be best to write a couple of getter methods (one for
>     getting
>     > the keys and one for getting the values) that delegates to the
>     > appropriate methods in the set or builds the keys and values on the
>     > value using the set's contents.
>
>     Or if you are using facelets, you can write your own functions like:
>
>     public Set keysFromMap(Map m)
>
>     and
>
>     public Object valueFromMap(Object key)
>
>     --
>     Martin Beranek
>
>
>
>
> -- 
> Kind Regards
> Shibi Thomas
> Cell : 0843052341
> Email : shibimary@gmail.com <ma...@gmail.com>
>
> Rom 12:21  Do not be overcome by evil, but overcome evil with good. 


Re: Displaying data from a map

Posted by Kuni <ku...@muschkoten-berlin.de>.
try #{map['key']} if you have String-based key's.. that works. a

Shibi Thomas schrieb:
> hi
> i am not familiar with witing your own functions for facelets. where 
> do i read more about this??
>
>  
> On 7/27/06, *Martin Beránek* <martin.beranek@i.cz 
> <ma...@i.cz>> wrote:
>
>     CD napsal(a):
>
>     > It might be best to write a couple of getter methods (one for
>     getting
>     > the keys and one for getting the values) that delegates to the
>     > appropriate methods in the set or builds the keys and values on the
>     > value using the set's contents.
>
>     Or if you are using facelets, you can write your own functions like:
>
>     public Set keysFromMap(Map m)
>
>     and
>
>     public Object valueFromMap(Object key)
>
>     --
>     Martin Beranek
>
>
>
>
> -- 
> Kind Regards
> Shibi Thomas
> Cell : 0843052341
> Email : shibimary@gmail.com <ma...@gmail.com>
>
> Rom 12:21  Do not be overcome by evil, but overcome evil with good. 


Re: Displaying data from a map

Posted by Shibi Thomas <sh...@gmail.com>.
hi
i am not familiar with witing your own functions for facelets. where do i
read more about this??


On 7/27/06, Martin Beránek <ma...@i.cz> wrote:
>
> CD napsal(a):
>
> > It might be best to write a couple of getter methods (one for getting
> > the keys and one for getting the values) that delegates to the
> > appropriate methods in the set or builds the keys and values on the
> > value using the set's contents.
>
> Or if you are using facelets, you can write your own functions like:
>
> public Set keysFromMap(Map m)
>
> and
>
> public Object valueFromMap(Object key)
>
> --
> Martin Beranek
>



-- 
Kind Regards
Shibi Thomas
Cell : 0843052341
Email : shibimary@gmail.com

Rom 12:21  Do not be overcome by evil, but overcome evil with good.

Re: Displaying data from a map

Posted by Martin Beránek <ma...@i.cz>.
CD napsal(a):

> It might be best to write a couple of getter methods (one for getting
> the keys and one for getting the values) that delegates to the
> appropriate methods in the set or builds the keys and values on the
> value using the set's contents.

Or if you are using facelets, you can write your own functions like:

public Set keysFromMap(Map m)

and

public Object valueFromMap(Object key)

--
Martin Beranek

Re: Displaying data from a map

Posted by CD <dc...@gmail.com>.
What kind of set are you using?  I will assume that you are using a HashSet
as I see key/value pairs mentioned.  You should probably look closer at the
javadoc for HashSet (or whatever set you are using) to ensure that it has
appropriate getters/setters for the methods you are trying to invoke (if it
doesn't have getKeys() and getValues(), then it would explain the errors as
reflection is not going to work).

It might be best to write a couple of getter methods (one for getting the
keys and one for getting the values) that delegates to the appropriate
methods in the set or builds the keys and values on the value using the
set's contents.


On 7/26/06, Shibi Thomas <sh...@gmail.com> wrote:
>
>  Hi Rajiv
>
> Tried this but throws error on c : out
>
> So i tried the following :
>
>
> <
> c:forEach items="#{sessionScope.request.details.entrySet}" var="entry">
>
> <tr><td >${entry.key} </td>
>
> <td>${entry.value} </ td></tr>
>
> </c:forEach>
> Nothing is being displayed. Do i have to do any code modification  for
> "entrySet"
> Rgds
>  Shibi
>
>  On 7/20/06, jsf ster <js...@gmail.com> wrote:
>
> > Hi Shibi,
> >
> > try this:
> >
> >
> > <c:forEach items="${sessionScope.request.details
> >  .entrySet}" var="entry">
> > <tr>
> > <td><c:out value="${entry.key}" /></td>
> > <td><c:out value="${entry.value}" /></ td>
> > </tr>
> > </c:forEach>
> >
> > -Rajiv
> >
> >
>
>
>
> --
>
> Kind Regards
> Shibi Thomas
> Cell : 0843052341
> Email : shibimary@gmail.com
>
> Rom 12:21  Do not be overcome by evil, but overcome evil with good.
>

Re: Displaying data from a map

Posted by Shibi Thomas <sh...@gmail.com>.
Hi Rajiv

Tried this but throws error on c : out

So i tried the following :


<c:forEach items="#{sessionScope.request.details.entrySet}" var="entry">

<tr><td>${entry.key} </td>

<td>${entry.value} </td></tr>

</c:forEach>
Nothing is being displayed. Do i have to do any code modification  for
"entrySet"

Rgds
Shibi

On 7/20/06, jsf ster <js...@gmail.com> wrote:
>
> Hi Shibi,
>
> try this:
>
>
> <c:forEach items="${sessionScope.request.details
>  .entrySet}" var="entry">
> <tr>
> <td><c:out value="${entry.key}" /></td>
> <td><c:out value="${entry.value}" /></ td>
> </tr>
> </c:forEach>
>
> -Rajiv
>
>



-- 
Kind Regards
Shibi Thomas
Cell : 0843052341
Email : shibimary@gmail.com

Rom 12:21  Do not be overcome by evil, but overcome evil with good.

Re: Displaying data from a map

Posted by Mike Kienenberger <mk...@gmail.com>.
Note that you'll be safer using t:dataList or ui:repeat unless you're
sure that these values will never change during the lifetime of the
session.

On 7/20/06, jsf ster <js...@gmail.com> wrote:
> Hi Shibi,
>
>  try this:
>
>
>  <c:forEach items="${sessionScope.request.details
> .entrySet}" var="entry">
> <tr>
> <td><c:out value="${entry.key}" /></td>
> <td><c:out value="${entry.value}" /></ td>
> </tr>
> </c:forEach>
>  -Rajiv
>

Re: Displaying data from a map

Posted by jsf ster <js...@gmail.com>.
Hi Shibi,

try this:

<c:forEach items="${sessionScope.request.details .entrySet}" var="entry">
<tr>
<td><c:out value="${entry.key}" /></td>
<td><c:out value="${entry.value}" /></ td>
</tr>
</c:forEach>

-Rajiv

Re: Displaying data from a map

Posted by Cosma Colanicchia <co...@gmail.com>.
I haven't tried it myself so I can't help.. try to understand where is
it failing.

Cosma



2006/7/19, Shibi Thomas <sh...@gmail.com>:
>
> hi Cosma
>
> I have tried what u suggested but without any fruit. I do no get anything
> displayed. Do u have any other suggestion ?
>
>
> On 7/19/06, Cosma Colanicchia <co...@gmail.com> wrote:
> > Maybe you could do like this:
> >
> > <c:forEach
> items="#{sessionScope.request.details.entrySet}"
> var="entry">
> > <tr>
> > <td>#{entry.key}</td>
> > <td>#{entry.value}</ td>
> > </tr>
> > </c:forEach>
> >
> >
> > Cosma
> >
> > 2006/7/19, Shibi Thomas <shibimary@gmail.com >:
> > >
> > > Hi
> > > I have a map called "details" with key as and values. i would like to
> > > retrieve the value in the keys.
> > > Currently this is how my code looks like:
> > >
> > >
> > > <c:forEach items="#{sessionScope.request.details }" var="entry">
> > >
> > > <tr>
> > >
> > > <td>???</ td>
> > >
> > > <td>#{entry}</ td>
> > >
> > > </tr>
> > >
> > > </c:forEach>
> > >
> > >
> > >
> > >
> > >
> > >
> > > --
> > > Kind Regards
> > > Shibi Thomas
> > >
> > > Rom 12:21  Do not be overcome by evil, but overcome evil with good.
> >
>
>
>
> --
> Kind Regards
> Shibi Thomas
> Cell : 0843052341
> Email : shibimary@gmail.com
>
>
> Rom 12:21  Do not be overcome by evil, but overcome evil with good.

Re: Displaying data from a map

Posted by Shibi Thomas <sh...@gmail.com>.
hi Cosma

I have tried what u suggested but without any fruit. I do no get anything
displayed. Do u have any other suggestion ?

On 7/19/06, Cosma Colanicchia <co...@gmail.com> wrote:
>
> Maybe you could do like this:
>
> <c:forEach items="#{sessionScope.request.details.entrySet}" var="entry">
> <tr>
> <td>#{entry.key}</td>
> <td>#{entry.value}</ td>
> </tr>
> </c:forEach>
>
>
> Cosma
>
> 2006/7/19, Shibi Thomas <sh...@gmail.com>:
> >
> > Hi
> > I have a map called "details" with key as and values. i would like to
> > retrieve the value in the keys.
> > Currently this is how my code looks like:
> >
> >
> > <c:forEach items="#{sessionScope.request.details }" var="entry">
> >
> > <tr>
> >
> > <td>???</ td>
> >
> > <td>#{entry}</ td>
> >
> > </tr>
> >
> > </c:forEach>
> >
> >
> >
> >
> >
> >
> > --
> > Kind Regards
> > Shibi Thomas
> >
> > Rom 12:21  Do not be overcome by evil, but overcome evil with good.
>



-- 
Kind Regards
Shibi Thomas
Cell : 0843052341
Email : shibimary@gmail.com

Rom 12:21  Do not be overcome by evil, but overcome evil with good.

Re: Displaying data from a map

Posted by Cosma Colanicchia <co...@gmail.com>.
Maybe you could do like this:

<c:forEach items="#{sessionScope.request.details.entrySet}" var="entry">
<tr>
<td>#{entry.key}</td>
<td>#{entry.value}</ td>
</tr>
</c:forEach>


Cosma

2006/7/19, Shibi Thomas <sh...@gmail.com>:
>
> Hi
> I have a map called "details" with key as and values. i would like to
> retrieve the value in the keys.
> Currently this is how my code looks like:
>
>
> <c:forEach items="#{sessionScope.request.details }" var="entry">
>
> <tr>
>
> <td>???</ td>
>
> <td>#{entry}</ td>
>
> </tr>
>
> </c:forEach>
>
>
>
>
>
>
> --
> Kind Regards
> Shibi Thomas
>
> Rom 12:21  Do not be overcome by evil, but overcome evil with good.