Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
13 changed files
with
212 additions
and
136 deletions.
There are no files selected for viewing
137 changes: 137 additions & 0 deletions
137
open18_java_ee_6/src/main/java/org/open18/action/GolferAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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
11
open18_java_ee_6/src/main/java/org/open18/action/GolferList.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 0 additions & 57 deletions
57
open18_java_ee_6/src/main/java/org/open18/action/NewGolfersList.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.