I am using jsf 1.2 selectonemenu, i have a requirement that when the page loads with the selectonemenu will load some data from database and a value will be selected in the listbox.i have done it using hardcode values.But When it is coming from DB it is not working, i am posting both my hardcode and db coding.
<h:selectOneMenu id="submenu" value="three">
<f:selectItem id="si1" itemLabel="One" itemValue="one" />
<f:selectItem id="si2" itemLabel="Two" itemValue="two" />
<f:selectItem id="si3" itemLabel="Three" itemValue="three" />
<f:selectItem id="si4" itemLabel="Four" itemValue="four" />
</h:selectOneMenu>
DB Coding
<h:selectOneMenu id="submenu">
<f:selectItem id="si1" itemValue="${useBean.memberDependentList}" />
</h:selectOneMenu>
My Bean class
List<DependentDTO> dependentList = new MemberProxy()
.getDependentListFormMember( loggedInUser
.getUserAccessList().get(0).getClientCode(),
loggedInUser
.getUserAccessList().get(0).getCertificateNumber());
List<SelectItem> selList=new ArrayList<SelectItem>();
for(DependentDTO depDTO:dependentList){
SelectItem sel = new SelectItem();
sel.setLabel(depDTO.getNameFirst());
sel.setValue(depDTO.getCertNumber()+"#"+depDTO.getClientCode()+"#"+depDTO.getDependentCode());
selList.add(sel);
}
mem = new MemberProxy().getMemberDetails(loggedInUser
.getUserAccessList().get(0).getClientCode(), loggedInUser
.getUserAccessList().get(0).getCertificateNumber());
SelectItem sel = new SelectItem();
sel.setLabel(mem.getNameFirst());
sel.setValue(mem.getCertNumber().toString().trim()+"#"+mem.getClientCode().toString().trim()+"#"+depDTO.getDependentCode());
selList.add(sel);
memberDependent.setMemberDependentList(selList);
I am setting the person name in the label and the value i am setting the certificate number ,client code and dependent code ,here the dependent code is unique.Certificate number and client code are same in both cases.Can i do something with the dependent code? when the list is populating in the dropdown. Because my purpose is to show always the mem.getNameFirst() selected when page is loaded.Is it possible with any tricks???Please help i am new to JSF 1.2
How i will show three as selected when loding data from database