MY code is:
BeanItemContainer<TimeCardBean> results = new BeanItemContainer<TimeCardBean> (TimeCardBean.class);
for (TimeCardBean bean : beans) {
results.addBean(bean);
}
table.setContainerDataSource(results);
table.addGeneratedColumn("function",new ColumnGenerator(){
public Object generateCell(final Table source, final Object itemId, final Object columnId) {
Byte timecardSeq=
(Byte)source.addItem(itemId).getItemProperty("timeCardSeq").getValue();
Button btnChange= new Button("Change", new ClickListener() {
public void buttonClick(final ClickEvent event) {
TimeCardEditDialog editDialog = new TimeCardEditDialog(viewService);
editDialog.init(timecardSeq);
}
});
return btnChange;
}
I get the following error:
com.vaadin.ui.Table$CacheUpdateException: Error during Table cache update. Additional causes not shown.
at com.vaadin.ui.Table.maybeThrowCacheUpdateExceptions(Table.java:1716)
at com.vaadin.ui.Table.refreshRenderedCells(Table.java:1705)
at com.vaadin.ui.Table.refreshRowCache(Table.java:2638)
at com.vaadin.ui.Table.addGeneratedColumn(Table.java:4404)
Hope you got when I want to express and can anyone tell me about to do this?
Related
I currently have a problem with the datareader when creating Microsoft.SqlServer.Management.Smo.Table asynchronously. Note: I derived my SmoTable from TableView and IDisposable.
private async Task Generate()
{
await Task.Run(()=>
{
MSSMSDatabase db = CreateDB(txtDBname.Text);
List<string> tableNames = GetTableNameList();
for(string tableName in tableNames)
{
using(SmoTable tbl = new Table(db, tableName)) // <=== after a few loops, the error occurs within here.
{
foreach(var col in columnList)
{
tbl.AddColumns(col);
}
tbl.Create();
}
}
});
}
Microsoft.SqlServer.Management.Smo.FailedOperationException: InvalidOperationException: There is already an open DataReader associated with this Connection which must be closed first.
I tried implementing IDisposable to my SmoTable class that I derived from the TableView class but still have the same error.
Thanks in advance.
I did a trial and error and found out that you need to create a new connection for each table creation to create a separate datareader for it. So, if you include the instantiation of Server in the foreach loop it will create a new connection and hence a new datareader.
for(string tableName in tableNames)
{
using(SmoTable tbl = new Table(db, tableName)) // <=== after a few loops, the error occurs within here.
{
foreach(var col in columnList)
{
_server = GetSQLServer(); // <=== this is basically Server server = new Server(); return server; kind of method.
db = _server.Databases[_databaseName];
tbl.AddColumns(col);
}
tbl.Create();
}
}
This is a know error when using C# expressions in windows workflow. The article at https://learn.microsoft.com/en-us/dotnet/framework/windows-workflow-foundation/csharp-expressions#CodeWorkflows explains the reason and how to fix it. It all works fine for me in standard workflows, but as soon as I add a custom NativeActivity to the WF, I get that same error again !
Below the code of how I load the XAML workflow and the simple NativeActivity (which is the ONLY activity in the test workflow and inside that activity is a simple assign expression).
Loading and invoking WF via XAML:
`XamlXmlReaderSettings settings = new XamlXmlReaderSettings()
{
LocalAssembly = GetContextAssembly()
};
XamlReader reader = reader = ActivityXamlServices.CreateReader(new XamlXmlReader(fileURL, settings));
ActivityXamlServicesSettings serviceSettings = new ActivityXamlServicesSettings
{
CompileExpressions = true
};
var activity = ActivityXamlServices.Load(reader, serviceSettings);
WorkflowInvoker.Invoke(activity);`
Doing it in code throws same Exception:
Variable<string> foo = new Variable<string>
{
Name = "Foo"
};
Activity activity = new Sequence
{
Variables = { foo },
Activities =
{
new TimeExecuteUntilAborted
{
Activities =
{
new Assign<string>
{
To = new CSharpReference<string>("Foo"),
Value = new CSharpValue<string>("new Random().Next(1, 101).ToString()")
}
}
}
}
};
CompileExpressions(activity);//the method from the article mentioned above
WorkflowInvoker.Invoke(activity);
The Native Activity:
[Designer("System.Activities.Core.Presentation.SequenceDesigner, System.Activities.Core.Presentation")]
public sealed class TimeExecuteUntilAborted : NativeActivity
{
private Sequence innerSequence = new Sequence();
[Browsable(false)]
public Collection<Activity> Activities
{
get
{
return innerSequence.Activities;
}
}
[Browsable(false)]
public Collection<Variable> Variables
{
get
{
return innerSequence.Variables;
}
}
protected override void CacheMetadata(NativeActivityMetadata metadata)
{
metadata.AddImplementationChild(innerSequence);
}
protected override void Execute(NativeActivityContext context)
{
context.ScheduleActivity(innerSequence);
}
}
Your TimeExecutedUntilAborted class seems to be the culprit. I was able to swap in one of my own template NativeActivities instead and your workflow executed fine with the expressions. I'm guessing that your class is causing an issue in the compiler method when it parses your code. I used this doc as an example for my NativeActivity: https://msdn.microsoft.com/en-us/library/system.activities.nativeactivity(v=vs.110).aspx.
Sizzle Finger's answer is no solution but pointed me into the right direction to simply check what is different. It came out that the simple call to the base class method was missing:
protected override void CacheMetadata(NativeActivityMetadata metadata)
{
base.CacheMetadata(metadata); // !! This needs to be added
metadata.AddImplementationChild(innerSequence);
}
I'm a newbie in ASP.NET and I'm stuck at populating a List when web page load.
I have a class that, when instantiated, will add some objects into a list. This class has a method to add objects to a list (I made this a method because I need to reuse it later). This is the code for this class:
public class Task()
{
private List<ObjectA> objList;
....// other variables and properties
public Task()
{
objList = new List<ObjectA>();
// first add 2 obj into the list
AddObjToList(objList);
AddObjToList(objList);
}
public void AddObjToList(List<ObjectA> objList)
{
bool exist = false;
ObjectA obj = new ObjectA(); // each obj has unique properties
foreach(var o in objList)
{
if(o.objName == obj.objName)
{
exist = true;
break;
}
}
if(!exist)
{
objList.add(obj);
}
}
}
I have a web page that, when loaded, I want it to populate the objList with 2 starting objects. This is my code behind for the web page:
protected void Page_Load(object sender, EventArgs e)
{
Task newTask = new Task();
// the following label control is to check the number of
// elements in the List
lblMSG.Text = newTask.getObjList.Count.ToString();
}
The problem is, when I run in debug mode, the list is populated with 2 objects just as I wanted. But when not in debug mode, when the page loaded, the label showed that the list has only 1 object. I tried to call the new Task() with isPostBack but the result is the same. What did I do wrong? What could I do to make it work?
I am Using Vaadin in my application to display the REPORTS on PAGED TABLE from date to to date.
The code is working fine, when I click the submit button the data is not showing any where on vaadin ui table but, when I click the header row of that table then the data is showing.I need when the user entered from date to to date then after clicking the submit button the I need to display the reports on table instead of clicking the header row.Here I am top display the reports on the table I am using PAGED TABLE instead of normal Table.
I am using this Code for all reports due to this all reports are behaving likesame.
Pls help me here is the code is
Button executeReportButton = new Button("Submit");
executeReportButton.addListener(new Button.ClickListener() {
#Override
public void buttonClick(ClickEvent event) {
if ((Date) tatFromDate.getValue() != null
&& (Date) tatToDate.getValue() != null) {
runDBReport(reportTable, (Date) tatFromDate.getValue(),
(Date) tatToDate.getValue());
} else
showWarningNotification("Error loading check list report.",
"Date entered is not valid.");
}
});
private void runDBReport(PagedTable reportTable, Date fromDate, Date toDate) {
final PagedTable _reportTable = reportTable;
final Date _fromDate = fromDate;
final Date _toDate = toDate;
HibernateUtils.getCurrentSession().doWork(new Work() {
#Override
public void execute(Connection connection) throws SQLException {
String reportCall = "{ call RP_PROC_CHECKLIST_AUDIT(?, ?, ?) }";
CallableStatement stmt = null;
ResultSet rs = null;
try {
stmt = connection.prepareCall(reportCall);
// register the type of the out param - an Oracle specific
// type
stmt.registerOutParameter(3, OracleTypesHelper.INSTANCE
.getOracleCursorTypeSqlType());
// set the in param
stmt.setDate(1, new java.sql.Date(_fromDate.getTime()));
stmt.setDate(2, new java.sql.Date(_toDate.getTime()));
// execute and retrieve the result set
stmt.execute();
rs = (ResultSet) stmt.getObject(3);
// get the results
while (rs.next()) {
Object TATDataRowId = _reportTable.addItem();
_reportTable.getItem(TATDataRowId)
.getItemProperty("checklistid")
.setValue(rs.getString(1));
_reportTable.getItem(TATDataRowId)
.getItemProperty("checklistdescription")
.setValue(rs.getString(2));
// ... a trillion more
}
} catch (Exception e) {
logger.error(
"Error loading check list report. Exception: {}",
e.getMessage());
logger.debug("Error loading check list report.", e);
showWarningNotification(
"Error loading check list report. Please contact admin",
"Error message is : " + e.getMessage());
} finally {
rs.close();
stmt.close();
}
}
});
}
I think that your HibernateUtils.getCurrentSession().doWork(new Work().... is starting a background thread and, when the report is finished fills in the table.
For background threads updating the UI in vaadin, there a special rules on how to do it.
When you don't follow them, then the serverside changes are only visible on the next client->server interaction.
https://vaadin.com/book/vaadin7/-/page/advanced.push.html#advanced.push.running
Don't forget to also look at server push/polling, since the webbrowser must be notified for the new content
I'm implementing a DynamicItemStart button inside a Menu Controller. I'm loading the dynamic items for this button when Visual Studio starts. Everything is loaded correctly so the initialize method is called an I see all the new items in this Dynamic button. After the package is completely loaded I want to add more items to this Dynamic button, but since the package is already loaded the initialize method is not called again and I cannot see the new items in this Dynamic button. I only see the ones that were loaded when VS started.
Is there any way that I can force the update of this Dynamic button so it shows the new items?. I want to be able to update the VS UI after I added more items but outside the Initialize method.
The implementation I did is very similar to the one showed on this msdn example:
http://msdn.microsoft.com/en-us/library/bb166492.aspx
Does anyone know if an Update of the UI can be done by demand?
Any hints are greatly appreciated.
I finally got this working. The main thing is the implementation of a derived class of OleMenuCommand that implements a new constructor with a Predicate. This predicate is used to check if a new command is a match within the DynamicItemStart button.
public class DynamicItemMenuCommand : OleMenuCommand
{
private Predicate<int> matches;
public DynamicItemMenuCommand(CommandID rootId, Predicate<int> matches, EventHandler invokeHandler, EventHandler beforeQueryStatusHandler)
: base(invokeHandler, null, beforeQueryStatusHandler, rootId)
{
if (matches == null)
{
throw new ArgumentNullException("Matches predicate cannot be null.");
}
this.matches = matches;
}
public override bool DynamicItemMatch(int cmdId)
{
if (this.matches(cmdId))
{
this.MatchedCommandId = cmdId;
return true;
}
this.MatchedCommandId = 0;
return false;
}
}
The above class should be used when adding the commands on execution time. Here's the code that creates the commands
public class ListMenu
{
private int _baselistID = (int)PkgCmdIDList.cmdidMRUList;
private List<IVsDataExplorerConnection> _connectionsList;
public ListMenu(ref OleMenuCommandService mcs)
{
InitMRUMenu(ref mcs);
}
internal void InitMRUMenu(ref OleMenuCommandService mcs)
{
if (mcs != null)
{
//_baselistID has the guid value of the DynamicStartItem
CommandID dynamicItemRootId = new CommandID(GuidList.guidIDEToolbarCmdSet, _baselistID);
DynamicItemMenuCommand dynamicMenuCommand = new DynamicItemMenuCommand(dynamicItemRootId, isValidDynamicItem, OnInvokedDynamicItem, OnBeforeQueryStatusDynamicItem);
mcs.AddCommand(dynamicMenuCommand);
}
}
private bool IsValidDynamicItem(int commandId)
{
return ((commandId - _baselistID) < connectionsCount); // here is the place to put the criteria to add a new command to the dynamic button
}
private void OnInvokedDynamicItem(object sender, EventArgs args)
{
DynamicItemMenuCommand invokedCommand = (DynamicItemMenuCommand)sender;
if (null != invokedCommand)
{
.....
}
}
private void OnBeforeQueryStatusDynamicItem(object sender, EventArgs args)
{
DynamicItemMenuCommand matchedCommand = (DynamicItemMenuCommand)sender;
bool isRootItem = (matchedCommand.MatchedCommandId == 0);
matchedCommand.Enabled = true;
matchedCommand.Visible = true;
int indexForDisplay = (isRootItem ? 0 : (matchedCommand.MatchedCommandId - _baselistID));
matchedCommand.Text = "Text for the command";
matchedCommand.MatchedCommandId = 0;
}
}
I had to review a lot of documentation since it was not very clear how the commands can be added on execution time. So I hope this save some time whoever has to implement anything similar.
The missing piece for me was figuring out how to control the addition of new items.
It took me some time to figure out that the matches predicate (the IsValidDynamicItem method in the sample) controls how many items get added - as long as it returns true, the OnBeforeQueryStatusDynamicItem gets invoked and can set the details (Enabled/Visible/Checked/Text etc.) of the match to be added to the menu.