rich:dropDownMenu: What can I put inside?
seg.fault May 27, 2008 8:49 AMHello!
I want to dynamically populate a dropDownMenu without binding a Bean class (and using RichFaces API).
I've tried the following JSF but it doesn't work:
<h:form>
<rich:dropDownMenu id="myMenu-cforEach" submitMode="server">
<f:facet name="label">
<h:panelGrid cellpadding="0" cellspacing="0" columns="2" style="vertical-align:middle">
<h:outputText value="MyChoice"/>
</h:panelGrid>
</f:facet>
<c:forEach items="#{myBean.pairList}" var="item">
<rich:menuItem value="#{item.first}" action="#{myBean.menuChangeAction}">
<f:setPropertyActionListener target="#{myBean.currentChoice}" value="#{item.first}"/>
<f:facet name="icon">
<h:outputText value="#{item.first}"/>
</f:facet>
<h:outputText value="#{item.second}"/>
</rich:menuItem>
</c:forEach>
</rich:dropDownMenu>
</h:form>
where myBean is defined as follows:
import java.util.ArrayList;
import java.util.List;
public class MyBean
{
private static List<Pair<String,String>> PairList = null;
static
{
PairList = new ArrayList<Pair<String,String>>();
PairList.add( new Pair<String,String>( "de", "Deutsch") );
PairList.add( new Pair<String,String>( "en", "English" ) );
PairList.add( new Pair<String,String>( "es", "Espaniol") );
PairList.add( new Pair<String,String>( "fr", "Francaise" ) );
PairList.add( new Pair<String,String>( "it", "Italiano") );
}
public List<Pair<String,String>> getPairList()
{
return PairList;
}
private String curChoice;
public String getCurrentChoice() { return this.curChoice; }
public void setCurrentChoice(String value) { this.curChoice = value; }
public String menuChangeAction()
{
// change action trigger goes here
return "ok";
}
}
and the Pair type is defined as:
public class Pair<V1,V2>
{
private V1 v1; /** The first element. */
private V2 v2; /** The second element. */
public Pair(V1 v1, V2 v2)
{
this.v1 = v1;
this.v2 = v2;
}
public V1 getFirst() { return this.v1; }
public V2 getSecond() { return this.v2; }
@Override
public String toString() { return "<" + this.v1 + ", " + this.v2 + ">"; }
}
What I get is like:
[de] deDeutsch [en] enEnglish [es] esEspaniol [fr] frFrancaise [it] itItaliano
That is, each menuItem displays both elements of each pair (note [xx] stands for what is showed in the icon part), instead of displaying only the second one.
I've also tried to implement a custom JSF component, using UIData as the base component and implementing the rendering logic by myself. But no hope (without the enclosing rich:dropDownMenu element it works).
Please, Can anyone help me??
Thank you very very much!!