Search in sources :

Example 1 with Member

use of org.jboss.as.quickstarts.kitchensinkjsp.model.Member in project quickstart by wildfly.

the class MemberListProducer method retrieveAllMembersOrderedByName.

@PostConstruct
public void retrieveAllMembersOrderedByName() {
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<Member> criteria = cb.createQuery(Member.class);
    Root<Member> member = criteria.from(Member.class);
    // Swap criteria statements if you would like to try out type-safe criteria queries, a new
    // feature in JPA 2.0
    // criteria.select(member).orderBy(cb.asc(member.get(Member_.name)));
    criteria.select(member).orderBy(cb.asc(member.get("name")));
    members = em.createQuery(criteria).getResultList();
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Member(org.jboss.as.quickstarts.kitchensinkjsp.model.Member) PostConstruct(javax.annotation.PostConstruct)

Example 2 with Member

use of org.jboss.as.quickstarts.kitchensinkjsp.model.Member in project quickstart by wildfly.

the class MemberRegistrationServlet method doPost.

/**
 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
 */
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    StringBuilder errorMessage = new StringBuilder();
    try {
        System.out.println("EMAIL='" + request.getParameter("email") + "'");
        Member member;
        while ((member = registrationService.getNewMember()) == null) {
            registrationService.initNewMember();
        }
        String value;
        if ((value = request.getParameter("name")).length() < 1) {
            errorMessage.append("Name can not be null\n");
        } else {
            member.setName(value);
            if ((value = request.getParameter("email")).length() < 1) {
                errorMessage.append("email required!\n");
            } else {
                member.setEmail(value);
                if ((value = request.getParameter("phoneNumber")).length() < 1) {
                    errorMessage.append("phoneNumber required \n");
                } else // all parameters are filled, register
                {
                    member.setPhoneNumber(value);
                    log("\n*****************Try Registration of Member=" + member);
                    registrationService.register();
                    request.setAttribute("infoMessage", member.getName() + " Registered!");
                }
            }
        }
    } catch (Exception e) {
        Throwable t = e;
        while ((t.getCause()) != null) {
            t = t.getCause();
        }
        errorMessage.append("Error========>" + t.getMessage());
        request.setAttribute("infoMessage", "");
        e.printStackTrace();
    } finally {
        request.setAttribute("errorMessage", errorMessage.toString());
        RequestDispatcher resultView = request.getRequestDispatcher("index.jsp");
        resultView.forward(request, response);
    }
}
Also used : Member(org.jboss.as.quickstarts.kitchensinkjsp.model.Member) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) RequestDispatcher(javax.servlet.RequestDispatcher)

Example 3 with Member

use of org.jboss.as.quickstarts.kitchensinkjsp.model.Member in project quickstart by wildfly.

the class MemberRegistrationIT method testRegister.

@Test
public void testRegister() throws Exception {
    Member newMember = memberRegistration.getNewMember();
    newMember.setName("Jane Doe");
    newMember.setEmail("jane@mailinator.com");
    newMember.setPhoneNumber("2125551234");
    memberRegistration.register();
    assertNotNull(newMember.getId());
    log.info(newMember.getName() + " was persisted with id " + newMember.getId());
}
Also used : Member(org.jboss.as.quickstarts.kitchensinkjsp.model.Member) Test(org.junit.Test)

Example 4 with Member

use of org.jboss.as.quickstarts.kitchensinkjsp.model.Member in project quickstart by wildfly.

the class MemberRegistration method initNewMember.

@PostConstruct
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public void initNewMember() {
    newMember = new Member();
    log.info("@PostConstruct:initNewMember called");
}
Also used : Member(org.jboss.as.quickstarts.kitchensinkjsp.model.Member) TransactionAttribute(javax.ejb.TransactionAttribute) PostConstruct(javax.annotation.PostConstruct)

Aggregations

Member (org.jboss.as.quickstarts.kitchensinkjsp.model.Member)4 PostConstruct (javax.annotation.PostConstruct)2 IOException (java.io.IOException)1 TransactionAttribute (javax.ejb.TransactionAttribute)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 RequestDispatcher (javax.servlet.RequestDispatcher)1 ServletException (javax.servlet.ServletException)1 Test (org.junit.Test)1