*/
private Product createProductInstance () {
// Create product instance
- final Product newProduct = new GenericProduct(this.getProductI18nKey(), this.getProductGrossPrice(), this.getProductCurrencyCode(), this.getProductCategory(), this.getProductAvailability(), this.getProductUnitAmount(), this.getProductUnitI18nKey());
+ final Product newProduct = new GenericProduct(
+ this.getProductI18nKey(),
+ this.getProductGrossPrice(),
+ this.getProductCurrencyCode(),
+ this.getProductCategory(),
+ this.getProductAvailability(),
+ this.getProductUnitAmount(),
+ this.getProductUnitI18nKey()
+ );
// Set all optional fields
newProduct.setProductAgeGroup(this.getProductAgeGroup());
// Fire event
this.categoryAddedEvent.fire(new CategoryAddedEvent(updatedCategory));
-
- // Unset all older values
- this.clear();
}
/**
this.parentCategory = parentCategory;
}
- /**
- * Clears this bean (example: when category has been added)
- */
- private void clear () {
- // Clear all fields
- this.setCategoryI18nKey(null);
- this.setParentCategory(null);
- }
-
/**
* Creates a category instance with all fields (except primary key)
* <p>
*/
private Category createCategoryInstance () {
// Create category
- final Category category = new ProductCategory(this.getCategoryI18nKey(), this.getParentCategory(), this.getCategoryShownInStatistics());
+ final Category category = new ProductCategory(this.getCategoryI18nKey(), this.getCategoryShownInStatistics());
+
+ // Set all optional fields
+ category.setParentCategory(this.getParentCategory());
// Return it
return category;
@Override
public void validate (final FacesContext context, final UIComponent component, final Object productI18nKey) throws ValidatorException {
// The required field
- final String[] requiredFields = {"categoryI18nKey"}; //NOI18N
+ final String[] requiredFields = {"productI18nKey"}; //NOI18N
// Pre-validate it
super.preValidate(context, component, productI18nKey, requiredFields, Boolean.FALSE);
PRODUCT_LIST_CONTROLLER = CDI.current().select(FinancialsProductListWebViewBean.class).get();
}
+ // Don't allow duplicates by default
+ Boolean allowDuplicates = Boolean.FALSE;
+
+ // Is attribute "allowEmptyRequiredData" set?
+ if (component.getAttributes().containsKey("allowDuplicates")) { //NOI18N
+ // Get attribute
+ final Object attribute = component.getAttributes().get("allowDuplicates"); //NOI18N
+
+ // Make sure, it is Boolean as no String is accepted anymore
+ if (!(attribute instanceof String)) {
+ // Not valid attribute, please use "true" or "false" (default)
+ throw new IllegalArgumentException("allowDuplicates must be of type String. Please use \"true\" or \"false\" for f:attribute value."); //NOI18N
+ }
+
+ // Securely cast it
+ allowDuplicates = Boolean.parseBoolean((String) attribute);
+ }
+
// Check, if the name has already been used
- if (PRODUCT_LIST_CONTROLLER.isProductI18nKeyAdded((String) productI18nKey)) {
+ if (!allowDuplicates && PRODUCT_LIST_CONTROLLER.isProductI18nKeyAdded((String) productI18nKey)) {
// Create message
final String message = MessageFormat.format("I18n key {0} is already used. Please type an other.", productI18nKey);
<!-- @TODO Find an interface for BaseFacesBean and set it here instead -->
<type>org.mxchange.jcoreee.bean.faces.BaseFacesBean</type>
</attribute>
+ <attribute>
+ <name>allowDuplicates</name>
+ <description>Whether to allow duplicate i18n keys.</description>
+ <required>false</required>
+ <type>java.lang.Boolean</type>
+ </attribute>
</tag>
</facelet-taglib>
validatorMessage="#{project.ADMIN_ENTERED_PRODUCT_I18N_KEY_ALREADY_ADDED}"
>
<f:validator validatorId="GenericProductValidator" />
+ <f:attribute name="allowDuplicates" value="#{allowDuplicates}" />
</p:inputText>
<p:outputLabel for="productNumber" value="#{project.ADMIN_ENTER_GENERIC_PRODUCT_NUMBER}" />
<product:genericProductForm
targetController="#{adminGenericProductActionController}"
+ allowDuplicates="true"
/>
<f:facet name="footer">