How to find out if an XPages view(Panel) is sorted by a viewColumnHeader sort toggle switch? - xpages

I'm displaying a view using a viewPanel. The view contains some columns which are enabled to be sorted in both directions, which is working fine.
Now I'd need to find out if the view has been resorted by the user by being clicked on the "Sort Toggle" in the viewColumnHeader.
Is there a property or a method which I can access programmatically to find this out?
Or is there an event in the viewPanel I could intercept or listen to?
Update:
I found that the class UIViewColumnHeader (which is extended by XspViewColumnHeader) has some static properties describing the icons (see here) - could I check for them? And if yes, how?

The sort column should be defined on the dominoView datasource in the sortColumn property, whose Java class is com.ibm.xsp.model.domino.DominoViewData. That can be accessed by calling getData() on the ViewPanel
So you should be able to use getComponent("myViewPanel").getData().getSortColumn() in SSJS. By default I suspect it will be blank.

Ok, with the help of those both sites, I solved resp. worked around my problem:
First, there was Naveen's solution how to Getting ViewPanel Headers programmatically
Second, Mark Leusink's article about the order of events in XPages.
This led me to following code:
<xp:this.beforeRenderResponse><![CDATA[#{javascript:
var viewPnl:com.ibm.xsp.component.xp.XspViewPanel = getComponent("viewPanel1");
var list:java.util.List = viewPnl.getChildren();
var replaceRespCol = false;
for (var i = 0 ; i < list.size(); i++) {
var viewCol:com.ibm.xsp.component.xp.XspViewColumn = list.get(i);
var viewHdr:com.ibm.xsp.component.xp.XspViewColumnHeader = viewCol.getHeader();
if (#RightBack(viewHdr.getSortIcon(), "/") != "sort_none.gif") {
replaceRespCol = true;
}
}
if (getSearchKey() != "") {
getComponent("viewColumn1").setRendered(false);
getComponent("viewColumn1b").setRendered(true);
} else if (replaceRespCol == true) {
getComponent("viewColumn1").setRendered(false);
getComponent("viewColumn1b").setRendered(true);
} else {
getComponent("viewColumn1").setRendered(true);
getComponent("viewColumn1b").setRendered(false);
}}]]></xp:this.beforeRenderResponse>
which enables me now to dynamically show a categorized column (viewColumn1)
- if no filter/search key is entered and
- no re-sort via the headers is done.
Otherwise, a flat column (viewColumn1b) is shown. HTH

Related

Select UI Element by filtering properties in coded ui

I have a web application. And I am using coded ui to write automated tests to test the application.
I have a dropdown with a text box. Which on entering values in the textbox, the values in the dropdown gets filtered based on the text entered.
If I type inside textbox like 'Admin', I will get below options like this:
And I need to capture the two options displayed.
But using IE Developer tool (F12), I am not able to capture the filtered options, because the options that are displayed do not have any unique property (like this below). And the options that are NOT displayed have a class="hidden" property
Any way to capture the elements that are displayed by applying some kind of filter like 'Select ui elements whose class != hidden'
Thanks in advance!!
HI please try below code will it works for you or not.By traversing all those controls that have class ="hidden"
WpfWindow mainWindow = new WpfWindow();
mainWindow.SearchProperties.Add(HtmlControl.PropertyNames.ClassName, "hidden");
UITestControlCollection collection = mainWindow.FindMatchingControls();
foreach (UITestControl links in collection)
{
HtmlHyperlink mylink = (HtmlHyperlink)links;
Console.WriteLine(mylink.InnerText);
}
I'm not sure there is a way to do it by search properties, but there are other approaches.
One way would be to brute force difference the collections. Find all the list items, then find the hidden ones and do a difference.
HtmlControl listControl = /* find the UL somehow */
HtmlControl listItemsSearch = new HtmlControl(listControl);
listItemsSearch.SearchProperties.Add(HtmlControl.PropertyNames.TagName, "li");
HtmlControl hiddenListItemsSearch = new HtmlControl(listControl);
hiddenListItemsSearch.SearchProperties.Add(HtmlControl.PropertyNames.TagName, "li");
hiddenListItemsSearch.SearchProperties.Add(HtmlControl.PropertyNames.ClassName, "hidden");
var listItems = listItemsSearch.FindMatchingControls().Except(hiddenListItemsSearch.FindMatchingControls());
You will only be able to iterate this collection one time so if you need to iterate multiple times, create a function that returns this search.
var listItemsFunc = () => listItemsSearch.FindMatchingControls().Except(hiddenListItemsSearch.FindMatchingControls());
foreach(var listItem in listItemsFunc()){
// iterate 1
}
foreach(var listItem in listItemsFunc()){
// iterate 2
}
The other way I would consider doing it would be to filter based on the controls which have a clickable point and take up space on the screen (ie, not hidden).
listItemsSearch.FindMatchingControls().Where(x => {
try { x.GetClickablePoint(); return x.Width > 0 && x.Height > 0; } catch { return false; }
});

