I am new in working with JSF and i am trying to write a simple code for a training center
In this JSF code, the subjects array is working fine when i load page but when i submit page, it gives me a null pointer exception , i do not know why this happen.
**The Java Bean Code :**
===============================================
College.java:
===============================================
package Training_Center;
import javax.faces.bean.ManagedBean;
@ManagedBean(name = "College")
public class College {
private int college; // College Number HardCoded from College.xhtml page(Drop Down List)
private String special[] = new String[4]; //specialization array (Radio Button)
private String specialTicked; //Variable to store the element value from special[] array
private String subjects[] = new String[4];//Subjects[] array ( Check Boxes )
public College() {
}
public int getCollege() {
return college;
}
public void setCollege(int college) {
this.college = college;
}
public String[] getSpecial() {
if (getCollege() == 0) { // AOU Unoversity
special[0] = "AAAA";
special[1] = "IT";
special[2] = "BBBB";
special[3] = "CCCC";
}
return special;
}
public String getSpecialTicked() {
return specialTicked;
}
public void setSpecialTicked(String specialTicked) {
this.specialTicked = specialTicked;
}
public String[] getSubjects() {
if ("IT".equals(specialTicked)) {
subjects[0] = "M105 Introduction To Java";
subjects[1] = "M257 Java OOP";
subjects[2] = "M275 PHP";
subjects[3] = "M180 Data Structure";
}
return subjects;
}
public void setSubjects(String[] subjects) {
this.subjects = subjects;
}
}
=======================================================
College.xhtml page:
========================================================
<h:form >
<h:selectOneMenu value="#{College.college}" >
<f:selectItem itemValue="-1" itemLabel="...Select..." />
<f:selectItem itemValue="0" itemLabel="AOU University" />
</h:selectOneMenu>
<h:commandButton value="Show Subjects" action="ShowSubjects" />
</h:form>
=====================================================
ShowSubjects.xhtml page :
=====================================================
<h:form>
<h:selectOneRadio value="#{College.specialTicked}" layout="pageDirection" >
<f:selectItems value="#{College.special}" ></f:selectItems>
</h:selectOneRadio>
<h:commandButton value="Submit" action="subjects" />
</h:form>
========================================================
subjects..xhtml page : ( this page gives the exception when i click submit button)
======================================================
<h:form>
<h:selectManyCheckbox value="#{College.subjects}" layout="pageDirection" >
<f:selectItems value="#{College.subjects}" ></f:selectItems>
</h:selectManyCheckbox>
<h:commandButton value="Submit"/>
</h:form>
Thanks