Edit:
looks like this is called a "complex type" in Entity Framework, and I see how I would be able to set the name on columns for having once complex type contained in a class, but I don't know how/if you can do it with multiple of the same complex type contained in the class.
http://blogs.msdn.com/b/wriju/archive/2010/07/26/ef4-complex-type.aspx
EntityFramework 4.1 Code First incorrectly names complex type column names
Since Castle ActiveRecord has been sunset, I am moving over to Entity Framework 5, however I don't know how to accomplish the "nested property" concept that Activerecord had:
http://docs.castleproject.org/Active%20Record.Mappings.ashx#Nested_5
http://docs.castleproject.org/Default.aspx?Page=Nested%20data%20%28NHibernate%20components%29&NS=Active%20Record&AspxAutoDetectCookieSupport=1
I've done my googling, but I'm not sure that "nested" is the proper terminology for this concept in EF, if it even exists. Here are my tables and classes that I had in Castle ActiveRecord, can someone please provide the EF terminology for this and how it can be accomplished:
The Address property on AmaStatementEntity marked with <Nested(ColumnPrefix:="FL")))> maps to the database columns FLStreet, FLSuite, FLCity, etc.
CREATE TABLE [dbo].[AMA](
--other columns not necessary to discussion removed
[AMAId] [uniqueidentifier] NOT NULL,
[FLStreet] [nvarchar](255) NULL,
[FLSuite] [nvarchar](255) NULL,
[FLCity] [nvarchar](255) NULL,
[FLZipCode] [nvarchar](255) NULL,
[FLCountry] [nvarchar](255) NULL,
[FLState] [nvarchar](255) NULL,
[BAStreet] [nvarchar](255) NULL,
[BASuite] [nvarchar](255) NULL,
[BACity] [nvarchar](255) NULL,
[BAZipCode] [nvarchar](255) NULL,
[BACountry] [nvarchar](255) NULL,
[BAState] [nvarchar](255) NULL,
[PAStreet] [nvarchar](255) NULL,
[PASuite] [nvarchar](255) NULL,
[PACity] [nvarchar](255) NULL,
[PAZipCode] [nvarchar](255) NULL,
[PACountry] [nvarchar](255) NULL,
[PAState] [nvarchar](255) NULL,
[IAStreet] [nvarchar](255) NULL,
[IASuite] [nvarchar](255) NULL,
[IACity] [nvarchar](255) NULL,
[IAZipCode] [nvarchar](255) NULL,
[IACountry] [nvarchar](255) NULL,
[IAState] [nvarchar](255) NULL,
[EAStreet] [nvarchar](255) NULL,
[EASuite] [nvarchar](255) NULL,
[EACity] [nvarchar](255) NULL,
[EAZipCode] [nvarchar](255) NULL,
[EACountry] [nvarchar](255) NULL,
[EAState] [nvarchar](255) NULL,
[PYAStreet] [nvarchar](255) NULL,
[PYASuite] [nvarchar](255) NULL,
[PYACity] [nvarchar](255) NULL,
[PYAZipCode] [nvarchar](255) NULL,
[PYACountry] [nvarchar](255) NULL,
[PYAState] [nvarchar](255) NULL,
CONSTRAINT [PK_AMA] PRIMARY KEY CLUSTERED
(
[AMAId] ASC
))
Public Class AmaStatementEntity
Public Sub New()
_amaId = Guid.NewGuid
End Sub
'Other properties not relavent to discussion removed
<Nested(ColumnPrefix:="FL")))>
Public Property FacilityLocation() As AddressEntity
<Nested(ColumnPrefix:="BA"))>
Public Property BillingAddress() As AddressEntity
<Nested(ColumnPrefix:="PA"))>
Public Property PatientAddress() As AddressEntity
<Nested(ColumnPrefix:="IA"))>
Public Property InsuredAddress() As AddressEntity
<Nested(ColumnPrefix:="EA"))>
Public Property EmployerAddress() As AddressEntity
<Nested(ColumnPrefix:="PYA"))>
Public Property PayorAddress() As AddressEntity
Public Property AMAId() As Guid
End Class
Public Class AddressEntity
Public Property Street() As String
Public Property Suite() As String
Public Property City() As String
Public Property State() As String
Public Property ZipCode() As String
Public Property Country() As String
Public Property AddressId() As Guid
End Class
Once I found the correct terminology I was able to find the answer:
Entity Framework - Reuse Complex Type
for my specific scenario this is how you would do it (example shows mapping of one of the comlex type references):
modelBuilder.ComplexType<AddressEntity>();
modelBuilder.Entity<AmaStatementEntity>().ToTable("vAMA");
modelBuilder.Entity<AmaStatementEntity>().HasKey(a => a.AMAId);
modelBuilder.Entity<AmaStatementEntity>().Property(a => a.FacilityLocation.Street).HasColumnName("FLStreet");
modelBuilder.Entity<AmaStatementEntity>().Property(a => a.FacilityLocation.Suite).HasColumnName("FLSuite");
modelBuilder.Entity<AmaStatementEntity>().Property(a => a.FacilityLocation.City).HasColumnName("FLCity");
modelBuilder.Entity<AmaStatementEntity>().Property(a => a.FacilityLocation.ZipCode).HasColumnName("FLZipCode");
modelBuilder.Entity<AmaStatementEntity>().Property(a => a.FacilityLocation.Country).HasColumnName("FLCountry");
modelBuilder.Entity<AmaStatementEntity>().Property(a => a.FacilityLocation.State).HasColumnName("FLState");
Related
For the sake of clarity (and brevity) I am listing just the key segments of my code.
I have a backing bean MemberView containing two nested classes:
private Person person;
private Member member;
that are instantiated when the page loads:
#PostConstruct
public void init() {
person = new Person();
member = new Member();
}
with the appropriate getters and setters. I have a web page, member.xhtml, that utilizes PrimeFaces and displays nested class properties:
<p:inputText value="#{memberView.person.lastName}" />
<p:inputText value="#{memberView.member.id}" />
and a CommandButton that calls a search routine in the backing bean:
<p:commandButton value="Retrieve" type="submit"
actionListener="#{memberView.fetchMembers()}"
update="#all"/>
The page loads without incident. But selecting the CommandButton results in an EL ContextAwarePropertyNotFoundException: javax.el.PropertyNotFoundException: Target Unreachable, 'member' returned null.
To track what is happening, I added some logging to the get- and setMember methods:
public Member getMember() {
LOG.info("getMember() invoked");
if(member == null) {
LOG.log(Level.WARNING, "getMember() returning NULL");
}
LOG.info("getMember() returning Member: " + member.toString()
+ " with ID: " + member.getId());
return member;
}
public void setMember(Member member) {
LOG.info("setMember() invoked with argument: " + member);
this.member = member;
}
Here is the output when I click on the CommandButton:
INFO: getMember() invoked
INFO: getMember() returning Member: scc.model.Member#6f453701 with ID: null
INFO: getMember() invoked
INFO: getMember() returning Member: scc.model.Member#6f453701 with ID: null
INFO: getMember() invoked
INFO: getMember() returning Member: scc.model.Member#6f453701 with ID: null
INFO: setMember() invoked with argument: null
INFO: getMember() invoked
WARNING: getMember() returning NULL
Clearly, the class Member is being nulled out. One further detail. If I comment out the member ID input field
<!-- <p:inputText value="#{memberView.member.id}" /> -->
and then select the Retrieve button, the page populates a dataTable with the names of members and the name field, as supplied by the nested MemberView Person class:
<p:dataTable id="dtPerson" var="member"
style="margin-top:10px;text-align:center;width:400px;minWidth:400px"
value="#{memberView.selectableMemberList}"
selectionMode="single" editable="false"
selection="#{memberView.member}" >
<p:inputText value="#{memberView.person.lastName}" />
I am at a complete loss to explain the EL call to the setMember method with a null argument after three calls that successfully returned the instantiated class. I am open to any and all suggestions.
Thanks to you both for your timely and helpful responses. Following BalusC's suggestion, a trace shows that the Method class is nulled during DataTable.processUpdates. Since there is no row data, and therefore no Member to be found in the table, the PrimeFaces SelectableDataModel returns null, which is then set by the JSF method BeanELResolver.setValue.
My prior databases all utilize many-to-one relationships where ArrayLists are populated on post-construct and, by design, are never empty thereafter. One possible resolution here would be to populate the data table when the page loads, as suggested in this 2006 post by BalusC ("You can load the dataList in either the constructor or initialization block of the [backing] bean.") http://balusc.omnifaces.org/2006/06/using-datatables.html
A more general solution is to provide the data table with a blank, not empty, data list, both on initialization and whenever a query returns an empty result set:
/**
* Member edited/displayed in web page text fields
*/
private Member member;
/**
* List of Member Objects
*/
private List<Member> mList;
/**
* Member List implementing PF SelectableDataModel
*/
private SelectableMemberList selectableMemberList;
/**
* Creates a blank [not empty] SelectableMemberList.
* Call on PostConstruct & on return of empty result set.
*/
private void blankSelectableMemberList() {
if(mList == null) { // instantiate on init()
mList = new ArrayList<>();
}
if(mList.isEmpty()) { // add blank Object
mList.add(new Member());
}
selectableMemberList = new SelectableMemberList(mList);
}
I hope this is helpful to anyone who wants to display an "empty" data table.
I have 3 entities - markets, topics and items. Markets is the parent of topics which is the parent of items. I'm hoping to find a simple way to invoke an action by selecting a value from the the final child node (items) and being taken to the page where the selected item can be viewed. The JSF:
<p:tree value="#{treeTestBean.treeTest}" var="tree"
dynamic="true"
selectionMode="single"
selection="#{treeTestBean.selectednode}">
<p:ajax event="select" listener="#{treeTestBean.onNodeSelect}"/>
<p:treeNode>
<h:outputText value="#{tree}"/>
</p:treeNode>
</p:tree>
The managed bean:
#Named(value = "treeTestBean")
#SessionScoped
public class TreeTestBean implements Serializable {
private TreeNode treetest;
private TreeNode selectednode;
private TreeNode node0;
private TreeNode node1;
private TreeNode node2;
private List<Enmarkets> markList;
private List<Entopic> topList;
private ListDataModel<Enitem> itList;
private Enitem selItem;
public TreeNode getTreeTest() {
treetest = new DefaultTreeNode("Root", null);
markList = rootFacade.findAll();
for (Enmarkets m : markList) {
node0 = new DefaultTreeNode(m.getMarketname(), treetest);
int marketid = m.getMarketid();
topList = topfac.marketTopNorm(marketid);
for (Entopic t : topList) {
node1 = new DefaultTreeNode(t.getTopicname(), node0);
int topicid = t.getTopicid();
itList = itfac.itemFroTopic(topicid);
for (Enitem i : itList) {
node2 = new DefaultTreeNode(i.getItemname(), node1);
}
}
}
return treetest;
}
The onNodeSelect method used in the ajax is also in the managed bean. If the selected node is a leaf it will search the item name and return that in the navigated page:
public void onNodeSelect(NodeSelectEvent event) {
this.setSelectednode(event.getTreeNode());
String somekey = selectednode.getRowKey();
if(selectednode.isLeaf()){
String itemName = selectednode.getData().toString();
// Standard JPA call to search for item name here (omitted because this is not how i want to do it)
FacesContext
.getCurrentInstance()
.getApplication()
.getNavigationHandler()
.handleNavigation(FacesContext.getCurrentInstance(), null, "/Main/Starter.xhtml?faces-redirect=true");
}
else {
doNothing();
}
}
onNodeSelect is supposed to search the item name and navigates to the page with details of the selected item. The above method does this by searching for the Item name String and matching this to the name in a list of the item entity values created from the persistence layer. This will allow matching the selectednode String to the correct item name, so that the navigated jsf page is populated with the entity details (for example using a standard h:outputText tag). For several reasons, i prefer to search based on the entity ID instead of a String.
Comments from Kukeltje greatly helped me in the right direction. First I include a Map(String, int) when creating the leaf node:
for (Enitem i : itList) {
node2 = new DefaultTreeNode(i.getItemname(), node1);
String rowK = node2.getRowKey();
int itid = i.getItemid();
rowMap.put(rowK, itid);
Then, in the onNodeSelect method I use this map to match the rowKey of the selectednode to the corresponding entity Id:
public void onNodeSelect(NodeSelectEvent event) {
if(selectednode.isLeaf()){
String rKey = selectednode.getRowKey();
if(rowMap.containsKey(rKey)) {
String xKey = rowMap.get(rKey).toString();
Integer rKeyint = Integer.parseInt(xKey);
selItem = itfac.find(rKeyint);
FacesContext
.getCurrentInstance()
.getApplication()
.getNavigationHandler()
.handleNavigation(FacesContext.getCurrentInstance(), null, "/Main/Client/ItemDetails.xhtml?faces-redirect=true");
}
}
else {
doNothing();
}
This navigates to the page showing the detail of the selected node leaf. I suspect there might be an easier or more efficient way of doing this and would welcome any views. Like, I don't know if it's really necessary to make the string to integer conversions and I didn't think through a simpler way.
For now, this seems to solve my concrete problem. thanks
There are three tables in MySQL database, category, sub_category and brand (manufacturer) where category is a parent of the rest i.e. sub_category and brand. I hope, the relationship between menus can be clearer based on the table relationships.
All of three <p:selectOneMenu>s are placed inside a <p:dataTable> in three respective columns as identified by <p:column>. I am ignoring <p:column>, <p:cellEditor>, <f:facet name="output">, <f:facet name="input">, <p:rowEditor> and all such nuisances for brevity.
row corresponds to a JPA managed entity which is product in this case as specified by var="row" in the <p:dataTable> associated.
This is the actual question mark : When an item (the first one) with a null value in the categoryList (parent) is selected, its child lists subCategoryList and brandList should be rest to empty.
Category List:
<p:selectOneMenu id="categoryList"
value="#{row.category}"
required="#{param['javax.faces.source'] ne component.clientId}">
<f:selectItem itemLabel="Select"
itemValue="#{null}"/>
<!-- When this item is selected, its children below should be reset to empty. -->
<f:selectItems var="category"
value="#{productManagedBean.categories}"
itemLabel="Select"
itemValue="#{category}"/>
<p:ajax update="subCategoryList brandList"/>
<!-- The listener functionality is left incomplete here. -->
</p:selectOneMenu>
Subcategory List :
<p:selectOneMenu id="subCategoryList"
value="#{row.subCategory}">
<f:selectItem itemLabel="Select"
itemValue="#{null}"/>
<f:selectItems var="subCategory"
value="#{productManagedBean.getSubCategories(row.category)}"
itemLabel="#{subCategory.subCatName}"
itemValue="#{subCategory}"
rendered="true"/>
</p:selectOneMenu>
Brand (manufacturer) List :
<p:selectOneMenu id="brandList"
value="#{row.brand}">
<f:selectItem itemLabel="Select"
itemValue="#{null}"/>
<f:selectItems var="brand"
value="#{productManagedBean.getBrands(row.category)}"
itemLabel="#{brand.brandName}"
itemValue="#{brand}"
rendered="true"/>
</p:selectOneMenu>
The managed bean (lazy data model can be ignored in the context of this question) :
#Named
#ViewScoped
public class ProductManagedBean extends LazyDataModel<Product> implements Serializable {
#Inject
private Service service;
// Associated with <p:selectOneMenu id="categoryList">.
private List<Category> categories; // Getter & setter.
// These are merely helper maps to reduce possible database calls.
private Map<Category, List<SubCategory>> subCategoriesByCategory;
private Map<Category, List<Brand>> brandByCategory;
public ProductManagedBean() {}
#PostConstruct
private void init() {
// This can be application scoped somewhere else as per business requirement.
categories = service.getCatgeoryList();
subCategoriesByCategory = new HashMap<Category, List<SubCategory>>();
brandByCategory = new HashMap<Category, List<Brand>>();
}
// This method populates <f:selectItems> associated with <p:selectOneMenu id="brandList">.
public List<SubCategory> getSubCategories(Category category) {
// category is never null here unless something is broken deliberately.
if (category == null) {
return null;
}
List<SubCategory> subCategories = subCategoriesByCategory.get(category);
if (subCategories == null) {
subCategories = service.findSubCategoriesByCategoryId(category.getCatId());
subCategoriesByCategory.put(category, subCategories);
}
return subCategories;
}
// This method populates <f:selectItems> associated with <p:selectOneMenu id="brandList">.
public List<Brand> getBrands(Category category) {
// category is never null here unless something is broken deliberately.
if (category == null) {
return null;
}
List<Brand> brands = brandByCategory.get(category);
if (brands == null) {
brands = service.findBrandsByCategoryId(category.getCatId());
brandByCategory.put(category, brands);
}
return brands;
}
}
In any case, the selected value in any of these menus is not supplied to the corresponding backing bean. It is only available in the model backed by JPA (value="#{row.category}", value="#{row.subCategory}" and value="#{row.brand}" respectively).
► How to signal the backing bean that the first item with a nullvalue (labelled "Select") in the parent menu is selected so as to resetting its child lists to empty? This should happen in any feasible way, if this is not feasible.
I am using PrimeFaces 5.2 final (community release) and Mojarra 2.2.12.
This is not needed unless there is a null foreign key in the underlying database table specifically using the vendor specific ON DELETE SET NULL option allowing an optional parent in each (or some) corresponding child row.
To the point, you need to make sure that the <f:selectItem> getter is called with a null argument. In other words, the #{row.category} must be null. Given that you're for #{row.category} using the model als shown in this answer, Populate p:selectOneMenu based on another p:selectOneMenu in each row of a p:dataTable, most likely as below,
#Transient
private Category category;
public Category getCategory() {
return (category == null && subCategory != null) ? subCategory.getCategory() : category;
}
then the #{row.category} will actually never be null when there's a subCategory. This will be the case when an existing data entry is presented in view.
You basically need to explicitly null out the subCategory (and brand) when the transient category property is explicitly set to null. This oversight has in the meanwhile been fixed in the mentioned answer. Here's how your new setCategory() method should look like:
public void setCategory(Category category) {
this.category = category;
if (category == null) {
subCategory = null;
brand = null;
}
}
This way, the getCategory() will properly return null and thus the passed-in #{row.category} also.
We have a requirement to allow users to configure the order of columns in all datatables, including the columns that have action buttons on them, here p:commandButtons.
Hence we are using binding for all our columns which we must instantiate manually. For all columns that only display some strings, booleans, dates, and numbers all works fine, however problems start when adding p:commandButtons to the columns that have one or more <f:setPropertyActionListener>s on them.
ELContext elContext = FacesContext.getCurrentInstance().getELContext();
ExpressionFactory factory = FacesContext.getCurrentInstance().getApplication().getExpressionFactory();
CommandButton button = new CommandButton();
button.setIcon( "ui-icon ui-icon-pencil" );
button.setProcess( "#this" );
button.setUpdate( ":compliance-case-dialog :compliance-case-form:data" );
button.setOncomplete( "complianceCaseDialog.show();" );
ValueExpression targetExpression = factory.createValueExpression( elContext, "#{complianceCaseManager.selectedComplianceCaseWithRefresh}", ComplianceCase.class );
ValueExpression valueExpression = factory.createValueExpression( elContext, "#{coca}", ComplianceCase.class );
button.addActionListener( new SetPropertyActionListenerImpl( targetExpression, valueExpression ) );
column.getChildren().add( button ); // add to Column instance
This button "correctly" displays a <p:dialog>, but should call ComplianceCaseManager class' setSelectedComplianceCaseWithRefresh( ComplianceCase selectedComplianceCase ) method with the datatable's current entity (as defined by var="coca") before showing the dialog.
<p:dataTable id="data"
widgetVar="resultTable"
value="#{complianceCaseManager.complianceCases}"
var="coca"
...>
</p:dataTable>
Debugging shows the setSelectedComplianceCaseWithRefresh( ComplianceCase selectedComplianceCase ) method is never called.
Q:
What's wrong? How do you fix this?
PS: config is PrimeFaces 3.4.2, Mojarra 2.1.22, GlassFish 3.1.2.2, Java 7
Update 1:
Here's the p:commandButton I want to translate to programmatic:
<p:commandButton icon="ui-icon ui-icon-pencil"
title="#{msg['complianceCaseManager.data.edit.button.hint']}"
process="#this"
update=":compliance-case-dialog :compliance-case-form:data"
oncomplete="complianceCaseDialog.show();">
<p:resetInput target=":unlocked-form" />
<f:setPropertyActionListener target="#{complianceCaseManager.selectedComplianceCaseWithRefresh}" value="#{coca}" />
<f:setPropertyActionListener target="#{complianceCaseManager.mode}" value="EDIT" />
</p:commandButton>
The line
<f:setPropertyActionListener target="#{complianceCaseManager.selectedComplianceCaseWithRefresh}" value="#{coca}" />
is the one I must get to work.
The solution by kolossus to create a MethodExpressionActionListener did not work for my code:
String targetExpressionString = "#{complianceCaseManager.selectedComplianceCaseWithRefresh}";
String valueExpressionString = "#{coca}";
MethodExpression targetMethodExpression = factory.createMethodExpression( elContext, targetExpressionString, null, new Class<?>[]{ ComplianceCase.class } );
MethodExpression valueMethodExpression = factory.createMethodExpression( elContext, valueExpressionString, ComplianceCase.class, new Class<?>[0] );
button.addActionListener( new MethodExpressionActionListener( targetMethodExpression, valueMethodExpression ) );
AFAIK is made so that on the target the setter is called and on the value the setter is called, so I'd assume the ValueExpressions to be sufficient.
Update 2:
Trying to set the current entity via EL 2.2 method call also doesn't work.
Code:
String methodExpressionString = "#" + "{complianceCaseManager.selectedComplianceCaseWithRefresh(coca)}";
MethodExpression methodExpression = factory.createMethodExpression( elContext, methodExpressionString, null, new Class<?>[]{ ComplianceCase.class } );
button.addActionListener( new MethodExpressionActionListener( methodExpression ) );
Nothing is called.
Update 3:
Here's the correct <:setPropertyActionListener> code:
// traditional <f:setPropertyActionListener target="#{complianceCaseManager.selectedComplianceCaseWithRefresh}" value="#{coca}" />
ValueExpression targetExpression = factory.createValueExpression( elContext, "#{complianceCaseManager.selectedComplianceCaseWithRefresh}", ComplianceCase.class );
ValueExpression valueExpression = factory.createValueExpression( elContext, "#{coca}", ComplianceCase.class );
button.addActionListener( new SetPropertyActionListenerImpl( targetExpression, valueExpression ) );
Big thanks to kolossus. Remember to call setId() when instantiating a PrimeFaces CommandButton.
An actionListener should be created as a MethodExpression not a ValueExpression :
I'm assuming that factory instanceOf ExpressionFactory. Use the createMethodExpression factory
MethodExpression targetExpression = factory.createMethodExpression( elContext, "#{complianceCaseManager.selectedComplianceCaseWithRefresh(coca)}",null,new Class[]{ComplianceCase.class} );
Adding the listener to the component:
button.addActionListener( new MethodExpressionActionListener(targetExpression));
Not entirely related to the current problem, you also omitted the id attribute of the component. To be safe, add
button.setId("theButton");
EDIT: You absolutely have to set the id attribute when dynamically creating command components
I used to solve it by using a lambda expression:
private final ActionListener actionListener = (ActionEvent event) -> {
//code to execute
};
and then just:
set de CommandButton id comandButton.setId(id);
add de ActionListener commandButon.addActionListener(actionListener);
I'm creating a List of javax.faces.model.SelectItem (in a bean) for use with a h:selectManyCheckbox but I cannot figure out how to make a SelectItem selected.
How to do this? Must be possible, right?...
public List<SelectItem> getPlayerList(String teamName) {
List<SelectItem> list = new ArrayList<SelectItem>();
TeamPage team = (TeamPage) pm.findByName(teamName);
List<PlayerPage> players = pm.findAllPlayerPages();
for (PlayerPage player : players) {
boolean isMember = false;
if (team.getPlayerPages().contains(player)) {
isMember = true;
}
SelectItem item;
if (isMember) {
// TODO: Make SelectItem selected???
item = null;
} else {
item = new SelectItem(player.getId(), createListItemLabel(player), "", false, false);
}
list.add(item);
}
return list;
}
Assume we have this JSF code:
<h:selectManyCheckbox value="#{bean.selectedValues}">
<f:selectItems value="#{bean.playerList}"/>
</h:selectManyCheckbox>
then the selected values (i.e. the checked checkboxes) are stored in the bean.selectedValues property.
Thus, in your Java code, you must handle the selectValues by putting the correct ID in the selectedValues property.
If anybody is working with selectOneMenu and populating elements dynamically:
While creating a SelectItem, if you provide some value(first parameter) as follows:
new SelectItem("somevalue", "someLabel", "someDescription", false, false);
It translates to this in the html:
<option value="somevalue">someLabel</option>
If you do not provide a value as follows:
new SelectItem("", "someLabel", "someDescription", false, false);
, it translates to this
<option value="" selected="selected">someLabel</option>
Hence if you want an element to be the default on page load(like "Select one of these"), do not provide a value. If you create more than one element without a value, any one of them are chosen for default on page load(probably preference based on ascending alphabetical order).