Is there a way to change the text of checked/unchecked MCheckBox states?

How would I go about changing the default MCheckBox state text (currently I/0) to, for example, YES/NO or ON/OFF?
Mr. Daniel Kurka is the author for all the widget classes in MGWT. If the look & feel is not
fulfilling our requirement, We can edit those classes and rewrite them according to our requirement.Because they are open source. I done this on many classes like CellList,FormListEntry and MCheckBox. code for ON/OFF instead of I/O
public MyOwnCheckBox(CheckBoxCss css) {
this.css = css;
css.ensureInjected();
setElement(DOM.createDiv());
addStyleName(css.checkBox());
onDiv = DOM.createDiv();
onDiv.setClassName(css.on());
onDiv.setInnerText("ON");
getElement().appendChild(onDiv);
middleDiv = DOM.createDiv();
middleDiv.setClassName(css.middle());
Element middleContent = DOM.createDiv();
middleContent.setClassName(css.content());
middleDiv.appendChild(middleContent);
getElement().appendChild(middleDiv);
offDiv = DOM.createDiv();
offDiv.setClassName(css.off());
offDiv.setInnerText("OFF");
getElement().appendChild(offDiv);
addTouchHandler(new TouchHandlerImplementation());
setValue(true, false);
}
Write a new class like MyOwnCheckBox.just copy the code in MCheckBox and paste in your class MyOwnCheckBox, find and replace the MCheckBox with MyOwnCheckBox in the code(change constructor's name). do the following changes.
onDiv.setInnerText("ON");
offDiv.setInnerText("OFF");
and finally create object to MyOwnCheckBox rather MCheckBox, it'll shows MCheckBox with ON/OFF.
Right now there is no way to do that, but there is no real reasons that checkbox does not implement HasText other than we might need to update the css so that big text will not break the layout.
If you think mgwt should implement this go and vote for this issue: http://code.google.com/p/mgwt/issues/detail?id=171
Well, an easy way to accomplish the same thing, without creating a new class that mimics MCheckBox, is to do something like the code below:
CheckBoxCss css = MGWTStyle.getTheme().getMGWTClientBundle().getCheckBoxCss();
String offClass = css.off();
String onClass = css.on();
NodeList<Node> checkBoxElems;
mIsSingleSkuBox = new MCheckBox(css);
checkBoxElems = mIsSingleSkuBox.getElement().getChildNodes();
for( int i = 0; i < checkBoxElems.getLength(); i++ )
{
Element openElem = (Element) checkBoxElems.getItem(i);
String className = openElem.getClassName();
if( className.equals( offClass))
{
openElem.setInnerText("No" );
}
else if( className.equals( onClass))
{
openElem.setInnerText("Yes" );
}
}
It will probably have space problems with anything longer than 3 characters, but it works consistently with "Yes" and "No" for me.

SharePoint 2010 BaseFieldControl Duplicates first item in list when in DisplayMode

I have come across a problem when using the BaseFieldControl that is driving me to distraction.
Essentinally I am trying to convert a list into a HTML table using the BaseFieldControl to render the fields.
When my table renders it writes out the correct number of lines BUT the data in each line is always the same as the first item in the list.
When I change the ControlMode property from SPControlMode.Display to SPControlMode.Edit the list renders correctly ( apart from being in Edit mode )
When my code running with ControlMode set to SPControlMode.Display I can actually get at the correct value in the BaseFieldControl.ItemFieldValue property but the wretched BaseFieldControl still insists on rendering the first item in the list!
I've also installed the web part on a SharePoint foundation and SharePoint 2010 server and I get the same results!
Finally I've googled around and found other peoples examples. Unfortunately when I try other dev's code ( unmodified ) I get exactly the same results!
This is what I'm doing. Any suggestions would be really appreciated!
foreach (string f in list.DefaultView.ViewFields)
{
TableCell c = new TableCell();
var i = item[f];
if (i != null)
{
SPField spf = item.Fields.GetField(f);
BaseFieldControl bfc = spf.FieldRenderingControl;
bfc.ControlMode = SPControlMode.Display;
bfc.Value = bfc.ItemFieldValue;
bfc.ID = Guid.NewGuid().ToString();
bfc.FieldName = spf.Title;
bfc.ListId = list.ID;
bfc.ItemId = item.ID;
SPContext context = SPContext.GetContext(this.Context, item.ID, list.ID, SPContext.Current.Web);
bfc.ItemContext = context;
bfc.RenderContext = context;
bfc.EnableViewState = true;
bfc.Visible = true;
c.Controls.Add(bfc);
}
else
{
c.Text = "NULL";
}
r.Cells.Add(c);
}
I finally fixed it. Turns out to be a problem with the SPWeb object. I had grabbed it from SPContext and passed it through as a reference to my method.
When I stopped doing that but instead created it within the method ( and created it once per item in the list ) it all worked fine.
Very strange.

Sharepoint 2010 - make Title, Description and Keyword fields as required fields in Picture Library using server-object-model

I'm creating a Sharepoint feature, this feature has an event receiver associated to it. In the event receiver, I'm creating a Document Library and Picture Library using server-side object model. I'm also adding new custom columns (around 80) to these newly created document and picture library. Now I want to modify the properties of the Description, Keywords and Title fields that are by default created along with the picture library. I want to make these fields as Required fields. How do I do this? I tried to set SPList.AllowContentTypes = true and try to change the attributes of these fields, but it doesn't work (neither gives an error nor makes these required fields). I also tried to access the content types and try to change the attributes using SPContentType.FieldsLinks["Column_name"].Required and SPContentType.Fields["Column_name"].Required but it gives me an error. Does anyone have any other suggestions?
Here is the answer....
SPContentType ct = mypiclib.ContentTypes["Picture"];
SPFieldLinks titleLink = ct.FieldLinks["Title"];
SPFieldLinks descLink = ct.FieldLinks["comments"]; //internal name of Description
SPFieldLinks keywords = ct.FieldLinks["keywords"];
titlelink.Required = true;
descLink.Required = true;
keywords.Required = true;
ct.Update();
can you tell us the error you got when trying to use the fieldlinks? Because this should work... I have done it like this:
SPContentType ct = web.Lists["*ListName*"].ContentTypes["*ContentTypeName*"];
SPFieldLinkCollection flinks = ct.FieldLinks;
flinks["*ColumnName*"].Required = true;
ct.update();
This should do the trick:
SPWeb yourWeb = ... //assign your web
SPList yourPictureLibrary = ... //assign your picture library
web.AllowUnsafeUpdates = true;
yourPictureLibrary.Fields[SPBuiltInFieldId.Title].Required = true;
yourPictureLibrary.Fields[SPBuiltInFieldId.Description].Required = true;
yourPictureLibrary.Fields[SPBuiltInFieldId.Keywords].Required = true;
yourPictureLibrary.Update();
SPAllowContentTypes isn't settable. You might try setting ContentTypesEnabled instead.
I don't have a 2010 box to test against, but if SPAllowContentTypes returns false I think you're looking at modifying the definition of your picture library in the 14 hive (TEMPLATE\FEATURES\PictureLibrary\PicLib) to get what you're after. Tread lightly there.

How can I change the width of a column in a list view is SharePoint?

I have SharePoint 2007 and I have a list view that has a text field that, when shown with quite a few other fields, is only about 1 word narrow.
Is there a way to expand that column without access to css or other web programming languages?
If you can't use CSS, JavaScript, SharePoint Designer, or deploy any C# code to the server.. then you can't change the width of the column.
Try adding a ContentEditor Web Part with the CSS/JavaScript that sets the look of the column. You don't need C# or Designer.
I did something similar with a search page where I needed a JavaScript function to be triggered so I added a CEWP to the page with the following code (see below).
You could change this to look for the id of the column you want to modify. Just remember that ID's of controls in SharePoint are generated during the page render so you won't necessarily know the exact ID. That is why this code looks for an anchor with an ID that ends with '_PSB_Show', instead of looking for the exact ID.
<script type="text/javascript">
var anchors = document.getElementsByTagName("a");
var anchor;
var j;
// Iterate through all anchors on the page and find the one with ID ending in _PSB_Show
for (j = 0; j < anchors.length; j++)
{
if (anchors[j].id.match(/\_PSB_Show$/) != null)
{
anchor = anchors[j];
break;
}
}
// If the anchor is found and the click is supported in the current browser
// Perform a click after 100 ms
if ((anchor != null) && (anchor.click != null))
{
setTimeout("anchor.click();", 100);
}
</script>

Resources