<p:column headerText="Cancel" width="60">
<p:commandLink actionListener="#{userLeaveBean.cancelForLeave}" title="Cancel Request" process="#this" update="leaveDataTable" disabled="false">
<h:graphicImage url="resources/images/cancel.gif"/>
<f:attribute name="userId" value="#{employee.name}"/>
<f:attribute name="leaveId" value="#{leaveDetails.strLeaveId}"/>
</p:commandLink></p:column>
Hi I have written this code to modify a row value of a data table. The method that invoked named 'cancelForLeave' modifies the detail of the row value of the data table.The method is as follows:
public void cancelForLeave(ActionEvent actionEvent){
String userId = (String)actionEvent.getComponent().getAttributes().get("userId");
String leaveId = (String)actionEvent.getComponent().getAttributes().get("leaveId");
int currentYear = Calendar.getInstance().get(Calendar.YEAR);
ConnectLdap connectLdap = new ConnectLdap();
UserTotalLeaveInfoBean userTotalLeaveInfoBean = connectLdap.getUserLeaveBean(""+currentYear, userId);
if(userTotalLeaveInfoBean != null){
UserGeneralLeaveDetailsBean[] userGeneralLeaveDetailsBean = userTotalLeaveInfoBean.getArrUserGeneralLeaveDetailsBean();
if(userGeneralLeaveDetailsBean != null){
for(int i=0;i<userGeneralLeaveDetailsBean.length;i++){
String beanLeaveId = userGeneralLeaveDetailsBean[i].getStrLeaveId();
if(leaveId.trim().equalsIgnoreCase(beanLeaveId)){
if(userGeneralLeaveDetailsBean[i].getStrLeaveStatus().trim().equalsIgnoreCase(LeaveStatus.LVST_APPLIED)){
userGeneralLeaveDetailsBean[i].setStrLeaveStatus(LeaveStatus.LVST_CANCELED);
}if(userGeneralLeaveDetailsBean[i].getStrLeaveStatus().trim().equalsIgnoreCase(LeaveStatus.LVST_APPROVED)){
userGeneralLeaveDetailsBean[i].setStrLeaveStatus(LeaveStatus.LVST_CANCELREQ);
}
userTotalLeaveInfoBean.setArrUserGeneralLeaveDetailsBean(userGeneralLeaveDetailsBean);
connectLdap.addAppliedLeaveInLdap(userTotalLeaveInfoBean, ""+currentYear, userId);
leaveDetails.add(userGeneralLeaveDetailsBean[i]);
}
}
}
}
}
private List<UserGeneralLeaveDetailsBean> leaveDetails;
//Getter and Setter
Now the problem is that, When I click on the image button it modifies the value for the row, but adds an extra row in the data table with the modified value. But when I Logout and then Again login,it shows there is no extra row, and the row I attempted to modify shows nicesly with the modified value.
what should be done to prevent the extra row addition at run time, while attempting for the value change of the data table row?Please Help!!
I get the following Log Details: If I put a Log in the page:
Monday, June 03, 2013 3:59:55 PM : Initiating ajax request.
Monday, June 03, 2013 3:59:55 PM : Form to post applyLeaveForm.
Monday, June 03, 2013 3:59:55 PM : URL to post /DemoApplication/applyLeave.xhtml.
Monday, June 03, 2013 3:59:55 PM : Post Data:javax.faces.partial.ajax=true&javax.faces.source=applyLeaveForm%3AleaveDataTable%3A0%3Aj_idt90&javax.faces.partial.execute=applyLeaveForm%3AleaveDataTable%3A0%3Aj_idt90&javax.faces.partial.render=applyLeaveForm%3AleaveDataTable&applyLeaveForm%3AleaveDataTable%3A0%3Aj_idt90=applyLeaveForm%3AleaveDataTable%3A0%3Aj_idt90&applyLeaveForm=applyLeaveForm&applyLeaveForm%3AfromDate_input=&applyLeaveForm%3AtoDate_input=&applyLeaveForm%3Aj_idt59=morning&applyLeaveForm%3Aj_idt60=endofday&applyLeaveForm%3AleaveDataTable%3A0%3AeditFrom_input=03-Jun-2013&applyLeaveForm%3AleaveDataTable%3A0%3Aj_idt68=morning&applyLeaveForm%3AleaveDataTable%3A0%3AeditTo_input=04-Jun-2013&applyLeaveForm%3AleaveDataTable%3A0%3Aj_idt72=endofday&javax.faces.ViewState=-3803632482959899224%3A-5634910090194656061
Monday, June 03, 2013 3:59:55 PM : Response received succesfully.
Monday, June 03, 2013 3:59:56 PM : DOM is updated.
Monday, June 03, 2013 3:59:56 PM : Response completed.
You don't need to add the modified item back to your list :
leaveDetails.add(userGeneralLeaveDetailsBean[i]);
You must remove this line and it should fix your problem. You are updating your source the line just before, and the add only apply in the current view, that's why refreshing get the right data.
Also your bean must be at least in #ViewScoped or #SessionScoped.
Related
i got a list of datetime value from ()table look like these: 31/12/14 4:45:30 PM
31/12/14 4:45:30 PM
31/12/14 4:45:30 PM
31/12/14 4:45:30 PM
31/12/14 4:45:30 PM
AND i want them to only show like e.g.:, in the combobox.display member
2014
2015
2016
2017
i know i wrote like below might have datatypes error, but anyone can correct me or guide me on this??
Public Sub combothing()
Dim connection As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" & aaa & "';Persist Security Info=False;")
Dim selectme As String = "SELECT * FROM yeartbl"
Dim cmd As New OleDbCommand(selectme, connection)
Dim da As New OleDbDataAdapter
Dim ds As New DataSet
Dim dt As New DataTable
Try
If connection.State = ConnectionState.Closed Then
connection.Open()
End If
da.SelectCommand = cmd
da.Fill(ds)
da.Fill(ds, "yeartbl")
dt = ds.Tables("yeartbl")
connection.Close()
Me.ComboBox1.DataSource = ds.Tables(0)
Me.ComboBox1.ValueMember = "YID"
**Convert.ToDateTime(Me.ComboBox1.DisplayMember = "Years").Date.Year.ToString()**
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
One of the things that you can do (assuming we work against Excel) is, when you already filled DataSet, add one more column
ds.Tables(0).Columns.Add("year", System.Type.GetType("System.Integer"))
For each (r as row in ds.Tables(0).Rows)
r("year") = DirectCast(r("YTD"), DateTime).Year 'assuming it is not null column
Next
Now, set Value Member to
Me.ComboBox1.ValueMember = "Year"
Also, needs more research, you may can do this:
"SELECT *, FunctionTOConvertToDate(YTD) as year FROM yeartbl"
when the date property is set in the model, this is executed:
if (!(rdr["JobEnded"] is DBNull)) { job.JobEnded = (DateTime)rdr["JobEnded"]; }
which results in job.JobEnded being 1/1/0001 12:00:00 AM.
What can I use in place of
#Html.DisplayFor(modelItem => item.JobEnded)
to show "In Progress" instead of "1/1/0001 12:00:00 AM".
I've tried putting an if/else in the view, but was only able to display a valid date or nothing. I'm sure I'm missing something really basic here as this is my first attempt at an APS.NET MVC view.
You're dealing with default dates here, so to test for it, you need to use:
#if (item.JobEnded == default(DateTime))
{
#:In Progress
}
else
{
#Html.DisplayFor(m => item.JobEnded)
}
Or in one-liner form:
#((item.JobEnded == default(DateTime)) ? "In Progress" : Html.DisplayFor(m => item.JobEnded).ToString())
I'm having some trouble working with dates.
I have an object with a date field:
public DateTime FechaInicio{get; set;}
This definition generates the following field in the database:
FechaInicio datetime not null
Making the request to the web service I get the date ( in the JSON ) in the following format:
"FechaInicio": "1982-12-02T00: 00:00"
And calling FechaInicio() on tne entity returns a javascript Date object.
Creating a new entity I get the following value:
createPalanca var = function () {
MetadataStore var = manager.metadataStore;
metadataStore.getEntityType palancaType = var ("Toggle");
palancaType.createEntity newPalanca = var ();
manager.addEntity (newPalanca);
//Here: newPalanca.FechaInicio () has the value in this format: 1355313343214
//Expected Date object here
newPalanca return;
};
After all, my real question is: What format should I use to assign new values to date type fields?
Edit:
After doing some tests, I noticed that if I assign a Date object to the property, everything seems fine until we got to this line:
saveBundleStringified var = JSON.stringify (saveBundle);
saveBundle content is:
FechaInicio: Thu Dec 20 2012 00:00:00 GMT+0100 (Hora estándar romance)
and the saveBundleStringified:
"FechaInicio": "2012-12-19T23:00:00.000Z" <- I guess this is utc format
What finally is stored in the database is: 2012-12-19 23:00:00.0000000
When the result of the call to SaveChanges are returned , they are merged with the entities in cache at the function updateEntity which does this check: if (!core.isDate(val)) that returns false.
As a consequence it is created a new Date object with the wrong date:
function fastDateParse(y, m, d, h, i, s, ms){ //2012 12 19 23 00 00 ""
return new Date(y, m - 1, d, h || 0, i || 0, s || 0, ms || 0);
}
Correct me if I'm wrong, but I think that's the problem.
Sorry for taking so long...
There were bugs with Breeze's DateTime timezone serialization and the default DateTime values used for newly constructed entities with non-nullable date fields. These are fixed as of v 0.77.2. Please confirm if this set of fixes works for you.
And thanks for finding these.
And to answer your question, all date properties on your object should be set to javascript Dates. Breeze should handle all of the serialization issues properly.
Dates always scare me. My immediate instinct is that the browser and server are not on the same TimeZone; how that could be I don't know. In any case, it's bound to happen and I recall all kinds of fundamental problems with coordinating client and server on datetime. I think the usual recommendation has always been to keep everything in UTC and adjust what you display to the user in local time.
I rather doubt this is a helpful answer. I'm not sure what part Breeze should play in resolving this. Would welcome a suggestion that we can circulate and build consensus around.
Also can you clarify this statement:
When the result of the call to SaveChanges are returned , they are merged with the entities in cache at the function updateEntity which does this check: if (!core.isDate(val)) that returns false. As a consequence it is created a new Date object with the wrong date
What do you mean by "the wrong date"? And are you saying that Breeze thinks the incoming date value is in an invalid format (as opposed to being a date other than the one you expected)?
Yes, #Sascha, Breeze is using the Web Api standard for JSON formatting (Json.Net) and it is set for ISO8601 format as opposed to the wacky Microsoft format (which escapes me as I write this).
Breeze/Web Api seem to need the dates in some special format (ISO8601). Any other format did not work for me. moment.js solved the problem for me with setting and reading. Formatting is also nicely done if you use Knockout to display the date with a special binding.
entity.someDate(moment().utc().toDate()) // example
and it works.
You could also use this:
Date.prototype.setISO8601 = function(string) {
var regexp = "([0-9]{4})(-([0-9]{2})(-([0-9]{2})" +
"(T([0-9]{2}):([0-9]{2})(:([0-9]{2})(\.([0-9]+))?)?" +
"(Z|(([-+])([0-9]{2}):([0-9]{2})))?)?)?)?";
var d = string.match(new RegExp(regexp));
var offset = 0;
var date = new Date(d[1], 0, 1);
if (d[3]) {
date.setMonth(d[3] - 1);
}
if (d[5]) {
date.setDate(d[5]);
}
if (d[7]) {
date.setHours(d[7]);
}
if (d[8]) {
date.setMinutes(d[8]);
}
if (d[10]) {
date.setSeconds(d[10]);
}
if (d[12]) {
date.setMilliseconds(Number("0." + d[12]) * 1000);
}
if (d[14]) {
offset = (Number(d[16]) * 60) + Number(d[17]);
offset *= ((d[15] == '-') ? 1 : -1);
}
offset -= date.getTimezoneOffset();
time = (Number(date) + (offset * 60 * 1000));
this.setTime(Number(time));
};
I have an h:inputText field which I use to enter a date. I am using the f:convertDateTime but I get errors.
Here is the situation:
<h:inputText value="#{listModel.creationDate}" valueChangeListener="#{listController.filterFieldChanged}">
<f:convertDateTime type="date" pattern="yyyy-MM-dd"/>
</h:inputText>
If I enter "2011-11-23" I get the following error:
"...[exec] sourceId=j_idt3[severity=(ERROR 2), summary=(Conversion Error setting value 'Wed Nov 23 01:00:00 CET 2011' for 'null Converter'. ), detail=(Conversion Error setting value 'Wed Nov 23 01:00:00 CET 2011' for 'null Converter'. )]|#]" (besides, where does 01:00:00 come from??)
If I remove the type="date" and leave only pattern="yyyy-MM-dd" and enter the same date, I get the same error.
If I remove the pattern and leave only type="date" and enter the same date, I get the following error:
"[exec] sourceId=searchForm:j_idt72[severity=(ERROR 2), summary=(searchForm:j_idt72: '2011-11-23' could not be understood as a date.), detail=(searchForm:j_idt72: '2011-11-23' could not be understood as a date. Example: 23.11.2011 )]|#]"
I am a little confused. If I define the pattern yyyy-MM-dd why "2011-11-23" isn't accepted?
Info added:
value="#{listModel.creationDate}"
public Date getCreationDate()
{
return creationDate;
}
This is the getter for creationDate in the class ListModel. (it is a java.Util.Date)
valueChangeListener="#{listController.filterFieldChanged}"
public void filterFieldChanged( ValueChangeEvent event )
{
// Note: value change events are handled in the PROCESS_VALIDATIONS
// phase by default. The problem is that the model values are not
// updated until later, so any changes we make here would normally be
// overwritten.
// By requeueing the event and targeting it to the UPDATE_MODEL_VALUES
// phase we can make the model changes without them being overwritten.
if ( event.getPhaseId().equals( PhaseId.ANY_PHASE ) )
{
event.setPhaseId( PhaseId.UPDATE_MODEL_VALUES );
event.queue();
}
else
{
// reset the paging any time a filter field was changed
listModel.setFirstResult( 0 );
}
}
I hope this is useful...
I'm trying to update an object, and getting:
SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.
There are two fields in the object that are DateTime objects, and they're set with:
obj.created_date = DateTime.Now;
obj.modified_date = DateTime.Now;
Except that everything looks reasonable when I view the object:
>? obj.created_date
{1/13/2010 4:02:47 PM}
Date: {1/13/2010 12:00:00 AM}
Day: 13
DayOfWeek: Wednesday
DayOfYear: 13
Hour: 16
Kind: Unspecified
Millisecond: 817
Minute: 2
Month: 1
Second: 47
Ticks: 633989953678170000
TimeOfDay: {16:02:47.8170000}
Year: 2010
>? obj.modified_date
{1/19/2010 12:20:50 PM}
Date: {1/19/2010 12:00:00 AM}
Day: 19
DayOfWeek: Tuesday
DayOfYear: 19
Hour: 12
Kind: Local
Millisecond: 333
Minute: 20
Month: 1
Second: 50
Ticks: 633995004503331818
TimeOfDay: {12:20:50.3331818}
Year: 2010
Any idea what's going on? Even reading the fields from the database, then trying to save them back without changes, causes the error. Other classes have no problems, and I can't see any differences that would account for this error.
I've added
<globalization culture="en-US" />
to my web.config, with no changes.
These problems are on my local dev
OK, here's what was happening. marc_s had the right idea.
There's was binder handling the updates:
TryUpdateModel(editItem, new string[] { "LookupTable", "TextField1", "TextField2" });
I removed the "LookupTable" from the call to TryUpdateModel, and instead handle the value in the binder with:
var fkid = Convert.ToInt32(controllerContext.HttpContext.Request.Form["LookupTable.ID"]);
EntityKey ek = new EntityKey("entities.LookupTable", "ID", fkid);
obj.LookupTableReference.EntityKey = ek;
Apparently, the EF was trying to update the LookupTable value for some reason.