Skip to content

Commit

Permalink
Golfer profile functional
Browse files Browse the repository at this point in the history
General clean up
  • Loading branch information
LightGuard committed Apr 20, 2012
1 parent 048ee9f commit ffbeb39
Show file tree
Hide file tree
Showing 13 changed files with 212 additions and 136 deletions.
137 changes: 137 additions & 0 deletions open18_java_ee_6/src/main/java/org/open18/action/GolferAction.java
@@ -0,0 +1,137 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2012, Red Hat, Inc., and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.open18.action;

import java.io.Serializable;

import javax.ejb.Stateful;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.enterprise.context.Conversation;
import javax.enterprise.context.ConversationScoped;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;

import org.open18.model.Golfer;
import org.open18.model.dao.GolferDao;

/**
*
*/
@ConversationScoped
@Named
@Stateful
public class GolferAction implements Serializable {

private static final long serialVersionUID = 2281839629956903065L;

@Inject
private GolferDao dao;

@Inject
private transient Conversation conversation;

private Long golferId;

private Golfer golfer;

private boolean managed;

@Inject
private void init() {
golfer = new Golfer();
}

public void loadCourse() {
if (this.golferId != null && !FacesContext.getCurrentInstance().isPostback()) {
this.golfer = this.dao.findBy(this.golferId);
this.managed = true;
}
}

public void beginConversation() {
if (conversation.isTransient()) {
conversation.begin();
}
}

public void endConversation() {
if (!conversation.isTransient()) {
conversation.end();
}
}

@TransactionAttribute(TransactionAttributeType.REQUIRED)
public String save() {
dao.saveAndFlush(golfer);
endConversation();
return "/admin/GolferList.xhtml";
}

@TransactionAttribute(TransactionAttributeType.REQUIRED)
public String update() {
dao.saveAndFlush(golfer);
return "/admin/GolferList.xhtml?golferId=" + golfer.getId();
}

@TransactionAttribute(TransactionAttributeType.REQUIRED)
public String remove() {
dao.remove(golfer);
endConversation();
return "/admin/GolferList.xhtml";
}

public Long getGolferId() {
return golferId;
}

public void setGolferId(Long newRoundId) {
if (newRoundId != null && !newRoundId.equals(golfer.getId())) {
golferId = newRoundId;
golfer = dao.findBy(newRoundId);
managed = true;

if (golfer == null) {
managed = false;
golfer = new Golfer();
final FacesContext fc = FacesContext.getCurrentInstance();
fc.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "No Round found with id " + newRoundId, ""));
}

this.beginConversation();
}
}

public Golfer getGolfer() {
return golfer;
}

public void setGolfer(Golfer newGolfer) {
golfer = newGolfer;
}

public boolean isManaged() {
return managed;
}

public void setManaged(boolean newManaged) {
managed = newManaged;
}
}
11 changes: 0 additions & 11 deletions open18_java_ee_6/src/main/java/org/open18/action/GolferList.java

This file was deleted.

