Primefaces Calender Date comparison only works within the same month - date

I have two calendars. It shouldn´t be possible for the user to pick a date in calendar two that is before the date in calendar one. Also if calender one picks a value that is after calendar two, calender two should change automatically to the same date as calendar one.
This is the index.html. "vom" is Calendar one and "bis" is calendar two.
<p:calendar id="vom" value="#{IndexBean.vom}" maxlength="50"
navigator="true" pattern="dd.mm.yyyy" locale="de" mask="true" >
<f:ajax event="dateSelect" execute="vom" listener="#{IndexBean.dateChanger}" render="vom bis" />
</p:calendar>
<p:calendar id="bis" value="#{IndexBean.bis}" maxlength="50"
navigator="true" pattern="dd.mm.yyyy" locale="de" mask="true" mindate="#{IndexBean.vom}">
<f:ajax event="dateSelect" execute="bis" listener="#{IndexBean.dateChanger}" render="vom bis"/>
</p:calendar>
This is the dateChanger method
public void dateChanger() {
try {
if (bis.before(vom)) {
bis = (Date) vom.clone();
}
} catch (Exception e) {
}
}
The problem is everything works fine as long both calendars are in the same month. I debugged the dateChanger and I´m realy confused about the values coming from the calendars. It doesn´t seem to be dependent of the browser. The type of the dates is java.util.date.
Any clue why this happens?
Java 1.8
JSF 2.2.14

You use a wrong pattern. In
pattern="dd.mm.yyyy"
the mm means 'minutes' and not 'month'. Month is 'MM' so change it to
pattern="dd.MM.yyyy"

Related

Odoo 12: How to disable past dates with datepicker?

How can I use datepicker in a Date field?
I try to disable past dates like that:
<field class="delivery_date" name="delivery_date" options="{'datepicker':{'minDate': 0}}"/>
But past dates are shown nevertheless.
It seems as if the options-tag is not parsed at all. I used the debugger to get an overview what happens in addons/web/static/src/js/fields/basic_fields.js (where datepicker is initialized) but there are no options declared.
Thanks in advance!
UPDATE:
That's my field definition
delivery_date = fields.Date(string='Delivery Date', help="Date on which sales order is delivered.", default=_get_default_delivery_date)
The default-method sets the date to the day after tomorrow.
My view declaration is above. That's all I have.
I expected that the datepicker is invoked as soon as I use it in "options"-attribute.
When I enter my website the datepicker is shown, when I click on that date-field, but the past dates are not disabled..
I tried multiple modules, but nothing works for me in js Odoo 14
#api.model
def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):
res = super(AccountInvoice, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu)
if view_type == 'form':
doc = etree.XML(res['arch'])
for node in doc.xpath("//field[#name='date_invoice']"):
node.set('options', "{'datepicker': {'minDate': '%sT23:59:59'}}" % fields.Date.today().strftime(DEFAULT_SERVER_DATE_FORMAT))
res['arch'] = etree.tostring(doc)
return res
Try this, This may help you

Object Number is not an instance of Date, Angular 2 form, typescript

I'm working on an Angular 2 form. I'm getting problems working with a date variable.
For cross-browser compatibility on a calendar input, I'm using ng-pick-datetime (https://www.npmjs.com/package/ng-pick-datetime).
I get this error -> ERROR TypeError: [object Number] is not an instance of Date
The template code of the date input:
<div class="input-control col-sm-6" >
<label class="control-label" for="startDate">
Starting date *
</label>
<owl-date-time
[(ngModel)]="data.startDate"
[dateFormat]="'DD-MM-YYYY'"
[inputId]="'startDate'"
[placeHolder]="'dd-mm-aaaa'"
[type]="'calendar'"
[dataType]="'date'"
[autoClose]="'true'"
id="startDate"
name="startDate"
#startDate="ngModel"
[disabled]="!paramsService.isSolicitante()"
[hideClearButton]="!paramsService.isSolicitante()"
[max]="data.endDate"
required>
</owl-date-time >
</div>
The declaration of this startDate property in the typescript "Data" class:
startDate: Date = new Date();
endDate: Date = null;
As you can see, the [dataType] property on the calendar picker is set to 'date', same type as the variable.
What am I doing wrong?
Solved! It was an issue of assigning the data from one variable to another, with no use of new Date().

DD-MM-YYYY date format possible for input in orbeon?

