Hi, guys. Please, could someone help me?
I have following problem: I need to retreive projectNames from DataBase into<h:selectOneMenu ...><f:selectItems ...></f:selectItems></h:selectOneMenu>. I do it this way(part of .jsp page as I think the problem is in it):
----------------------------------------------------------------------------
<h:selectOneMenu value="#{SubmitReport.projectName}"
styleClass="common-dropdown" required="true" >
<f:selectItems value="#{SubmitReport.loggedUserProjects}"/>
</h:selectOneMenu>
----------------------------------------------------------------------------
I succeed in retreiving projectNames from DataBase and displaying on the page. But when I press submit in browser:
----------------------------------------------------------------------------
<h:commandButton value="Submit" id="SubmitCommand" action="#{SubmitReport.submitReport}"
immediate="true">
----------------------------------------------------------------------------
projectName variable of backingBean appears to be null, when it must already have been initialized(there is setter/getter for projectName in backingBean). If I remove immediate="true" in <h:commandButton ...> the page just refreshes, but the submitReport() method of the backingBean is not invoked at all...
In backingBean(SubmitReport) the 2 variables - projectName & loggedUserProjects are:
-----------------------------------------------------------------
private
String projectName;
private ArrayList<SelectItem> loggedUserProjects;
public String getProjectName() {
return this.projectName;
}
public void setProjectName(String projectName) {
this.projectName = projectName;
}
public void setLoggedUserProjects(ArrayList<SelectItem> loggedUserProjects) {
this.loggedUserProjects = loggedUserProjects;
}
public ArrayList<SelectItem> getLoggedUserProjects() {
return loggedUserProjects = extractUserProjectsFromDB();
}
-----------------------------------------------------------------
And I tried to change the type of projectName to SelectItem - didn't help.
And one more detail:
I debugged the application, when I press submit in submitReport() of backingBean I tracked the contained values in request like this:
------------------------------------------------------------------
public String submitReport() {
...
Map allParams;
if (this.projectName == null) {
allParams = ((HttpServletRequest)FacesContext.getCurrentInstance().
getExternalContext().getRequest()).getParameterMap();
System.out.println(allParams.size());
}
------------------------------------------------------------------
So in principle if projectName == null, I can retreive it from request "by hands" - but it's wrong,
JSF MUST DO THIS. Seems like I configured smt. wrong or misunderstood.
What is the problem in? I have already been fighting this for 2 days - but no luck. So, Gurus, please I need Your help...