Inside my controller StudentController
I have a variable Course course
and I want to set this variable with the value, selected in a selectOneMenu
, inside my JSF-page. Clicking the save-button would temporarily just call the JSF-page index
(I will fill that part with my own code that will persist the student course, which will not be a problem).
The corresponding part in my JSF-page:
<h:form>
<h:panelGrid columns="2" style="margin-bottom:10px" cellpadding="5">
<p:outputLabel for="course" value="Select Course:" />
<p:selectOneMenu id="course" value="#{studentController.course}">
<f:selectItem itemLabel="--- Please Select ---" itemValue="" />
<f:selectItems value="#{studentController.courses}" var="course"
itemLabel="#{course.name}" itemValue="#{course}" />
</p:selectOneMenu>
</h:panelGrid>
<p:commandButton action="index?faces-redirect=true"
value="Save" icon="ui-icon-circle-check" />
</h:form>
The corresponding part in the controller:
@ManagedBean
@SessionScoped
public class StudentController {
// list contains available courses, is not empty
private List<Course> courses;
private Course course = new Course();
// getter, setter and other functionality
}
When I click the save-button, nothing happens. No error messages in my console, no redirecting.
How can I store the value, selected on the selectOneMenu
inside my course
variable?