【问题标题】:JSF actionListener method not found未找到 JSF actionListener 方法
【发布时间】:2014-03-06 10:52:35
【问题描述】:

我在 h:commandButton 中有一个 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>

还有豆子:

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

【问题讨论】:

    标签: java jsf events javabeans


    【解决方案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>  
    

    对于动作和动作侦听器,您必须提及与变量不同的确切方法名称。

    【讨论】:

    • 谢谢!在允许的情况下接受答案:)。
    猜你喜欢
    • 2019-05-08
    • 2017-02-15
    • 2018-02-14
    • 1970-01-01
    • 1970-01-01
    • 2013-08-03
    • 2016-03-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多