1

I have a simple document with 3 fields and 1 rich text field. I also have an xpage with 3 simple edit box controls and 1 rich text. The name of my NotesXSPDocument is document1.

Question 1: Can i get a vector with all the controls of the xsp document? for example, instead of using getComponent("fld1"), getComponent("fld2") ... etc, can i use something like getAllComponents() or document1.getControls()? These methods do not exist of course so i am asking if there is a way to do it. I know i can get all items of a document (not XSP) by calling document1.getDocument().getItems(). IS there anything similar for xsp?

Question2: Lets say we can get a vector as i described above. Then if i iterate through this vector to get each control's value, is there a method to check if it is rich text or simple text field?

mike_x_
  • 1,900
  • 3
  • 35
  • 69
  • I'm just wondering why you want to get all the components on an Xpage? What's the need/use case for that? I can see a rare need for getItems on a document but I don't see why you'd want all the components on an Xpage. – David Leedy Sep 02 '14 at 12:28
  • I have created a module that works like "auto save as draft" of gmail. So when i open a document to edit, i periodically check if there is any change in the fields. I have implemented it by getting the fields one by one but i want to make it more abstract and reusable. – mike_x_ Sep 02 '14 at 12:32
  • You might be better off checking for field differences client side, then triggering your server side save, especially since you want to "periodically" poll for changes. – Michael G. Smith Sep 02 '14 at 12:34
  • yes maybe i ll end up to client side but... I am also curious! :) – mike_x_ Sep 02 '14 at 12:36
  • To make it reusable you can just assign a class to all the fields that need to be checked. – Michael G. Smith Sep 02 '14 at 12:40

2 Answers2

4

Technically, yes, but not readily and this is one of those situations where there's likely a better way to approach whatever underlying problem it is you want to solve.

Nonetheless, if you're looking to get a list of inputs on the page, XspQuery is your friend: http://avatar.red-pill.mobi/tim/blog.nsf/d6plinks/TTRY-96R5ZT . With that, you could use "locateInputs" to get a List of all the inputs on the page, and then check their value method bindings to see if the string version is referencing your variable name. Error-prone and not pretty, but it'd work. Since they're property bindings, I don't think the startsWith filter in there would do what you want.

Alternatively, you could bind the components to something in a Java class from the start. I've been doing just such a thing recently (for a different end) and initially described it here: https://frostillic.us/f.nsf/posts/my-black-magic-for-the-day . The upshot is that, with the right cleverness for how you do your binding="" property, you could get a list of all the components that reference a property of a given object.

As for the second part of the question, if you DO get a handle on the components one way or another, you can check to see if it's a rich text control by doing "component instanceof com.ibm.xsp.UIInputRichText".

Jesse Gallagher
  • 4,461
  • 13
  • 11
3

A bit complex but yes. facesContext.getViewRoot() is an UIViewRoot object so it has List<UIComponent> getChildren() method which returns its children.

However, since it's a tree-structure, some of its children will have additional children components. You have to traverse the entire tree to build a list of components you want to see.

For types, you can decide what type a component is by its class. For instance, UIInput is a text box, etc.

Serdar Basegmez
  • 3,355
  • 16
  • 20