pass parameter in a <h:selectOneMenu>

Hello

Im working on a Jboss-Seam project with Facelets. Everything works fine but it is really hard to pass a parameter to a bean. This would be nice for using dynamic methods.

I trying to pass a parameter in a <h:selectOneMenu> section to a bean method. I tryed many different ways but it still not works.

1.

First i tried it with <f:param> and <f:setPropertyActionListener>

This solution works fine with commandButtons and commandLinks but not in a selectOneMenu.

- http://justfiveminutes.wordpress.com/2006/07/12/passing-parameters-to-links-in-facelets/

2.

My second try i startet with the el-functors library. This is very useful but didn't work in a

selectOneMenu too. i got a javax.faces.el.PropertyNotFoundException

- http://forum.java.sun.com/thread.jspa?threadID=759750&messageID=4340566

The Files:

faces-config

<faces-config version="1.2"

xmlns="http://java.sun.com/xml/ns/javaee"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://java.sun.com/xml/javaee

http://java.sun.com/xml/ns/web-facesconfig_1_2.xsd">

<application>

<el-resolver>

org.jboss.seam.jsf.SeamELResolver

</el-resolver>

</application>

<lifecycle>

<phase-listener>

org.jboss.seam.jsf.SeamPhaseListener

</phase-listener>

</lifecycle>

</faces-config>

The selectOneMenu section in the facelet:

<h:selectOneMenu id="test" >

<f:selectItems value="#{myBean.nameList$['bla']}"/>

</h:selectOneMenu>

and the session bean:

@Stateful

@Scope(ScopeType.SESSION)

@Name("myBean")

publicclass myBeanBeanimplements myBean{

......

public List<SelectItem> getNameList(String name){

......

}

Unfortunately this version didn't work either. But this would be the nicest solution.

So i found a third possibilty:

-http://forum.java.sun.com/thread.jspa?threadID=759079&messageID=4336534

And i also tried this but i only got a null value. It also worked with commandButtons and commandLinks but not with the selectOneMenu :(

the Files:

the selectOnMenu section in the Facelet:

<h:selectOneMenu id="test" binding="#{myBean.text}" >

<f:attribute name="att" value="test"/>

<f:selectItems value="#{myBean.items}"/>

</h:selectOneManue>

The methods in the bean:

private HtmlSelectOneMenu text;

publicvoid setText(HtmlSelectOneMenu text){

this.text = text;

String name = (String) text.getAttributes().get("att");

System.out.println(name);

}

public HtmlSelectOneMenu getText(){

return text;

}

I tryed this not only with HtmlSelectOneMenu also with:

-UIComponent

-UISelectItem

-UISelectOne

-HtmlOutputText

But it didn't work.

Any Ideas ?

[3912 byte] By [manu440a] at [2007-11-27 6:44:41]
# 1

The 3rd option with f:attribute should work. What's happening in your case? If you're talking about the Sysout inside the binding setter, then it indeed returns null on the *first* call, simply because it's f:attribute child isn't rendered yet. The subsequent requests in the same view should work. Also the f:selectItems getter should be able to retrieve the attribute value on the *first* call. And when requesting it in the action method, this should always return the right value.

Where exactly do you need this attribute and why?

BalusCa at 2007-7-12 18:16:09 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Yeah

You are right.

In the methode were i build my selectItems list i have the parameter.

public void List<SeletItem> getList(){

String name = (String) text.getAttributes().get("att");

System.out.println(name);

.....

I use this to create cynamic a list of selectItems

Alll works fine now

Thanks

manu440a at 2007-7-12 18:16:09 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...