Subversion Repositories WebE

Compare Revisions

Last modification

Regard whitespace Rev 21 → Rev 22

/trunk/src/struts.xml
3,7 → 3,7
"http://struts.apache.org/dtds/struts-2.0.dtd">
 
<struts>
<constant name="struts.devMode" value="false" /> <!-- set to true for more debugging output -->
<constant name="struts.devMode" value="true" /> <!-- activates debugging output -->
<!-- User environment -->
<package name="user" namespace="/user" extends="struts-default">
10,6 → 10,8
</package>
<!-- Admin environment -->
<package name="admin" namespace="/admin" extends="hibernate-default">
<action name="userAddForm">
16,15 → 18,22
<result>/admin/userAddForm.jsp</result>
</action>
<action name="doUserAdd" method="addForm" class="ch.ffhs.webE.action.UserAction">
<result name="success" type="redirect">/admin/userAdd.jsp</result>
<action name="doUserAdd" method="add" class="ch.ffhs.webE.action.UserAction">
<result name="success">/admin/userAdd.jsp</result>
</action>
<action name="userList">
<result>/admin/userList.jsp</result>
<action name="userList" method="list" class="ch.ffhs.webE.action.UserAction">
<result name="success">/admin/userList.jsp</result>
</action>
<action name="deleteUser" method="delete" class="ch.ffhs.webE.action.UserAction">
<result name="success" type="redirect">/admin/userList</result>
</action>
</package>
<!-- Remaining environment of the session-->
<package name="default" namespace="" extends="hibernate-default">
/trunk/src/ch/ffhs/webE/dao/UserDAO.java
9,4 → 9,5
List<User> listUser();
void saveUser(User user);
User searchUsername(String username);
void deleteUser(int userId);
}
/trunk/src/ch/ffhs/webE/dao/UserDAOImpl.java
19,13 → 19,13
@SuppressWarnings("unchecked")
@Override
public List<User> listUser() {
List<User> courses = null;
List<User> user = null;
try {
courses = session.createQuery("from User").list();
user = session.createQuery("from User").list();
} catch (Exception e) {
e.printStackTrace();
}
return courses;
return user;
}
 
@Override
39,19 → 39,34
}
/**
* Used to delete a user.
*/
@Override
public void deleteUser(int userId) {
try {
User user = (User) session.get(User.class, userId);
session.delete(user);
} catch (Exception e) {
transaction.rollback();
e.printStackTrace();
}
}
 
/**
* Returns a single user with this user name (used for login)
* @param username: String - entire user name
* @return User: Returns a user object if something is found. If not, null is returned
*
* @param username
* : String - entire user name
* @return User: Returns a user object if something is found. If not, null
* is returned
*/
public User searchUsername(String username) {
User user = null;
try {
user = (User) session.createQuery(
"FROM User " +
"WHERE username = :username")
.setParameter("username", username)
.uniqueResult();
user = (User) session
.createQuery("FROM User " + "WHERE username = :username")
.setParameter("username", username).uniqueResult();
} catch (Exception e) {
//TODO: Log error
}
/trunk/src/ch/ffhs/webE/action/UserAction.java
3,6 → 3,11
import java.util.ArrayList;
import java.util.List;
 
import javax.servlet.http.HttpServletRequest;
 
import org.apache.struts2.ServletActionContext;
 
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import ch.ffhs.webE.dao.UserDAO;
23,18 → 28,12
return user;
}
public String add()
{
public String add() {
userDAO.saveUser(user);
return SUCCESS;
}
public String addForm() {
return SUCCESS;
}
public String list()
{
public String list() {
userList = userDAO.listUser();
return SUCCESS;
}
55,4 → 54,11
this.userList = userList;
}
 
public String delete() {
HttpServletRequest request = (HttpServletRequest) ActionContext
.getContext().get(ServletActionContext.HTTP_REQUEST);
userDAO.deleteUser(Integer.parseInt(request.getParameter("id")));
return SUCCESS;
}
 
}
/trunk/WebContent/admin/userAdd.jsp
0,0 → 1,11
<html>
<head>
<title>User bearbeiten</title>
</head>
<body>
 
<h1>User hinzugef&uuml;gt</h1>
<p>Der Benutzer wurde hinzugef&uuml;gt</p>
<p>TODO: Weiterleitung!!</p>
</body>
</html>
Property changes:
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Index: WebContent/admin/userList.jsp
===================================================================
--- WebContent/admin/userList.jsp (revision 21)
+++ WebContent/admin/userList.jsp (revision 22)
@@ -1,3 +1,4 @@
+<%@taglib uri="/struts-tags" prefix="s"%>
<html>
<head>
<title>User bearbeiten</title>
@@ -5,6 +6,36 @@
<body>
<h1>UserListe</h1>
-<p>Noch nicht umgesetzt</p>
+<p>Die Liste:</p>
+
+<s:if test="userList.size() == 0">
+<p>Keine Benutzer gefunden</p>
+</s:if>
+<s:else>
+<table>
+ <tr>
+ <th>Username</th>
+ <th>Vorname</th>
+ <th>Nachname</th>
+ <th>Admin?</th>
+ </tr>
+<s:iterator value="userList" status="stat">
+ <tr>
+ <td><s:property value="username" /></td>
+ <td><s:property value="firstname" /></td>
+ <td><s:property value="lastname" /></td>
+ <td><s:property value="admin" /></td>
+
+ <td><s:url id="editURL" action="editUser">
+ <s:param name="id" value="%{id}"></s:param>
+ </s:url> <s:a href="%{editURL}">Edit</s:a></td>
+ <td><s:url id="deleteURL" action="deleteUser">
+ <s:param name="id" value="%{id}"></s:param>
+ </s:url> <s:a href="%{deleteURL}">Delete</s:a></td>
+ </tr>
+</s:iterator>
+</table>
+</s:else>
+
</body>
</html>
\ No newline at end of file
/trunk/WebContent/admin/userAddForm.jsp
5,8 → 5,8
</head>
<body>
 
<h1>User Hinzuf&uuml;gen</h1>
<p>Noch nicht umgesetzt...</p>
<h1>User hinzuf&uuml;gen</h1>
<p>Bitte geben Sie die Benutzerdaten ein</p>
<s:form action="doUserAdd">
<s:textfield name="username" label="User Name" />
<s:password name="password" label="Password" />
/trunk/.
Property changes:
Modified: svn:ignore
## -1 +1,5 ##
svn history.txt
+
+hibernate.reveng.xml
+
+hibernate.properties