Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
richard authored and richard committed Jun 15, 2010
1 parent 02ece08 commit f3e674a
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 10 deletions.
4 changes: 3 additions & 1 deletion WebContent/pages/Administer.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
<h1>Word List Administration</h1>

<table border="1" width="30%">
<th>Action</th>
<th>Value</th>
<th>Points</th>
<c:forEach var="t" items="${it.words}" varStatus="loop">
<tr>
<td align="left"><a href="/jersey/hibernate/delete/${t.id}/">Remove</a></td>
<td><b>${t.value}</b></td>
<td>${t.points}</td>
</tr>
Expand All @@ -28,7 +30,7 @@
<hr></hr>
<p>Enter a new word and the points associated with it. Then click Save</p>

<form action="../hibernate/save" method="POST">
<form action="/jersey/hibernate/save" method="POST">
<label for="value">Value</label>
<input name="value" />
<label for="points">Points</label>
Expand Down
2 changes: 2 additions & 0 deletions src/example/dao/DictionaryDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public interface DictionaryDao {
List getWords();
/** @return word for the given identifier */
Word getWord(Integer id);
/** @return word for the given identifier */
void deleteWord(Integer id);
/** @return a random word */
Word getRandomWord();
}
3 changes: 3 additions & 0 deletions src/example/dao/DictionaryDaoImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public List getWords() {
public Word getWord(Integer id) {
return (Word) getHibernateTemplate().get(Word.class, id);
}
public void deleteWord(Integer id) {
getHibernateTemplate().delete(getWord(id));
}
public Word getRandomWord() {
return (Word) getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session session) throws HibernateException, SQLException {
Expand Down
35 changes: 26 additions & 9 deletions src/example/resources/Administer.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
Expand All @@ -24,6 +26,7 @@
import org.springframework.stereotype.Component;

import com.sun.jersey.api.view.Viewable;
import com.sun.jersey.samples.bookstore.resources.Item;
import com.sun.jersey.spi.inject.Inject;

import sample.hello.bean.Address;
Expand Down Expand Up @@ -52,6 +55,21 @@ public class Administer {
@Inject private DictionaryDao dictionaryDao;
@Inject private DictionaryService dictionaryService;

@POST
@Path("save")
@Produces(MediaType.TEXT_HTML)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Viewable newWord(
@FormParam("value") String value,
@FormParam("points") String points,
@Context HttpServletResponse servletResponse
) throws IOException {
Word w = new Word(value, new Integer(points));
dictionaryService.updateWord(w);
//servletResponse.sendRedirect("../pages/new_contact.html");
return getWordList();
}

@GET
@Path("list")
public Viewable getWordList() {
Expand All @@ -63,18 +81,17 @@ public Viewable getWordList() {
return new Viewable("/pages/Administer.jsp", wlist);
}

@POST
@Path("save")
@Produces(MediaType.TEXT_HTML)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Viewable newWord(
@FormParam("value") String value,
@FormParam("points") String points,
@GET
@Path("delete/{wordKey}/")
public Viewable delete(
@PathParam("wordKey") String wordKey,
@Context HttpServletResponse servletResponse
) throws IOException {
Word w = new Word(value, new Integer(points));
dictionaryService.updateWord(w);
dictionaryService.deleteWord(new Integer(wordKey));
//servletResponse.sendRedirect("../pages/new_contact.html");
return getWordList();
}



}
2 changes: 2 additions & 0 deletions src/example/service/DictionaryService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@

public interface DictionaryService {
void updateWord(Word word);
void deleteWord(Integer wordKey);
Word getWord(Integer wordKey);
}
6 changes: 6 additions & 0 deletions src/example/service/DictionaryServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,10 @@ public void updateWord(Word word) {
public void setDictionaryDao(DictionaryDaoImpl dictionaryDao) {
this.dictionaryDao = dictionaryDao;
}
public void deleteWord(Integer wordKey) {
dictionaryDao.deleteWord(wordKey);
}
public Word getWord(Integer wordKey) {
return dictionaryDao.getWord(wordKey);
}
}

0 comments on commit f3e674a

Please sign in to comment.