Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Linnea Samila
/
Moya
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 3d9986b2
authored
Feb 11, 2012
by
Tuomas Riihimäki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed product management
1 parent
d029fc8e
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
201 additions
and
106 deletions
code/LanBortalBeansClient/ejbModule/fi/insomnia/bortal/beans/RoleBeanLocal.java
code/LanBortalDatabase/src/fi/insomnia/bortal/model/Role.java
code/LanBortalWeb/WebContent/product/createDiscount.xhtml
code/LanBortalWeb/WebContent/product/edit.xhtml
code/LanBortalWeb/WebContent/product/editDiscount.xhtml
code/LanBortalWeb/WebContent/resources/cditools/products/edit.xhtml
code/LanBortalWeb/src/fi/insomnia/bortal/resources/i18n.properties
code/LanBortalWeb/src/fi/insomnia/bortal/web/cdiview/shop/ProductView.java
code/LanBortalWeb/src/fi/insomnia/bortal/web/cdiview/user/RoleDataView.java
code/LanBortalWeb/src/fi/insomnia/bortal/web/converter/RoleConverter.java
code/LanBortalBeansClient/ejbModule/fi/insomnia/bortal/beans/RoleBeanLocal.java
View file @
3d9986b
...
...
@@ -31,4 +31,6 @@ public interface RoleBeanLocal {
public
Role
setPermissions
(
Role
role
,
List
<
IAppPermission
>
newPerms
);
public
Object
getEmptyRole
();
}
code/LanBortalDatabase/src/fi/insomnia/bortal/model/Role.java
View file @
3d9986b
...
...
@@ -32,6 +32,8 @@ public class Role extends GenericEntity {
protected
static
final
String
EVENT_ID_COLUMN
=
"event_id"
;
public
static
final
Role
EMPTY_ROLE
=
new
Role
(
"----"
);
@Column
(
name
=
NAME_COLUMN
,
nullable
=
false
)
private
String
name
;
...
...
@@ -83,6 +85,11 @@ public class Role extends GenericEntity {
this
.
name
=
roleName
;
}
private
Role
(
String
rolename
)
{
setId
(
0
);
name
=
rolename
;
}
public
String
getName
()
{
return
name
;
}
...
...
code/LanBortalWeb/WebContent/product/createDiscount.xhtml
View file @
3d9986b
...
...
@@ -11,8 +11,11 @@
<h:body>
<ui:composition
template=
"/layout/#{sessionHandler.layout}/template.xhtml"
>
<ui:param
name=
"thispage"
value=
"page.product.edit"
/>
<ui:define
name=
"content"
>
<h:link
id=
"back"
outcome=
"/product/edit"
value=
"#{i18n['product.returnProductEdit']} #{productView.product.name}"
>
<f:param
name=
"productid"
value=
"#{productView.product.id}"
/>
</h:link>
<products:manageDiscount
commitaction=
"#{productView.createDiscount()}"
commitvalue=
"#{i18n['discount.create']}"
/>
...
...
code/LanBortalWeb/WebContent/product/edit.xhtml
View file @
3d9986b
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html
xmlns=
"http://www.w3.org/1999/xhtml"
xmlns:ui=
"http://java.sun.com/jsf/facelets"
<html
xmlns=
"http://www.w3.org/1999/xhtml"
xmlns:ui=
"http://java.sun.com/jsf/facelets"
xmlns:h=
"http://java.sun.com/jsf/html"
xmlns:f=
"http://java.sun.com/jsf/core"
xmlns:c=
"http://java.sun.com/jsp/jstl/core"
xmlns:products=
"http://java.sun.com/jsf/composite/cditools/products"
>
xmlns:c=
"http://java.sun.com/jsp/jstl/core"
xmlns:products=
"http://java.sun.com/jsf/composite/cditools/products"
>
<h:head>
<title></title>
...
...
@@ -18,9 +17,72 @@
</f:metadata>
<ui:param
name=
"thispage"
value=
"page.product.edit"
/>
<ui:define
name=
"content"
>
<products:edit
commitaction=
"#{productView.saveProduct()}"
commitvalue=
"#{i18n['products.save']}"
/>
<products:edit
commitaction=
"#{productView.saveProduct()}"
commitvalue=
"#{i18n['products.save']}"
/>
<h:form
id=
"discounts"
>
<h:commandButton
rendered=
"#{!empty productView.product.id}"
action=
"#{productView.initCreateDiscount()}"
value=
"#{i18n['product.createDiscount']}"
>
</h:commandButton>
<h:dataTable
border=
"1"
id=
"discount"
value=
"#{productView.productDiscounts}"
var=
"discount"
rendered=
"#{!empty productView.product.id and !empty productView.product.discounts}"
>
<h:column>
<f:facet
name=
"header"
>
<h:outputText
value=
"${i18n['discount.percentage']}"
/>
</f:facet>
<h:outputText
value=
"#{discount.percentage}"
/>
</h:column>
<h:column>
<f:facet
name=
"header"
>
<h:outputText
value=
"${i18n['discount.code']}"
/>
</f:facet>
<h:outputText
value=
"#{discount.code}"
/>
</h:column>
<h:column>
<f:facet
name=
"header"
>
<h:outputText
value=
"${i18n['discount.details']}"
/>
</f:facet>
<h:outputText
value=
"#{discount.details}"
/>
</h:column>
<h:column>
<f:facet
name=
"header"
>
<h:outputText
value=
"${i18n['discount.shortdesc']}"
/>
</f:facet>
<h:outputText
value=
"#{discount.shortdesc}"
/>
</h:column>
<h:column>
<f:facet
name=
"header"
>
<h:outputText
value=
"${i18n['discount.amountMin']}"
/>
</f:facet>
<h:outputText
value=
"#{discount.amountMin}"
/>
</h:column>
<h:column>
<f:facet
name=
"header"
>
<h:outputText
value=
"${i18n['discount.amountMax']}"
/>
</f:facet>
<h:outputText
value=
"#{discount.amountMax}"
/>
</h:column>
<h:column>
<f:facet
name=
"header"
>
<h:outputText
value=
"${i18n['discount.maxNum']}"
/>
</f:facet>
<h:outputText
value=
"#{discount.maxNum}"
/>
</h:column>
<h:column>
<f:facet
name=
"header"
>
<h:outputText
value=
"${i18n['discount.perUser']}"
/>
</f:facet>
<h:outputText
value=
"#{discount.perUser}"
/>
</h:column>
<h:column>
<h:commandButton
action=
"#{productView.editDiscount()}"
value=
"#{i18n['discount.edit']}"
/>
</h:column>
</h:dataTable>
</h:form>
</ui:define>
</ui:composition>
</h:body>
...
...
code/LanBortalWeb/WebContent/product/editDiscount.xhtml
View file @
3d9986b
...
...
@@ -3,7 +3,7 @@
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html
xmlns=
"http://www.w3.org/1999/xhtml"
xmlns:ui=
"http://java.sun.com/jsf/facelets"
xmlns:h=
"http://java.sun.com/jsf/html"
xmlns:f=
"http://java.sun.com/jsf/core"
xmlns:c=
"http://java.sun.com/jsp/jstl/core"
xmlns:
tools=
"http://java.sun.com/jsf/composite/tool
s"
xmlns:c=
"http://java.sun.com/jsp/jstl/core"
xmlns:
products=
"http://java.sun.com/jsf/composite/cditools/product
s"
>
<h:head>
<title></title>
...
...
@@ -11,11 +11,8 @@
<h:body>
<ui:composition
template=
"/layout/#{sessionHandler.layout}/template.xhtml"
>
<ui:param
name=
"thispage"
value=
"page.product.edit"
/>
<ui:define
name=
"content"
>
<products:manageDiscount
commitaction=
"#{productView.save()}"
commitvalue=
"#{i18n['discount.save']}"
/>
</ui:define>
</ui:composition>
</h:body>
...
...
code/LanBortalWeb/WebContent/resources/cditools/products/edit.xhtml
View file @
3d9986b
...
...
@@ -3,7 +3,7 @@
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
xmlns=
"http://www.w3.org/1999/xhtml"
xmlns:h=
"http://java.sun.com/jsf/html"
xmlns:f=
"http://java.sun.com/jsf/core"
xmlns:composite=
"http://java.sun.com/jsf/composite"
xmlns:ui=
"http://java.sun.com/jsf/facelets"
xmlns:c=
"http://java.sun.com/jsp/jstl/core"
xmlns:tools=
"http://java.sun.com/jsf/composite/tools"
xmlns:c=
"http://java.sun.com/jsp/jstl/core"
>
...
...
@@ -15,105 +15,60 @@
<composite:implementation>
<h:form
id=
"productform"
>
<h:inputHidden
value=
"#{productView.product.id}"
/>
<h:panelGrid
columns=
"2"
>
<h:outputLabel
value=
"#{i18n['product.name']}:"
/>
<h:inputText
value=
"#{productView.product.name}"
/>
<h:outputLabel
value=
"#{i18n['product.price']}:"
/>
<h:inputText
value=
"#{productView.product.price}"
/>
<h:outputLabel
value=
"#{i18n['product.unitName']}:"
/>
<h:inputText
value=
"#{productView.product.unitName}"
/>
<h:panelGrid
columns=
"3"
>
<h:outputLabel
for=
"name"
value=
"#{i18n['product.name']}:"
/>
<h:inputText
id=
"name"
value=
"#{productView.product.name}"
/>
<h:message
for=
"name"
/>
<h:outputLabel
for=
"price"
value=
"#{i18n['product.price']}:"
/>
<h:inputText
id=
"price"
value=
"#{productView.product.price}"
/>
<h:message
for=
"price"
/>
<h:outputLabel
for=
"unitName"
value=
"#{i18n['product.unitName']}:"
/>
<h:inputText
id=
"unitName"
value=
"#{productView.product.unitName}"
/>
<h:message
for=
"unitName"
/>
<h:outputLabel
for=
"vat"
value=
"#{i18n['product.vat']}:"
/>
<h:inputText
id=
"vat"
value=
"#{productView.product.vat}"
/>
<h:message
for=
"vat"
/>
<h:outputLabel
for=
"sort"
value=
"#{i18n['product.sort']}:"
/>
<h:inputText
id=
"sort"
value=
"#{productView.product.sort}"
/>
<h:message
for=
"sort"
/>
<h:outputLabel
for=
"barcode"
value=
"#{i18n['product.barcode']}:"
/>
<h:inputText
id=
"barcode"
value=
"#{productView.product.barcode}"
/>
<h:message
for=
"barcode"
/>
<h:outputLabel
for=
"prepaid"
value=
"#{i18n['product.prepaid']}"
/>
<h:selectBooleanCheckbox
id=
"prepaid"
value=
"#{productView.product.prepaid}"
/>
<h:message
for=
"prepaid"
/>
<h:outputLabel
for=
"instant"
value=
"#{i18n['product.prepaidInstant']}"
/>
<h:selectBooleanCheckbox
id=
"instant"
value=
"#{productView.product.prepaidInstant}"
/>
<h:message
for=
"instant"
/>
<h:outputLabel
for=
"provides"
value=
"#{i18n['product.providedRole']}"
/>
<h:selectOneMenu
id=
"provides"
layout=
"pageDirection"
value=
"#{productView.product.provides}"
converter=
"#{roleConverter}"
>
<f:selectItems
var=
"role"
itemLabel=
"#{role.name}"
value=
"#{roleDataView.rolesWithEmpty}"
noSelectionValue=
"#{roleDataView.noSelection}"
/>
</h:selectOneMenu>
<h:message
for=
"provides"
/>
<h:outputLabel
value=
"#{i18n['product.vat']}:"
/>
<h:inputText
value=
"#{productView.product.vat}"
/>
<h:
outputLabel
value=
"#{i18n['product.sort']}:
"
/>
<h:inputText
value=
"#{productView.product.sort}"
/
>
<h:
commandButton
id=
"commitbtn"
action=
"#{cc.attrs.commitaction}"
value=
"#{cc.attrs.commitvalue}
"
/>
</h:panelGrid
>
<h:outputLabel
value=
"#{i18n['product.barcode']}:"
/>
<h:inputText
value=
"#{productView.product.barcode}"
/>
<h:outputLabel
value=
"#{i18n['product.prepaid']}"
/>
<h:selectBooleanCheckbox
value=
"#{productView.product.prepaid}"
/>
<h:outputLabel
value=
"#{i18n['product.prepaidInstant']}"
/>
<h:selectBooleanCheckbox
value=
"#{productView.product.prepaidInstant}"
/>
<h:outputLabel
value=
"#{i18n['product.providedRole']}"
/>
<h:selectOneMenu
layout=
"pageDirection"
value=
"#{productView.product.role}"
converter=
"#{roleConverter}"
id=
"roles"
>
<f:selectItems
var=
"role"
itemLabel=
"#{role.name}"
value=
"#{roleDataView.roles}"
/>
</h:selectOneMenu>
<h:commandButton
id=
"commitbtn"
action=
"#{cc.attrs.commitaction}"
value=
"#{cc.attrs.commitvalue}"
/>
</h:panelGrid>
</h:form>
<h:commandButton
rendered=
"#{!empty productView.product.id}"
action=
"#{productView.createDiscount}"
value=
"#{i18n['product.createDiscount']}"
/>
<h:form
id=
"discounts"
rendered=
"#{!empty productView.product.id and !empty productView.product.discounts}"
>
<h:dataTable
border=
"1"
id=
"discount"
value=
"#{productView.product.discounts}"
var=
"discount"
>
<h:column>
<f:facet
name=
"header"
>
<h:outputText
value=
"${i18n['discount.percentage']}"
/>
</f:facet>
<h:outputText
value=
"#{discount.percentage}"
/>
</h:column>
<h:column>
<f:facet
name=
"header"
>
<h:outputText
value=
"${i18n['discount.code']}"
/>
</f:facet>
<h:outputText
value=
"#{discount.code}"
/>
</h:column>
<h:column>
<f:facet
name=
"header"
>
<h:outputText
value=
"${i18n['discount.details']}"
/>
</f:facet>
<h:outputText
value=
"#{discount.details}"
/>
</h:column>
<h:column>
<f:facet
name=
"header"
>
<h:outputText
value=
"${i18n['discount.shortdesc']}"
/>
</f:facet>
<h:outputText
value=
"#{discount.shortdesc}"
/>
</h:column>
<h:column>
<f:facet
name=
"header"
>
<h:outputText
value=
"${i18n['discount.amountMin']}"
/>
</f:facet>
<h:outputText
value=
"#{discount.amountMin}"
/>
</h:column>
<h:column>
<f:facet
name=
"header"
>
<h:outputText
value=
"${i18n['discount.amountMax']}"
/>
</f:facet>
<h:outputText
value=
"#{discount.amountMax}"
/>
</h:column>
<h:column>
<f:facet
name=
"header"
>
<h:outputText
value=
"${i18n['discount.maxNum']}"
/>
</f:facet>
<h:outputText
value=
"#{discount.maxNum}"
/>
</h:column>
<h:column>
<f:facet
name=
"header"
>
<h:outputText
value=
"${i18n['discount.perUser']}"
/>
</f:facet>
<h:outputText
value=
"#{discount.perUser}"
/>
</h:column>
<h:column>
<h:link
outcome=
"/product/editDiscount"
value=
"#{i18n['discount.edit']}"
>
<f:param
name=
"discountid"
value=
"#{discount.id.id}"
/>
</h:link>
</h:column>
</h:dataTable>
</h:form>
</composite:implementation>
</html>
...
...
code/LanBortalWeb/src/fi/insomnia/bortal/resources/i18n.properties
View file @
3d9986b
...
...
@@ -40,6 +40,11 @@ page.product.createBill.pagegroup=shop
page.product.edit.pagegroup
=
admin
page.product.list.pagegroup
=
admin
product.providedRole
=
Tuote tarjoaa roolin
product.createDiscount
=
Lis mralennus
product.saved
=
Tuote tallennettu
product.returnProductEdit
=
Palaa tuotteeseen:
page.role.create.pagegroup
=
admin
...
...
code/LanBortalWeb/src/fi/insomnia/bortal/web/cdiview/shop/ProductView.java
View file @
3d9986b
...
...
@@ -2,8 +2,12 @@ package fi.insomnia.bortal.web.cdiview.shop;
import
javax.ejb.EJB
;
import
javax.enterprise.context.ConversationScoped
;
import
javax.faces.model.ListDataModel
;
import
javax.inject.Named
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
fi.insomnia.bortal.beans.EventBeanLocal
;
import
fi.insomnia.bortal.beans.ProductBeanLocal
;
import
fi.insomnia.bortal.enums.apps.ShopPermission
;
...
...
@@ -27,6 +31,10 @@ public class ProductView extends GenericCDIView {
private
Integer
productId
;
private
ListDataModel
<
Discount
>
productDiscounts
;
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
ProductView
.
class
);
public
void
initEditView
()
{
if
(
super
.
requirePermissions
(
ShopPermission
.
MANAGE_PRODUCTS
)
&&
product
==
null
)
{
product
=
prodbean
.
findById
(
getProductId
());
...
...
@@ -76,4 +84,30 @@ public class ProductView extends GenericCDIView {
public
Discount
getDiscount
()
{
return
discount
;
}
public
String
createDiscount
()
{
product
=
prodbean
.
mergeChanges
(
product
);
return
"/product/edit"
;
}
public
String
initCreateDiscount
()
{
discount
=
new
Discount
(
product
);
product
.
getDiscounts
().
add
(
discount
);
return
"/product/createDiscount"
;
}
public
String
editDiscount
()
{
discount
=
productDiscounts
.
getRowData
();
return
"/product/editDiscount"
;
}
public
ListDataModel
<
Discount
>
getProductDiscounts
()
{
productDiscounts
=
new
ListDataModel
<
Discount
>(
product
.
getDiscounts
());
return
productDiscounts
;
}
}
code/LanBortalWeb/src/fi/insomnia/bortal/web/cdiview/user/RoleDataView.java
View file @
3d9986b
package
fi
.
insomnia
.
bortal
.
web
.
cdiview
.
user
;
import
java.util.List
;
import
javax.ejb.EJB
;
import
javax.enterprise.context.RequestScoped
;
import
javax.faces.model.ListDataModel
;
import
javax.inject.Named
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
fi.insomnia.bortal.beans.RoleBeanLocal
;
import
fi.insomnia.bortal.model.Role
;
import
fi.insomnia.bortal.web.cdiview.GenericCDIView
;
...
...
@@ -20,10 +25,27 @@ public class RoleDataView extends GenericCDIView {
private
transient
ListDataModel
<
Role
>
roles
;
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
RoleDataView
.
class
);
public
ListDataModel
<
Role
>
getRoles
()
{
if
(
roles
==
null
)
{
roles
=
new
ListDataModel
<
Role
>(
rolebean
.
listRoles
());
}
return
roles
;
}
public
Role
getNoSelection
()
{
return
Role
.
EMPTY_ROLE
;
}
public
ListDataModel
<
Role
>
getRolesWithEmpty
()
{
if
(
roles
==
null
)
{
List
<
Role
>
list
=
rolebean
.
listRoles
();
list
.
add
(
0
,
Role
.
EMPTY_ROLE
);
roles
=
new
ListDataModel
<
Role
>(
list
);
logger
.
info
(
"rolecount {}"
,
roles
.
getRowCount
());
}
return
roles
;
}
}
code/LanBortalWeb/src/fi/insomnia/bortal/web/converter/RoleConverter.java
View file @
3d9986b
...
...
@@ -13,7 +13,7 @@ import org.slf4j.LoggerFactory;
import
fi.insomnia.bortal.beans.RoleBeanLocal
;
import
fi.insomnia.bortal.model.Role
;
@Named
@Named
(
"roleConverter"
)
@RequestScoped
public
class
RoleConverter
implements
Converter
{
...
...
@@ -25,6 +25,10 @@ public class RoleConverter implements Converter {
@Override
public
Object
getAsObject
(
FacesContext
context
,
UIComponent
component
,
String
value
)
{
logger
.
debug
(
"converting string {} to Object"
,
value
);
if
(
value
==
null
||
value
.
isEmpty
()
||
value
.
equals
(
"0"
))
{
return
null
;
}
Role
ret
=
rolebean
.
find
(
Integer
.
parseInt
(
value
));
return
ret
;
}
...
...
@@ -32,11 +36,15 @@ public class RoleConverter implements Converter {
@Override
public
String
getAsString
(
FacesContext
context
,
UIComponent
component
,
Object
value
)
{
String
ret
=
""
;
if
(
value
instanceof
Role
)
{
ret
=
((
Role
)
value
).
getId
().
toString
();
Role
r
=
((
Role
)
value
);
if
(
r
.
getId
()
!=
null
)
{
ret
=
r
.
getId
().
toString
();
}
}
logger
.
debug
(
"converting role {} to string"
,
ret
);
return
ret
;
}
}
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment