2

Helo!

I wrote some Java code with JSF, and the invoked method doesn't run when clicking Register Button. The Controller:

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

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

I tried about 6 variations but non of them works. I would invoke the method here:

<h:commandButton value="Register" action="#{ucb.doRegister}">
BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
Akos
  • 21
  • 2

0 Answers0