Is there Java/SSJS equivalent of #AttachmentModifiedTimes? - xpages

I want to show list of attachments and FileDownload control is not an option (need custom actions for every file).
To get name and size of attachments there are properties of EmbeddedObject. AFAIK, to get modified time of attachment there is only one option: to use pure #Formula, either via session.evaluate or view containing column with #AttachmentModifiedTimes.
Is there a way (Java/SSJS) to get attachment's modified (and created) time without native #Formulas? That means date stored with file shown in document properties for $FILE item.

You can add a Repeat Control to the page and bind that to the attachments (stored in a rich text field) using document1.getAttachmentList("rt_field_name"). Every item in that list is an object of class
com.ibm.xsp.model.domino.wrapped.DominoDocument$AttachmentValueHolder
That class has a getLastModified() method that returns the last modified time as a Double.
A couldn't find a reference on the web showing the full API, but if you use the API Inspector in the XPage Debug Toolbar (sorry for the shameless plug...) you can view all properties and methods using:
getComponent( 'id_of_repeat_control' ).getDataModel().getRowData()
UPDATE
Found the API here,

I am not 100% sure what you want to achieve.
In general you can use #AttachmentModifiedTimes() - as well as #AttachmentNames() - as SSJS.

Related

Repeated fileDownload control each displays the same list of files?

I'm creating a student assignment submission application using xpages (8.5.3 FP3 UP1). The details are:
Student can do any number of submission. For each submission, a unique SubmitID will be created. For now,
a. The Form (Submit) - 2 fields only (SubmitID, SoftCopy-RTF type)
b. The View (Submit) - 2 column only (SubmitID, AttachmentNames)
c. Examples of SubmitID are: submit1, submit2
For each submission, student must select what course/subject that submission is for (eg: Maths, Physics etc). Therefore I've already created another form for the teacher to create the list of subject
a. The Form (Subject) - 1 field only (SubjectName)
b. The View (Subject) - 1 column only (SubjectName)
c. Say for now 2 subject has been created - Maths & Physics
I've created 2 xpage:
a. Submit.xsp - to create new submission (using form - Submit)
b. SubmitView.xsp - to display the list of submission (using view - Submit)
For Submit.xsp, here's where my problem begins:
a. The controls in here are as follows: SubmitID EditBox, Repeat Control(inside is a CheckBox, a fileUpload, and a fileDownload)
b. The repeat is based on the list of subject available. The CheckBox title will be each of the SubjectName. In the OnChange event of the fileUpload control, each time after a file is browsed, the checkbox will get checked and this worked.
c. The fileUpload should only update the accompanying fileDownload but instead the attachment that I just uploaded is reflected to every other fileDownload control. I'm doing full refresh on the fileUpload OnChange because that's the only way for the fileDownload to be updated. What is wrong here and what should I do to get the result that I wanted? Saving the document and opening it later in both read-only or edit mode is fine although each subject still display the same list of uploaded files. Both fileUpload and fileDownload are binded to the SoftCopy field.
Unless I'm not correctly interpreting your description, you're binding multiple upload / download controls to the same item ("SoftCopy"). Because these controls are always bound to an item, not to each other, a download control will show any attachments stored within the source item, regardless of how they got there. To limit display of attachments in a download control to those sent via a specific upload control, they must be stored in an item unique to that pair.
For example, if each pair were bound to a subject-specific item, such as "SoftCopy_Maths" or "SoftCopy_Physics", then each download would only display attachments stored within that specific item. You don't know what subjects will be defined, so you can't define these fields on the form, but that's okay... you don't need to. NSF has no schema, so a field need not be defined on a form for a control to be bound to it; the item will be created when the document is saved, even if the form does not define it. Strictly speaking, even the form itself need not exist.
We typically bind controls to items using dot syntax, e.g. #{currentDocument.SoftCopy}, but array syntax is equally valid, e.g. #{currentDocument["SoftCopy"]}. So if you wrap these controls in something that establishes the dynamic item name as a variable or property, you can use array syntax to target that dynamic item. Two of the best ways to do this are data contexts and custom controls.
For instance, you could surround the contents of the repeat in a panel, and define a panel-specific dataContext that associates the variable attachmentItemName with the concatenation of the item name prefix and the specific subject. Your upload and download controls can then be bound to #{currentDocument[attachmentItemName]}.
Alternatively, you can move the same content to a custom control that accepts the data source and item name as properties, in which case your value binding might look like #{compositeData.dataSource[compositeData.attachmentItemName]}.
Apart from very minor differences in runtime performance, either approach is equally valid.

How do I manage Attachments (View / Delete)

I am able to add a file upload control to my page and add attachments. But how do I manage them? View , delete?
I added a computed field to my xpage and make the attachments field the source and set the field as HTML. I get a bunch of entries like (See attached file: abc.pdf). But that does not seem to do what I want.
Is there an easy way to manage these attached files?
Bind a file download control to the same data the upload control is bound to. One of the attributes this component supports is a boolean for whether to allow deletion. You can also choose which attributes of each file it displays (MIME type, size, etc.).
What is wrong with having an repeat control repeat over the filenames and generate links directly to those files where on the links there are event handlers which do a remove or view ?

