You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@shale.apache.org by Mike Otto <mi...@morning.in-berlin.de> on 2007/09/10 15:45:22 UTC
HtmlSelectOneMenu dynamically
How do I create
HtmlSelectManyListbox, HtmlSelectOneRadio, HtmlSelectOneMenu dynamically with
clay?
In the rolodex example I found a function with the name
"createInputElementMetadata" which teaches me how to create links.
// create a command link attribute
ElementBean link = new ElementBean();
link.setRenderId(generateId());
link.setJsfid("commandLink");
link.setComponentType("javax.faces.HtmlCommandLink");
I tried this:
ElementBean inputElement = new ElementBean();
inputElement.setComponentType("javax.faces.HtmlSelectOneMenu");
inputElement.setJsfid("securitycheck");
inputElement.setId("securitycheck");
root.addChild(inputElement);
This is the output
<select id="systemform:securitycheck" name="systemform:securitycheck"
size="1"></select>
Well I am missing the <option>-Tags .. any idea how to add
the option attributes dynamically is appreciated
as well as any documentation about the subject :-)
Best Regards
Mike
RE: HtmlSelectOneMenu dynamically
Posted by Richard Eggert <re...@proteus-technologies.com>.
Oh, that's easy. In JSF, you don't explictly mark a SelectItem as being selected (unlike OPTION tags in HTML). Instead, you set the parent SelectOne(Menu|Radio|Checkbox) element's "value" field (or, more specifically, the value of the managed bean property to which "value" is bound). As long as the value of the SelectOne matches the value of one of the SelectItems, that SelectItem will be rendered as "selected".
I believe what you need to do in your case is something like this:
AttributeBean valAttr = new AttributeBean();
valAttr.setName("value");
valAttr.setValue("#{someBean.someProperty}");
selectElement.addAttribute(valAttr);
and then make sure that "someBean" initializes "someProperty" to a default value that corresponds to one of your SelectItems.
Rich Eggert
Member of Technical Staff
Proteus Technologies, LLC
http://www.proteus-technologies.com
-----Original Message-----
From: Mike Otto [mailto:mike@morning.in-berlin.de]
Sent: Tue 9/11/2007 8:29 AM
To: user@shale.apache.org
Subject: RE: HtmlSelectOneMenu dynamically
Hello Richard,
thanks for answering. Now I have a clue about what I should do ..
The code below works like a charm, except that I don't know how
to declare a item as selected. I looked up
javax.faces.component.UISelectItem.class
and found
private String _itemDescription = null;
private Boolean _itemDisabled = null;
private String _itemLabel = null;
private Object _itemValue = null;
private Object _value = null;
(no private Object _selected)
Besides I still do not have a solution for component type
javax.faces.SelectItem_s_ But I think with Items in singular
I have more control, right?
Regards Mike
// HTMLSelectOneMenu
ElementBean selectElement = new ElementBean();
selectElement.setComponentType("javax.faces.HtmlSelectOneMenu");
selectElement.setJsfid("securitycheck");
selectElement.setId("securitycheck");
ElementBean itemElement = new ElementBean();
itemElement.setComponentType("javax.faces.SelectItem");
itemElement.setJsfid("selectItem");
itemElement.setRenderId(generateId());
AttributeBean attr = new AttributeBean();
attr.setName("itemValue");
attr.setValue("value1");
itemElement.addAttribute(attr);
attr = new AttributeBean();
attr.setName("itemLabel");
attr.setValue("Label");
itemElement.addAttribute(attr);
selectElement.addChild(itemElement);
ElementBean itemElement2 = new ElementBean();
itemElement2.setComponentType("javax.faces.SelectItem");
itemElement2.setJsfid("selectItem2");
itemElement2.setRenderId(generateId());
attr = new AttributeBean();
attr.setName("itemValue");
attr.setValue("value2");
itemElement2.addAttribute(attr);
attr = new AttributeBean();
attr.setName("disabled");
attr.setValue("true");
itemElement2.addAttribute(attr);
attr = new AttributeBean();
attr.setName("selected"); // fixme
attr.setValue("true");
itemElement2.addAttribute(attr);
selectElement.addChild(itemElement2);
root.addChild(selectElement);
RE: HtmlSelectOneMenu dynamically
Posted by Mike Otto <mi...@morning.in-berlin.de>.
Hello Richard,
thanks for answering. Now I have a clue about what I should do ..
The code below works like a charm, except that I don't know how
to declare a item as selected. I looked up
javax.faces.component.UISelectItem.class
and found
private String _itemDescription = null;
private Boolean _itemDisabled = null;
private String _itemLabel = null;
private Object _itemValue = null;
private Object _value = null;
(no private Object _selected)
Besides I still do not have a solution for component type
javax.faces.SelectItem_s_ But I think with Items in singular
I have more control, right?
Regards Mike
// HTMLSelectOneMenu
ElementBean selectElement = new ElementBean();
selectElement.setComponentType("javax.faces.HtmlSelectOneMenu");
selectElement.setJsfid("securitycheck");
selectElement.setId("securitycheck");
ElementBean itemElement = new ElementBean();
itemElement.setComponentType("javax.faces.SelectItem");
itemElement.setJsfid("selectItem");
itemElement.setRenderId(generateId());
AttributeBean attr = new AttributeBean();
attr.setName("itemValue");
attr.setValue("value1");
itemElement.addAttribute(attr);
attr = new AttributeBean();
attr.setName("itemLabel");
attr.setValue("Label");
itemElement.addAttribute(attr);
selectElement.addChild(itemElement);
ElementBean itemElement2 = new ElementBean();
itemElement2.setComponentType("javax.faces.SelectItem");
itemElement2.setJsfid("selectItem2");
itemElement2.setRenderId(generateId());
attr = new AttributeBean();
attr.setName("itemValue");
attr.setValue("value2");
itemElement2.addAttribute(attr);
attr = new AttributeBean();
attr.setName("disabled");
attr.setValue("true");
itemElement2.addAttribute(attr);
attr = new AttributeBean();
attr.setName("selected"); // fixme
attr.setValue("true");
itemElement2.addAttribute(attr);
selectElement.addChild(itemElement2);
root.addChild(selectElement);
RE: HtmlSelectOneMenu dynamically
Posted by Richard Eggert <re...@proteus-technologies.com>.
Err... ignore the comment about InnerComponentBean. That was just me confusing myself.
Rich Eggert
Member of Technical Staff
Proteus Technologies, LLC
http://www.proteus-technologies.com
-----Original Message-----
From: Richard Eggert [mailto:reggert@proteus-technologies.com]
Sent: Mon 9/10/2007 11:13 AM
To: user@shale.apache.org
Subject: RE: HtmlSelectOneMenu dynamically
I haven't tried to do anything like this myself, but it seems to me that you should just need to do something along these lines:
ElementBean inputElement = new ElementBean();
inputElement.setComponentType("javax.faces.HtmlSelectOneMenu");
inputElement.setJsfid("securitycheck");
inputElement.setId("securitycheck");
// Added by me
ElementBean optionsElement = new ElementBean(); // use InnerComponentBean instead?
optionsElement.setComponentType("javax.faces.SelectItems");
optionsElement.setJsfid("selectItems");
// TODO: fill in SelectItems-specific details (perhaps using addAttributes?)
inputElement.addChild(optionsElement);
// Alternatively, use a series of SelectItem elements instead of a single SelectItems.
root.addChild(inputElement);
I hope this helps!
Rich Eggert
Member of Technical Staff
Proteus Technologies, LLC
http://www.proteus-technologies.com
-----Original Message-----
From: Mike Otto [mailto:mike@morning.in-berlin.de]
Sent: Mon 9/10/2007 9:45 AM
To: user@shale.apache.org
Subject: HtmlSelectOneMenu dynamically
How do I create
HtmlSelectManyListbox, HtmlSelectOneRadio, HtmlSelectOneMenu dynamically with
clay?
In the rolodex example I found a function with the name
"createInputElementMetadata" which teaches me how to create links.
// create a command link attribute
ElementBean link = new ElementBean();
link.setRenderId(generateId());
link.setJsfid("commandLink");
link.setComponentType("javax.faces.HtmlCommandLink");
I tried this:
ElementBean inputElement = new ElementBean();
inputElement.setComponentType("javax.faces.HtmlSelectOneMenu");
inputElement.setJsfid("securitycheck");
inputElement.setId("securitycheck");
root.addChild(inputElement);
This is the output
<select id="systemform:securitycheck" name="systemform:securitycheck"
size="1"></select>
Well I am missing the <option>-Tags .. any idea how to add
the option attributes dynamically is appreciated
as well as any documentation about the subject :-)
Best Regards
Mike
RE: HtmlSelectOneMenu dynamically
Posted by Richard Eggert <re...@proteus-technologies.com>.
I haven't tried to do anything like this myself, but it seems to me that you should just need to do something along these lines:
ElementBean inputElement = new ElementBean();
inputElement.setComponentType("javax.faces.HtmlSelectOneMenu");
inputElement.setJsfid("securitycheck");
inputElement.setId("securitycheck");
// Added by me
ElementBean optionsElement = new ElementBean(); // use InnerComponentBean instead?
optionsElement.setComponentType("javax.faces.SelectItems");
optionsElement.setJsfid("selectItems");
// TODO: fill in SelectItems-specific details (perhaps using addAttributes?)
inputElement.addChild(optionsElement);
// Alternatively, use a series of SelectItem elements instead of a single SelectItems.
root.addChild(inputElement);
I hope this helps!
Rich Eggert
Member of Technical Staff
Proteus Technologies, LLC
http://www.proteus-technologies.com
-----Original Message-----
From: Mike Otto [mailto:mike@morning.in-berlin.de]
Sent: Mon 9/10/2007 9:45 AM
To: user@shale.apache.org
Subject: HtmlSelectOneMenu dynamically
How do I create
HtmlSelectManyListbox, HtmlSelectOneRadio, HtmlSelectOneMenu dynamically with
clay?
In the rolodex example I found a function with the name
"createInputElementMetadata" which teaches me how to create links.
// create a command link attribute
ElementBean link = new ElementBean();
link.setRenderId(generateId());
link.setJsfid("commandLink");
link.setComponentType("javax.faces.HtmlCommandLink");
I tried this:
ElementBean inputElement = new ElementBean();
inputElement.setComponentType("javax.faces.HtmlSelectOneMenu");
inputElement.setJsfid("securitycheck");
inputElement.setId("securitycheck");
root.addChild(inputElement);
This is the output
<select id="systemform:securitycheck" name="systemform:securitycheck"
size="1"></select>
Well I am missing the <option>-Tags .. any idea how to add
the option attributes dynamically is appreciated
as well as any documentation about the subject :-)
Best Regards
Mike