Grails Scaffolding Default Date - groovy

I'm using Grails scaffolding and would like to make a change in the default date during a create. Currently dates default to today's date. How would one default it to blank or no date?
Thanks,
Steve

You can do grails install-templates and customize template, used for rendering.
In $PROJECT/src/templates/scaffolding/renderEditor.template there is method renderDateEditor which should be customized to your needs.
This customization will be applied to all new scaffolding operations.

Whatever the default value in your domain object is will show up in the form on create.
class Test {
Date aDate
}
In that example the domain object has a non-nullable date, so the default value is a newly constructed date. If the domain object gets changed to:
class Test {
Date aDate
static constraints = {
aDate(nullable:true)
}
}
Then the default value for the date will be null and that's what will show up in the scaffolded create form.
If you want to set the default value explictly, just assign it with a domain object initializer:
class Test {
Date aDate = Date.parse("yyyy-MM-dd", "2010-01-01")
static constraints = {
aDate(nullable:true)
}
}

Related

How to extend the core customer table?

I created a custom table with additional settings for customers. Next I added a field to the customer core table in which I'd like to store the id choice per customer. I extended with EntityExtensionInterface the customerDefinition :
public function extendFields(FieldCollection $collection): void
{
$collection->add(
(new OneToOneAssociationField(
'customerSetting',
'customer_setting',
'id',
WdtCustomerSettingsDefinition::class,
true
))->addFlags(new Inherited())
);
}
public function getDefinitionClass(): string
{
return CustomerDefinition::class;
}
When I manually manipulate the customer table, with an id from my custom table in the added field, I can retrieve and use the settings from my custom table in the storefront.
For the backend I created a single select to the entity custom_table,
<sw-entity-single-select entity="wdt_customer_settings" v-model="customer.extensions.customerSetting.id" >
</sw-entity-single-select>
and with the manually 'injected' id from the custom table, this choice indicates indeed 'selected' However, after changing to another choice and saving results in an error: Customer could not be saved.
What am I missing?
You should look always to the ajax responses. There is the explict error which is occured. Do you added some boilerplate code to check that your extensions is always available? Otherwise it would cause issues on new entities

Use of proper interceptor logic in Hybris

I have a products.impex file with an attribute gender=MALE or FEMALE in the itemtype MyProduct(which extends Product) I have an attribute "choice" which depends on the values in the gender column so I initially wrote a PrepareInterceptor and checked for isNew condition.Now it works fine for the new rows but when the value is changed it does not work.Should I just remove the isNew condition or use InitDefaultsInterceptor?
if (ctx.isRemoved(productModel))
{
//TODO
}
else if (ctx.isNew(productModel) || ctx.isModified(productModel, ProductModel.GENDER))
{
//TODO
}
As far as interceptor concern, you can use PrepareInterceptor for preparing fields value as it called before ValidateInterceptor. If you just want to validate your fields then use ValidateInterceptor. The Init Defaults Interceptor is called when a model is filled with its default values.
Have a look at interceptor life cycle.

Hybris cs-cockpit currency position

my cscockpit is displaying let says"125.00PHP" in price value.
Is there any config parameter or impex to change to "PHP125.00"?
You need to customize the widget corresponding to this layout.
For the same, you need to extend de.hybris.platform.cscockpit.widgets.renderers.impl.BasketTotalsWidgetRendererand override renderOrderDetail method of AbstractOrderTotalsWidgetRenderer
You need to change the below code block as per your requirement
NumberFormat currencyInstance = (NumberFormat) getSessionService()
.executeInLocalView(
new SessionExecutionBody(cartCurrencyModel) {
public Object execute() {
AbstractOrderTotalsWidgetRenderer.this
.getCommonI18NService()
.setCurrentCurrency(
this.val$cartCurrencyModel);
return AbstractOrderTotalsWidgetRenderer.this
.getFormatFactory()
.createCurrencyFormat();
}
});

Set different value for Sharepoint custom property of same web part in multiple different pages

I have visual web part and i am attempting to set custom property unique value on each pages. For example i have two aspx pages. Deal.aspx and Fund.aspx. Both page is having same web part used. When i set the value custom property in web part of Deal.aspx the same value gets reflect in Fund.aspx page web part as well. I read about PersonalizationScope but it did not help for my scenario. Below is the custom property i have created.
public static string ListName;
[Category("Extended Settings"),
Personalizable(PersonalizationScope.User),
WebBrowsable(true),
WebDisplayName("Enter List Name"),
WebDescription("Please Enter a List Name")]
public string _ListName
{
get { return ListName; }
set
{
// Sample Validation
Regex oRegEx = new Regex("[a-zA-Z]+");
if (!oRegEx.IsMatch(value))
throw new Microsoft.SharePoint.WebPartPages.
WebPartPageUserException(
"Please enter alphabeth characters only");
ListName = value;
}
}
Problem is not in SharePoint or PersonalizationScope. It works fine. Problem is in static property ListName. Static properties are "shared" between all instances of the same class. So all your webparts will have the same value there.

Adding custom field to User programmatically through liferay.expando

I am trying to add fields to com.liferay.portal.model.User, an extra attribute using Expando. Can someone explain to me how this method is adding a field because docs don't have much description.
private void addUserCustomAttribute(long companyId, ExpandoTable userExpandoTable, String attributeName, int type) throws PortalException, SystemException {
ExpandoColumnLocalServiceUtil.getColumn(userExpandoTable.getTableId(), attributeName); //should be addColumn(long tableId, String name, int type) ???
} //and where can find type description couse i have very specific type, Map(String,Object) couse in ExpandoColumnConstants didn't see it
I have taken this from Liferay Expando Wiki's Adding User Custom Attributes.
When should I call this all? Where to put this in my project? What change is required or everything needs to be changed to call it.
Some good tutorial will be nice because it's hard to find something from 0 to end, always found only some part with no explanation.
The question is not very clear. But if you simply want to add a custom attribute for your User then you can refer to my answer here and reproduced for your reference:
Custom field for the user-entity can be created through:
Control Panel -> Portal -> Custom Fields -> User.
And programmatically can be created as follows:
user.getExpandoBridge().addAttribute("yourCustomFieldKey");
Then set the value as:
user.getExpandoBridge().setAttribute("yourCustomFieldKey", "valueForCustomField");
If your custom field is already present you can check like this:
if (user.getExpandoBridge().hasAttribute("yourCustomFieldKey")) { ... };
The data is stored in tables prefixed with "EXPANDO":
EXPANDOCOLUMN: stores the custom field key and other settings
(contains the tableId refrences)
EXPANDODATA: stores the custom field value for the key (contains the
columnId and tableId refrences)
EXPANDOTABLE: stores for which liferay entity (user) are you adding
the custom field
EXPANDOROW: stores linking information between a user and its values
(contains tableId and userId refrences)
Hope this helps.
If your custom field is multivalue, you can use this:
String customVal = "yourCustomFieldValue";
user.getExpandoBridge().setAttribute("yourCustomFieldKey", new String[] {customVal }, false);
The last parameter set to "false" avoids permission check.

Resources