How to add a property an ASP.Net user control or web page and have that property read by Microsoft coded-ui testing? (CUIT)

I am using Microsoft coded-ui testing (CUIT) in VS 2010 Ultimate to test an ASP.Net 4.0 site.
I have the source code to the ASP.Net site, so I can modify it as needed.
I've got record/playback working.
I can write simple assert statements in the test methods to check properties of the UITestControl descendents (HTML links, tables, etc.) and compare them to expected values.
I want to add properties to user controls (ASCX's) and pages in my site, to pass back useful values to the testing code.
For example, I have a user control that implements a menu which displays different sets of menu items depending on the role of the current user.
Rather than having the test script click at the various menu items to check whether or not they're present, I want to add a property to the user control. This property will return info to the caller, listing the menus and menu items present.
I've found info on the Net on how to do this in WinForms, but this code relies on accessability, which I believe is only useful for CUIT with WinForms. Likewise, I've found info on how to do it with WPF/SL.
The answer may be related to getting the UITestControl.NativeElement property, then calling a method that overrides GetProperty(), but I haven't been able to get this approach to work.
Can anyone provide a short code sample showing how to add a property to an ASCX or ASPX page, where that property can be written in C# code-behind, and read by Microsoft Coded UI Testing (CUIT) code?
Thanks!
Adam Leffert
http://www.leffert.com
I haven't found an answer to this question, but I have written some code to solve the underlying problem.
I realized that adding properties to user controls would keep the validation data together with the control under test, but only for the case where the section of UI was implemented as a user control.
There are at least two other cases I need to cover:
1) Third-party controls added to the page, for example ASPxGridView, ASPxTreeView, etc.
2) Items that are not visible in the UI, for example the user profile data for the current user.
When you're running CUIT validation code with a Web app, the data you have available is DOM data, i.e. a tree that represents the contents of the Document Object Model of the contents of the browser window. There is no Request object, .Net Page object, etc. This DOM data is accessible through the UIMap object.
I don't want to wrap the third-party controls in user controls, because doing so would disturb the application under test, causing me to re-write the application code that touches properties and events of the grid, tree view, etc. Too intrusive for testing code.
So I created a code interface (ITestable) that contains a dictionary of string values, and a list of ITestable children.
In the LoadComplete event handler of the master page, I create an ITestable for the master page and fill the list with child ITestable objects for the child page, which can themselves contain lists of children.
I serialize this object into JSON, then store it in a hidden field on the master page.
I added the hidden field to the UIMap.
The test validation code deserializes the ITestable, then looks through it for values that need validation.
The controls create their own ITestable objects, so they can easily fill the objects with values that may be needed for validation, rather than forcing the test code to manipulate the UI trying to read validation values.
For example, a tree view could return its contents without the testing code having to click on each node and try to read the value displayed there. Additional properties (visible, enabled, etc.) can be stored in the values dictionary for each ITestable object.
CUIT has some very powerful features. I would very much appreciate it if Microsoft would document some best practices for solving these non-trivial validation problems. I've read through the Microsoft documentation but haven't found much on this topic for Web apps.

Word and Custom Content Types

I have defined a new content type (document) for sharepoint. The problem I have is that word automatically comes up with window allowing updating of these properties (for example effective date) that is not validated and I don't want it to show when the user is uploading changes (I fill in some of these fields on the updated method in the eventreceiver class). Is it possible to disable this or at least customize the word behavior?
You can create your own Document Information Panels: http://msdn.microsoft.com/en-us/library/bb684925.aspx.
Another alternative might be to set the ShowInNewForm/ShowInEditForm properties of the SPField. But im not sure if Word uses them.

Custom list form using sharepoint object model VS 2008

Is there a way to handle the DropDownSelectedIndexChanged for list item new form.
Let say I have a custom list named Temp having Title, Products (which is a DropDownList) and Color Shade (which is a TextBox).
When I create a list item I want to select a product from DropDownList and on the selected index changed I want to write the
business logic such as fetching the row from Color Shade list and bind the data to TextBox of Color Shade. Now I can say ok so that
a list item will be created. Is it possible using VS 2008 sharepoint object model.
you could add a custom control to your masterpage which resursively traverses your control tree (start from this.Page) to find your dropdown and attaches the event handler (which itself is defined in your custom control). Also set the AutoPostBack property to true on the dropdown once you found it.
In terms of getting a reference do your textbox within your eventhandler, you could also apply the same approach of traversing the control tree.
note, you need to ensure that event handler is attached before eventhandlers are run.
Jaap
I am not sure if I understand what you mean.
An alternative approach, and probably less work, would be to use javascript (I would recommend using the jQuery library) to automatically populate your textbox when the selection of the dropdown changes. Everything would be done clientside.
Jaap
There are some third party components that do this sort of thing as custom column types, but if you're developing from scratch you'll probably find it a lot easier doing a custom form. If you do a fully custom version of newform.aspx, you'll still be using the standard new item menu.
If you try to modify the standard controls you'll run into issues like security errors if the submitted value wasn't in the original list.
If you don't want to write your own saving code, hiding the standard new form with css and modifying the values with javascript from your custom control can work quite well.

Resources