Expand Up @@ -24,12 +24,12 @@ public class HoleHome {
// getInstance();
// Course course = courseHome.getDefinedInstance();
// if (course != null) {
// getInstance().setRound(course);
// getInstance().setGolfer(course);
// }
// }
//
// public boolean isWired() {
// if (getInstance().getRound() == null)
// if (getInstance().getGolfer() == null)
// return false;
// return true;
// }
Expand Down

This file was deleted.

Expand Up @@ -37,11 +37,6 @@ public class ProfileAction implements Serializable {
// private void init() {
// this.golferDao.setEntityManager(entityManager);
// }

public String view() {
assert selectedGolfer != null && selectedGolfer.getId() != null;
return "/profile.xhtml";
}
//
// public void load() {
// if (selectedGolfer != null && selectedGolfer.getId() != null) {
Expand Down
Expand Up @@ -12,7 +12,7 @@ public class RoundHome {
// // As an alternative to a page parameter, the courseId request
// // parameter can be injected using the @RequestParameter annotation.
// //@RequestParameter
// //public void setRoundId(Long id) {
// //public void setGolferId(Long id) {
// // setId(id);
// //}
//
Expand Down
Expand Up @@ -24,12 +24,12 @@ public class TeeSetHome {
// getInstance();
// Course course = courseHome.getDefinedInstance();
// if (course != null) {
// getInstance().setRound(course);
// getInstance().setGolfer(course);
// }
// }
//
// public boolean isWired() {
// if (getInstance().getRound() == null)
// if (getInstance().getGolfer() == null)
// return false;
// return true;
// }
Expand Down
13 changes: 13 additions & 0 deletions open18_java_ee_6/src/main/java/org/open18/model/dao/GolferDao.java
Expand Up @@ -19,6 +19,9 @@

import java.util.List;

import javax.enterprise.context.RequestScoped;
import javax.enterprise.inject.Produces;
import javax.inject.Named;
import javax.persistence.TypedQuery;

import org.open18.model.Golfer;
Expand All @@ -28,6 +31,8 @@
*/
public class GolferDao extends BaseDao<Golfer, Long> {

private static final long serialVersionUID = -4873600374648186511L;

public GolferDao() {
this.entityType = Golfer.class;
this.idType = Long.class;
Expand All @@ -39,4 +44,12 @@ public List<Golfer> findNewGolfers() {

return query.getResultList();
}

@Override
@Produces
@RequestScoped
@Named("allGolfers")
public List<Golfer> findAll() {
return super.findAll();
}
}
2 changes: 1 addition & 1 deletion open18_java_ee_6/src/main/webapp/CourseEdit.xhtml
Expand Up @@ -10,7 +10,7 @@
<ui:define name="metadata">
<f:metadata>
<f:viewParam name="courseId" value="#{courseAction.courseId}"/>
<f:event type="preRenderView" listener="#{courseAction.loadCourse}"/> <!-- TODO move the logic in setRoundId to this method -->
<f:event type="preRenderView" listener="#{courseAction.loadCourse}"/> <!-- TODO move the logic in setGolferId to this method -->
</f:metadata>
</ui:define>

Expand Down
13 changes: 6 additions & 7 deletions open18_java_ee_6/src/main/webapp/GolferList.xhtml
@@ -1,7 +1,6 @@
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:s="http://jboss.com/products/seam/taglib"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
Expand All @@ -17,15 +16,15 @@

<div class="results">

<h:outputText value="There are no golfers registered." rendered="#{empty golferList.resultList}"/>
<h:outputText value="There are no golfers registered." rendered="#{empty allGolfers}"/>

<rich:dataTable id="golferList" var="_golfer" value="#{golferList.resultList}"
rendered="#{not empty golferList.resultList}">
<rich:dataTable id="golferList" var="_golfer" value="#{allGolfers}"
rendered="#{not empty allGolfers}">
<h:column>
<f:facet name="header">Username</f:facet>
<s:link id="view" value="#{_golfer.username}" view="/profile.xhtml" propagation="none">
<h:link id="view" value="#{_golfer.username}" outcome="/profile.xhtml">
<f:param name="golferId" value="#{_golfer.id}"/>
</s:link>
</h:link>
</h:column>
<h:column>
<f:facet name="header">Name</f:facet>
Expand All @@ -34,7 +33,7 @@
<h:column>
<f:facet name="header">Date Joined</f:facet>
<h:outputText value="#{_golfer.dateJoined}">
<s:convertDateTime pattern="MMMM dd, yyyy" />
<f:convertDateTime pattern="dd MMM yyyy" timeZone="Etc/UTC"/>
</h:outputText>
</h:column>
</rich:dataTable>
Expand Down
9 changes: 0 additions & 9 deletions open18_java_ee_6/src/main/webapp/home.page.xml

This file was deleted.

7 changes: 5 additions & 2 deletions open18_java_ee_6/src/main/webapp/home.xhtml
Expand Up @@ -12,11 +12,12 @@
<div id="banner">
<h1>#{messages['application.title']}</h1>
<h2>...#{messages['application.tagline']}</h2>
<!-- TODO: fix with Apache Shiro
<ui:remove><!-- TODO: fix with Apache Shiro
<ui:fragment rendered="#{not identity.loggedIn}">
<p>Not a member?#{' '}<h:link id="register" value="Sign up now!" outcome="/register.xhtml" /></p>
</ui:fragment>
-->
</ui:remove>
</div>

<h:messages globalOnly="true" styleClass="message" errorClass="errormsg" infoClass="infomsg" warnClass="warnmsg"/>
Expand All @@ -42,7 +43,9 @@

<h:form id="selectGolfer">
<rich:list var="_golfer" value="#{newGolfers}">
<h:commandLink action="#{profileAction.view}" value="#{_golfer.name} (#{_golfer.username})"/>
<h:link outcome="/profile.xhtml" value="#{_golfer.name} (#{_golfer.username})">
<f:param name="golferId" value="#{_golfer.id}" />
</h:link>
</rich:list>
</h:form>
</rich:panel>
Expand Down

0 comments on commit ffbeb39

Please sign in to comment.