issues getting the selected value from a selectOneMenu
angela Mar 24, 2011 6:55 AMgood morning!!!
I am quite new in this community and excuse me if my english is little incorrect
I'm facing some issues for a while know concerning a selected value from the selectOneMenu.
Actually, what I'm trying to do is to create a new user for my application and each user must have a specific profil. so ,for a simple use, I made a drop down list from the profil datatable.
In the user datatable, I have idprofil which is a foreign key that references the idprofil in the profil datatable. I hope that was a little clear...
The problem is that i can't find out how to get the value of the profil selected and save it.
here is some parts of the code:
UserAdd.xhtml
<s:decorate id="emailField" template="layout/edit.xhtml">
<ui:define name="label">Email</ui:define>
<h:inputText id="email"
required="true"
size="45"
maxlength="45"
value="#{utilisateurHome.instance.email}">
<a:support event="onblur" reRender="emailField" bypassUpdates="true" ajaxSingle="true"/>
</h:inputText>
</s:decorate>
<s:decorate id="profilField" template="layout/edit.xhtml">
<ui:define name="label">Profil</ui:define>
<h:selectOneMenu value="#{selectedProfil}" id="profil" required="true">
<s:selectItems value="#{profilToTrack}"
var="_profil"
label="#{_profil.profil}"
noSelectionLabel="Please Select ..." />
<s:convertEntity />
<a:support event="onchange" action="#{profilAction.test()}" reRender="profilField" />
</h:selectOneMenu>
</s:decorate>ProfilActionBean.java
@Scope(ScopeType.CONVERSATION)
@Name("profilAction")
public class ProfilActionBean implements ProfilAction, Serializable {
/**
*
*/
private static final long serialVersionUID = -3853383063011157886L;
@In(create = true)
private ProfilList profilList;
@Logger private Log log;
@DataModel
private List<Profil> profilToTrack = new ArrayList<Profil>();
@Out(required = false)
@In(required = false)
private Profil selectedProfil = new Profil();
@Factory("profilToTrack")
public List<Profil> initProfilToTrack() {
profilToTrack = profilList.getResultList();
System.out.println("initProfilToTrack");
return profilToTrack;
}
public Profil getSelectedProfil() {
log.info(">>>>> get selectedPerson");
if (this.selectedProfil != null) {
log.info(">>>>> get getSelectedProfil selectedProfil = "
+ this.selectedProfil.getProfil());
}
return this.selectedProfil;
}
public void setSelectedProfil(Profil profil) {
this.selectedProfil = profil;
}
public void test() {
System.out.println("test");
System.out.println(selectedProfil == null ? "null" : selectedProfil.getIdprofil());
}
}
PS: the test method works fine, when I choose a value from the dropdown list i get the correct Idprofil
I'm ready for any further explanation
please if someone can help I will be very thankful :)