Domain Modul begonnen

This commit is contained in:
Peter Hormanns 2010-09-27 19:00:32 +00:00
parent 977d020f77
commit 5c28eb509d
8 changed files with 218 additions and 8 deletions

View File

@ -4,6 +4,7 @@ import java.text.DateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.ResourceBundle;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;

View File

@ -0,0 +1,106 @@
package de.hsadmin.web;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
@ManagedBean(name="domain")
@SessionScoped
public class Domain {
@ManagedProperty(value="#{context}")
private Context context;
@ManagedProperty(value="#{remote}")
private Remote remote;
@ManagedProperty(value="#{texts}")
private Texts texts;
private List<Map<String, String>> list = null;
private String error = null;
public Map<String, String> labels = null;
public Map<String, String> urls = null;
public String getError() {
return error;
}
public void setContext(Context context) {
this.context = context;
}
public void setRemote(Remote remote) {
this.remote = remote;
}
public void setTexts(Texts texts) {
this.texts = texts;
}
public List<Map<String, String>> getList() {
if (list == null) {
list = new ArrayList<Map<String,String>>();
try {
Map<String, String> whereParams = new HashMap<String, String>();
Object testList = remote.callSearch("domain", context.getUser(), whereParams);
if (testList != null && testList instanceof Object[]) {
Object[] lst = (Object[])testList;
for (int i = 0; i<lst.length; i++) {
Object testRow = lst[i];
if (testRow instanceof Map<?, ?>) {
Map<?, ?> row = (Map<?, ?>) testRow;
Map<String, String> dom = new HashMap<String, String>();
for (String key : new String[] { "id", "name", "user", "hive", "pac", "since" }) {
dom.put(key, (String) row.get(key));
}
list.add(dom);
}
}
}
} catch (HsarwebException e) {
error = e.getMessage();
}
}
return list;
}
public Map<String, String> getLabels() {
if (labels == null) {
labels = new HashMap<String, String>();
for (String key : new String[]{ "name", "user" }) {
labels.put(key, texts.getLabel("domain." + key + ".label"));
}
}
return labels;
}
public Map<String, String> getUrls() {
if (urls == null) {
String path = context.getContextPath() + "/";
urls = new HashMap<String, String>();
for (String key : new String[]{ "edit", "delete" }) {
urls.put(key, path + "domain/" + key + ".html");
}
}
return urls;
}
public String delete() {
System.out.println("domain.delete" + FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("dom_id"));
return null;
}
public String edit() {
System.out.println("domain.edit" + FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("dom_id"));
return null;
}
}

View File

@ -1,7 +1,9 @@
package de.hsadmin.web;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
@ -14,20 +16,48 @@ public class Modules {
@ManagedProperty(value="#{context}")
private Context context;
public String[] pageNames = new String[] { "hello" };
@ManagedProperty(value="#{texts}")
private Texts texts;
public String[] pageNames = new String[] { "hello", "domain" };
public Map<String, String> labels = null;
public Map<String, String> urls = null;
public List<String> getPageNames() {
ArrayList<String> names = new ArrayList<String>();
String path = context.getContextPath() + "/";
names.add(path + context.getUser());
for (String name : pageNames) {
names.add(path + name);
names.add(name);
}
return names;
}
public Map<String, String> getLabels() {
if (labels == null) {
labels = new HashMap<String, String>();
for (String key : pageNames) {
labels.put(key, texts.getLabel(key + ".label"));
}
}
return labels;
}
public Map<String, String> getUrls() {
if (urls == null) {
String path = context.getContextPath() + "/";
urls = new HashMap<String, String>();
for (String key : pageNames) {
urls.put(key, path + key + "/index.html");
}
}
return urls;
}
public void setContext(Context context) {
this.context = context;
}
public void setTexts(Texts texts) {
this.texts = texts;
}
}

View File

@ -0,0 +1,17 @@
package de.hsadmin.web;
import java.util.ResourceBundle;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
@ManagedBean(name="texts")
@SessionScoped
public class Texts {
public String getLabel(String key) {
ResourceBundle resource = ResourceBundle.getBundle("texts.messages");
return resource.getString(key);
}
}

View File

@ -1 +1,6 @@
hello=Hallo
edit=bearbeiten
delete=loeschen
hello.label=Hallo
domain.label=Domains
domain.name.label=Domain
domain.user.label=Verwalter

View File

@ -1 +1,6 @@
hello=Hello
edit=edit
delete=delete
hello.label=Hello
domain.label=Domains
domain.name.label=Domain
domain.user.label=Owner

View File

@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets">
<head>
<title>Hello World</title>
</head>
<body>
<ui:composition template="/templates/menu-template.xhtml">
<ui:param name="title" value="Hostsharing - Ihre Domains"/>
<ui:define name="content">
<f:view>
<h:dataTable var="dom" value="#{domain.list}">
<h:column>
<f:facet name="header">
<h:outputText value="#{domain.labels['name']}" />
</f:facet>
<h:outputText value="#{dom['name']}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="#{domain.labels['user']}" />
</f:facet>
<h:outputText value="#{dom['user']}" />
</h:column>
<h:column>
<h:outputLink value="#{domain.urls['edit']}">
<h:outputText value="#{msgs.edit}" />
<f:param name="id" value="#{dom['id']}" />
</h:outputLink>
</h:column>
<h:column>
<h:outputLink value="#{domain.urls['delete']}">
<h:outputText value="#{msgs.delete}" />
<f:param name="id" value="#{dom['id']}" />
</h:outputLink>
</h:column>
</h:dataTable>
</f:view>
</ui:define>
</ui:composition>
</body>
</html>

View File

@ -14,8 +14,8 @@
<f:view>
<h:dataTable var="menuitem" value="#{modules.pageNames}">
<h:column>
<h:outputLink value="#{menuitem}/index.html">
<h:outputText value="#{msgs.hello}" />
<h:outputLink value="#{modules.urls[menuitem]}">
<h:outputText value="#{modules.labels[menuitem]}" />
</h:outputLink>
</h:column>
</h:dataTable>