I have a dynamicContent control I want to trap the error if there is no xp:key= matching value. I'm looking for something like a fall though that I can do something and not get a crash. I know that I can define a default key but I want to catch it at the end not the beginning. Or even something like dynamicContent.containsKey or dynamicContent.keyValues.
The xe:dynamicContent has a getFacet("facetId") method. It returns a UIComponent or (assumably) null if the facet doesn't exist. Maybe you can use that to check if the facet exists.
Related
I would like to know how can I search for log messages with a custom properties containing a field named “Main Status” and value “Starting Process”…
how can i do that?
I'm making the assumption that the field is "Main_Status" or "MainStatus". Otherwise you may need to encode it "Main&20%Status", but I'd expect that to be problematic.
If that's acceptable then a query with the field and value would be something like Main_Status:Starting Process*.
You could also verify that the the field exists with something like Main_Status:Starting Process* AND _exists_:Main_Status.
I feel like I'm just not understanding something about the XPages lifecycle here. I have an xp:text control, with a value of viewScope.count. Initially, that's null. After the xp:text, I have a repeat that's performing a calculation and returning an array of objects for its value. At the end of the repeat's value section, I'm trying to update the xp:text with a count of the things in the array:
viewScope.count = myArray.length;
The xp:text isn't being updated with that value, though. Should this work? Do I need to do a manual refresh of the xp:text when I modify viewScope.count? TIA!
You should be able to use the index of the repeat to give you a count.
Take a step back and rethink the approach. Inside the code you use for your repeat you update something outside.
Not looking at 'does it work' I would claim 'bad idea'. Such side effects make maintenance a nightmare (and are not very MVC).
The better approach (IMHO):
Create an object data source. AFAIK that can be a JSON object if you are not comfortable with Java. That object would have all the needed properties for your repeat and your counter display. It serves as your model.
Then bind the repeat and the text field to the model and you are good.
Makes sense?
I am working with xpages components and it is hard for me to quess when the getComponent("comp").getValue() returns null or when returns "" (empty string).
Is there a way to tell? Are there components which return null when other components return ""?
A component will have a null value if the value property has not been assigned. That can happen if the it's bound to a field on a document and that document does not yet have the field, e.g. it's a brand new document. It can also happen if it's bound to a scoped variable that hasn't been set yet.
It's best practice to bind, wherever possible, to the data source rather than go via the component. This way document1.getItemValueString("myField") will return a blank string if myField hasn't been set on document1, as well as if myField's value is "". Also, if in the future youo delete the component comp, the compiler won't (and can't) tell you you're calling that component in SSJS and you'll get a runtime error. If you're using document1.getItemValueString("myField"), it will still work.
Plus, as Tim Tripcony said, it's slower https://twitter.com/timtripcony/status/359532216382001152 and this blog post goes into much greater depth on why to talk to data not components http://www.timtripcony.com/blog.nsf/d6plinks/TTRY-942UPQ
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?
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".
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.
How do I get the value from a SPFieldBoolean object? Do I simply cast it to a boolean or do I need to do something further with it?
I am fetching it in an EventReceiver class during an ItemAdded event from properties.ListItem["fieldname"].
If there is a chance the field might not exist (and be null), how do I check for that?
The value is already a bool, you just need to type-cast it. All fields provide values in their native value-type — see also SPField.FieldValueType property that gives you the actual type in case you need to inspect it on runtime.
To make sure the field is contained in the list, just use the SPFieldCollection.ContainsField method on your list's Fields collection.