西洛!
我用JSF编写了一些Java代码,并且在单击“注册按钮”时调用的方法不会运行。 财务主任:
package controllers;
import beans.EntityBean;
import entities.User;
import javax.annotation.ManagedBean;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named;
@Named(value = "ucb")
@RequestScoped
public class UserControllerByAkos {
@Inject
private EntityBean bean;
private User user=new User();
public UserControllerByAkos(){}
public String doRegister(){
System.out.println("doResigter method invoked.");
getUser().setRole("user");
getBean().createEntity(User.class, getUser());
return "profil.xhtml";
}
public EntityBean getBean() {
return bean;
}
public void setBean(EntityBean bean) {
this.bean = bean;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
}
register.xhtml:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<h:head>
<title>Registration</title>
</h:head>
<h:body>
</h:body>
<ui:composition>
<h:form>
<h:panelGrid bgcolor="00CCFF" id="panel" columns="2" border="1" cellpadding="4" cellspacing="4" width="500">
<h:outputLabel value="Username:" />
<h:inputText value="#{ucb.user.username}"/>
<h:outputLabel value="Password:" />
<h:inputSecret value="#{ucb.user.password}" />
<h:outputLabel value="Name:" />
<h:inputText value="#{ucb.user.fullName}"/>
<h:outputLabel value="DateOfBirth:" />
<input type="number" value="#{ucb.user.yearOfBirth}"/>
<h:outputLabel value="Gender:"/>
<h:selectOneRadio value="#{ucb.user.gender}">
<f:selectItem itemValue="female" itemLabel="Female" />
<f:selectItem itemValue="male" itemLabel="Male" />
</h:selectOneRadio>
</h:panelGrid>
<h:commandButton value="Register" action="#{ucb.doRegister}">
<f:ajax execute="@form" render=":booklist:errors"/>
</h:commandButton>
</h:form>
<br/>
<br/>
<h:commandButton value="Back"/>
</ui:composition>
</html>
我尝试了大约6种变体,但没有它们有效。 我会在这里调用这个方法:
<h:commandButton value="Register" action="#{ucb.doRegister}">