我想实现注册,但数据不会写入bean。 但是电子邮件数据在其他数据类型中是正确的是null。 我收到一些警告,但我认为问题必须在xhtml代码中。
我正在使用 谷歌应用引擎 jsf 2.1 primefaces 3.5Bean.java
@ManagedBean(name = "regiBean")
@SessionScoped
public class RegisterBean implements Serializable {
private String email;
private String username;
private String password;
private String repeatpassword;
private String firstname;
private String lastname;
private boolean gtc;
private String locale;
private static Map<String, Object> countries;
static {
countries = new LinkedHashMap<String, Object>();
countries.put("German", Locale.GERMAN);
countries.put("English", Locale.ENGLISH);
}
public RegisterBean() {
super();
}
public RegisterBean(String email, String username, String password,
String repeatpassword, String firstname, String lastname,
boolean gtc) {
super();
this.email = email;
this.username = username;
this.password = password;
this.repeatpassword = repeatpassword;
this.firstname = firstname;
this.lastname = lastname;
this.gtc = gtc;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getRepeatpassword() {
return repeatpassword;
}
public void setRepeatpassword(String repeatpassword) {
this.repeatpassword = repeatpassword;
}
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public boolean getGtc() {
return gtc;
}
public void isGtc(boolean gtc) {
this.gtc = gtc;
}
public Map<String, Object> getCountries() {
return countries;
}
public String getLocale() {
return locale;
}
public void setLocale(String locale) {
this.locale = locale;
}
public void showDialog() {
System.out.println("AUSGABE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!: " + toString());
//if(gtc == true)
{
RequestContext.getCurrentInstance().execute("myDialog.show();");
}
}
@Override
public String toString() {
return "RegisterBean [email=" + email + ", username=" + username
+ ", password=" + password + ", repeatpassword="
+ repeatpassword + ", firstname=" + firstname + ", lastname="
+ lastname + ", gtc=" + gtc + "]";
}
//value change event listener
public void localeChanged(ValueChangeEvent e){
String newLocaleValue = e.getNewValue().toString();
for (Map.Entry<String, Object> entry : countries.entrySet()) {
if(entry.getValue().toString().equals(newLocaleValue)){
FacesContext.getCurrentInstance()
.getViewRoot().setLocale((Locale)entry.getValue());
}
}
FacesContext.getCurrentInstance().renderResponse();
}
}
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:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core">
<h:body>
<ui:composition template="/META-INF/templates/templateLogin.xhtml">
<ui:define name="title">
<h:outputText value="Register"/>
</ui:define>
<ui:define name="content">
<h:form id="regiForm">
<p:panelGrid >
<p:row style="height:20%">
<p:column> <h:outputLabel styleClass="col" for="mail" value="#{msg['regi_mail']}" /> </p:column>
<p:column>
<p:inputText style="width:350px" validatorMessage="#{msg['regi_mail_valid']}" id="email" value="#{regiBean.email}" required="true" >
<f:validateRegex pattern="^[_A-Za-z0-9-\+]+(\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9]+)*(\.[A-Za-z]{2,})$"/>
<f:ajax event="keyup" render="emailmessage username pic " execute="@this" />
</p:inputText>
</p:column>
<p:column><p:message for="email" id="emailmessage" /></p:column>
</p:row>
<p:row style="height:20%">
<p:column><h:outputLabel value="#{msg['regi_username']} " /></p:column>
<p:column><h:outputLabel for="email" style="#{facesContext.validationFailed ? 'display:inline;' : 'display:none;'};" id="username" value="#{regiBean.email}" /> </p:column>
<p:column><p:graphicImage for="email" libary="images" name="ok.png" id="pic" style="#{not facesContext.validationFailed ? 'display:inline; color:green;' : 'display:none;'}" /> </p:column>
</p:row>
<p:row style="height:20%">
<p:column><h:outputLabel for="password" value="#{msg['regi_password']}" /></p:column>
<p:column>
<p:password style="width:350px" id="password"
value="#{regiBean.password}" match="repeatpassword"
feedback="true" required="true" requiredMessage="#{msg['regi_password_error']}" validatorMessage="#{msg['regi_password_match']}" />
</p:column>
<p:column><p:message for="password"/></p:column>
</p:row>
<p:row style="height:20%">
<p:column><h:outputLabel for="repeatpassword" value="#{msg['regi_reppassword']}" /></p:column>
<p:column>
<p:password style="width:350px" id="repeatpassword"
value="#{regiBean.repeatpassword}" required="true" requiredMessage="#{msg['regi_password_error']}" validatorMessage="#{msg['regi_password_match']}" />
</p:column>
<p:column><p:message for="repeatpassword"/></p:column>
</p:row>
<p:row style="height:20%">
<p:column><h:outputLabel for="firstname" value="#{msg['regi_firstname']}" /></p:column>
<p:column>
<p:inputText style="width:350px" id="firstname"
value="#{regiBean.firstname}" required="true" requiredMessage="#{msg['regi_firstname_error']}" />
</p:column>
<p:column><p:message for="firstname"/></p:column>
</p:row>
<p:row style="height:20%">
<p:column><h:outputLabel for="lastname" value="#{msg['regi_lastname']}" /></p:column>
<p:column>
<p:inputText style="width:350px" id="lastname"
value="#{regiBean.lastname}" required="true" requiredMessage="#{msg['regi_lastname_error']}" />
</p:column>
<p:column><p:message for="lastname"/></p:column>
</p:row>
<p:row style="height:20%">
<p:column> <h:outputLabel for="gtc" value="#{msg['regi_gtc']}" /></p:column>
<p:column>
<p:selectBooleanCheckbox id="gtc" value="#{regiBean.gtc}" required="true" requiredMessage="#{msg['regi_gtc_error']}" >
<f:validator validatorId="RequiredCheckboxValidator" />
</p:selectBooleanCheckbox >
</p:column>
<p:column><p:message for="gtc"/></p:column>
</p:row>
<p:row style="height:20%">
<p:column><h:outputText value="#{msg['regi_language']}"></h:outputText> </p:column>
<p:column>
<h:selectOneMenu value="#{regiBean.locale}" onchange="submit()"
valueChangeListener="#{regiBean.localeChanged}" immediate="true">
<f:selectItems value="#{regiBean.countries}" />
</h:selectOneMenu>
</p:column>
<p:column></p:column>
</p:row>
<p:row style="height:20%">
<p:column><h:outputText/> </p:column>
<p:column>
<p:commandButton style="width:350px" type="submit" actionListener="#{regiBean.showDialog}" id="ajax"
value="#{msg['regi_button']}" update="regiForm" process="@this"/>
</p:column>
<p:column></p:column>
</p:row>
</p:panelGrid>
<p:dialog id="dialog" header="#{msg['regi_dialog_header']}" widgetVar="myDialog" position="center center" >
<h:outputText value="#{msg['regi_dialog']}" />
</p:dialog>
</h:form>
</ui:define>
</ui:composition>
</h:body>
</html>