gpt4 book ai didi

java - 未找到 JSF actionListener 方法

转载 作者:行者123 更新时间:2023-12-01 13:18:51 25 4
gpt4 key购买 nike

我在 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>

和 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

最佳答案

将代码更改为

   <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>

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

关于java - 未找到 JSF actionListener 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22222270/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com