2014-03-06 120 views
0

我在h中有一個actionListener h:commandButton但是當按下時找不到方法錯誤。未找到JSF actionListener方法

下面的代碼:

<h:form id="course"> 
    <ui:repeat value="#{stationCourses.course}" var="course"> 
     <h:commandButton class="buttons" 
      id="courseID" 
      value="#{course.courseName}" 
      actionListener="#{stationCourses.courseSelected}" 
      style="alignment-adjust: central; 
      white-space: pre-line; word-wrap: break-word;"/> 
    </ui:repeat>    
</h:form> 

和bean:

import javax.faces.event.ActionEvent; 
import java.io.Serializable; 
import javax.faces.bean.ManagedBean; 
import javax.faces.bean.RequestScoped; 
import java.util.List; 

@ManagedBean 
@RequestScoped 
public class StationCourses implements Serializable { 

//provide connection to db 
private CourseQueries cq = new CourseQueries(); 
private List<Course> courses = cq.getCourses("station_naas"); 
private int courseNumber; 

public void setCourse() 
{ 
    courses = cq.getCourses("station_naas"); 
}//end method setCourse 

public List<Course> getCourse() { 
    return courses; 
}//end method getCourseID 

public void getCourseSelected(ActionEvent event) 
{  
    // course:j_idt6:1:courseID"; 

    //HTML buttons generate ID like the one above 
    //get char at 14 will get the unique button number 
    //we get course according to that button and -1 
    //to correct the off by one error 
    courseNumber = event.getComponent().getId().charAt(14) - 1; 

    System.out.println(courses.get(courseNumber).getCourseID()); 
}//getCourseSelected 

}//end class StationCourses 

回答

1
作爲

<h:form id="course"> 
       <ui:repeat value="#{stationCourses.course}" var="course"> 
        <h:commandButton class="buttons" 
           id="courseID" 
           value="#{course.courseName}" 
           actionListener="#{stationCourses.getCourseSelected}" 
           style="alignment-adjust: central; 
           white-space: pre-line; word-wrap: break-word;"/> 
       </ui:repeat>    
      </h:form> 

的行動和的ActionListeners就不得不提到確切的方法名不同於

更改您的密碼變量。

+0

謝謝!在允許的情況下接受答案:)。 – RoMEJA

+0

歡迎您:) –