I use Orbeon Forms and i have a calendar input.
When i pick up a date, it shows me the date in american format: MM/DD/YYYY.
For example i have 1/27/2015!
How can the input show the date in european format DD/MM/YYYY? Like 27/01/2015
I've tried without success:
<!-- Main instance -->
...
</StartOfWork>
...
<!-- Bindings -->
...
<xf:bind id="startOfWork-bind" ref="FormData/Payload/Project/Payment/StartOfWork"
name="startOfWork" type="xf:date"/>
...
...<fr:view>
...
<xf:input id="startOfWork-control" bind="startOfWork-bind" class="" date="[D]/[M]/[Y]">
<xf:label ref="$form-resources/startOfWork/label"/>
<xf:hint ref="$form-resources/startOfWork/hint"/>
<xf:alert ref="$fr-resources/detail/labels/alert"/>
</xf:input>
...</fr:view>
...
You can, by setting the oxf.xforms.format.input.date property to [D]/[M]/[Y], as in:
<property as="xs:string"
name="oxf.xforms.format.input.date"
value="[D]/[M]/[Y]"/>
And you can find more on other supported values in the documentation for that property.

How to refresh page on select of date from datepicker Liferay

I am using liferay-ui datepicker.
When my page loads the date is current date in the datepicker and data of the current date is loaded on the page.
What I want to do is allow the user to view data such that when user selects any other date, data of the selected date is dispayed.
How should I go about this?
SHould I refresh the entire page? how?
Or should I use ajax? how should i go about? if ajax is to be used how should i pass the data?
EDIT:
I will explain my problem in detail. I am using liferay:ui:date . I want user to select a date from it. Once the user selects date, I want to pass the date to custom-sql. I am calling the finder function in the same jsp as follows:
List<Object[]> ObjdisplayAttListName = AttendanceLocalServiceUtil.findAttendance(currentdate);
I want to pass the user selected date in the above function.
Right now what I am doing is only passing the current date in the above line of code. Iwant to pass the user selected date.
I think you should go with AJAX. Make ajax call when you select date using date-picker
and get that date in your serveResource method. Based on your selected date fetch data and pass that data to your presentation layer in required format i.e JSON.
Collect data and display it. Thats it :)
Let me know if you have problem !!
Personally, I prefer working with liferay-ui:input-date. Just make sure to keep a Date or Calendar object in your Controller Class
<portlet:actionURL var="setDate" name="setDate" >
<portlet:param name="jspPage" value="/html/yourPage.jsp" />
</portlet:actionURL>
<aui:form action="<%= setDate%>" method="post" enctype="multipart/form-data" >
<%
Date date = (Date)renderRequest.getAttribute("_a_date");// Get your Date from the controller
Calendar cal = CalendarFactoryUtil.getCalendar();
cal.setTime(new Date()); // create with current date if this form is presented for the 1st time
if(Validator.isNotNull(date)){
cal.setTime(date); // else use the Date you want to display
}
%>
<liferay-ui:input-date
yearRangeStart="1970"
yearRangeEnd="2100"
formName="pickedDate"
dayParam="dd"
monthParam="mm"
yearParam="yy"
dayValue="<%= cal.get(Calendar.DATE) %>"
monthValue="<%= cal.get(Calendar.MONTH) %>"
yearValue="<%= cal.get(Calendar.YEAR) %>"
/>
<aui:button name="setDateBtn" value="Submit that date" type="submit"/>
</aui:form>
Back to the controller..
public void setDate(ActionRequest actionRequest,
ActionResponse actionResponse) throws IOException, PortletException {
UploadPortletRequest queryRequest = PortalUtil.getUploadPortletRequest(actionRequest);
int dd = ParamUtil.getInteger(queryRequest, "dd");
int mm = ParamUtil.getInteger(queryRequest, "mm");
int yy = ParamUtil.getInteger(queryRequest, "yy");
String date_format = "yyyy/MM/dd";
SimpleDateFormat sdf = new SimpleDateFormat(date_format);
GregorianCalendar gc = new GregorianCalendar(yy, mm, dd);
Date date = gc.getTime(); // Keep this Date and reload the page sending this Date in an actionRequest param
actionRequest.setAttribute("_a_date", date );

detailsview: insert / update single record

I want to implement the following scenario...
Table related to this question is as follows:
ProfileID int (identity)
FirstName varchar(100)
LastName varchar(100)
step 1. User visits profiles.aspx page. Here in a grid view, he can see other people profiles. (I know how to do this.)
Step 2. User visits MyProfile.aspx page. Since his profile does not exist, details view, is blank with insert button enabled. User clicks the insert button and he can add his own profile only. (I dont know how to do this).
Step 3. Once users profile is added, it shows up on profiles.aspx page. He wants to update his own profile. He navigates to MyProfile.aspx page with ProfileID lets say 33.
DetailsView is able to pull up his profile based on profileid and update button is enabled. (I dont know how how to do this.)
Could some one please help me with step 2 and 3. I dont know how to setup sqldatasource and detailsview to accomplish this.
Thank you in advance.
Alright , I'll give you a simple solution which you can alter to fit to your needs.
For the Step 2:
You create a page which called create.aspx for example; in that page you put all the text boxes that you need and a button for registration. On the clicked event of that button write something as below
//using System.Data;
//using System.Data.Sql; you have to import these
//Put connection string
SqlConnection sqlcon = new SqlConnection("your connection string here which will be able to find in MSDN");
sql.Open();
SqlCommand sqlcmd = new SqlCommand("INSERT INTO Statement which easily find in MSDN too",sqlcon);
sqlcmd.ExecuteNoneQuery();
sql.Close();
Which this code you can insert into database whatever you want. In the INSERT INTO string you concatenate your inputs but be very careful that may cause SqlInjection bug which is very dangerous.(Please read articles about it).
For Step 3:
everything is all the same except instead of putting "INSERT ...." statement you have to use "UPDATE ..." statement which can find on MSDN.
Regards,
Pooria.
see following example........
source file .aspx
i am using gridview and detailsview for insert,update,edit a truckmaster table.
do the following steps:
1.take a gridview.assign datakeynames as your unique column from table.you can write boundfields for your each field.Infact that is better way.
2. take datasource control.Bind it to your table.
3.bind this datasource to Gridview.you will understand this steps better once you go through the following code.
4.Take a detailsview.Assign datakeynames as your unique column from table.
5.Take another datasource.Bind it to same table.declare insertcommand,selectcommand.
declare select parameter,updateparameter as in below code.
Hope it will help you.
<asp:GridView id ="gridTruckMaster"
runat ="server"
CssClass ="GridView"
DataKeyNames ="TruckType"
DataSourceID ="SqlDataSource1"
AutoGenerateColumns ="False"
ShowFooter ="True"
AllowPaging ="True">
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White"></FooterStyle>
<RowStyle VerticalAlign="Top" BackColor="#F7F6F3" ForeColor="#333333"></RowStyle>
<Columns>
<asp:BoundField DataField="TruckType" HeaderText="TruckType" SortExpression="TruckType"></asp:BoundField>
<asp:BoundField DataField="TruckCapacity" HeaderText="TruckCapacity" SortExpression="TruckCapacity"></asp:BoundField>
<asp:CommandField ShowSelectButton="True"></asp:CommandField>
</Columns>
<PagerStyle BackColor="#284775" HorizontalAlign="Center" ForeColor="White"></PagerStyle>
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White"></SelectedRowStyle>
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White"></HeaderStyle>
</asp:GridView>
<asp:SqlDataSource ID ="SqlDataSource1"
runat ="server"
ConnectionString ="<%$ ConnectionStrings:GodrejReporterConnectionString %>"
SelectCommand ="SELECT [TruckType], [TruckCapacity] FROM [tbl_TruckMaster]"></asp:SqlDataSource>
<asp:DetailsView id ="dtlviewTruckMaster"
runat ="server"
CssClass ="GridView"
Width ="125px"
DataKeyNames ="TruckType"
Height ="50px"
AutoGenerateRows ="False"
HeaderText ="Truck Details"
><Fields>
<asp:BoundField DataField="TruckType" HeaderText="TruckType" ReadOnly="True"></asp:BoundField>
<asp:BoundField DataField="TruckCapacity" HeaderText="TruckCapacity"></asp:BoundField>
<asp:CommandField ShowInsertButton="True"></asp:CommandField>
<asp:CommandField ShowEditButton="True"></asp:CommandField>
</Fields>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White"></FooterStyle>
<RowStyle VerticalAlign="Top" BackColor="#F7F6F3" ForeColor="#333333"></RowStyle>
<EditRowStyle Width="250px" Height="10px"/>
<InsertRowStyle Width="250px" Height="10px" />
<PagerStyle HorizontalAlign="Center" BackColor="#284775" ForeColor="White"></PagerStyle>
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White"></HeaderStyle>
<CommandRowStyle BackColor="#5D7B9D" />
</asp:DetailsView>
<asp:SqlDataSource ID ="SqlDataSource2"
runat ="server"
ConnectionString ="<%$ ConnectionStrings:GodrejReporterConnectionString %>"
SelectCommand ="SELECT [TruckType], [TruckCapacity] FROM [tbl_TruckMaster] where TruckType=#pTruckType"
insertcommand ="insert into tbl_TruckMaster(TruckType,TruckCapacity) values(#TruckType,#TruckCapacity)"
updatecommand ="update tbl_TruckMaster set TruckCapacity=#TruckCapacity where TruckType=#pType"
>
<SelectParameters>
<asp:ControlParameter ControlID="gridTruckMaster" Name="pTruckType" PropertyName="SelectedValue" />
</SelectParameters>
<UpdateParameters>
<asp:ControlParameter ControlID="gridTruckMaster" Name="pType" PropertyName="SelectedValue" />
</UpdateParameters>
</asp:SqlDataSource>
If you getting problem you can mail me at tbchandgude#gmail.com