1

I have a Java Bean with a Method that returns an Object of type PaymentItem

Payments.getItem(viewScope.vsRIndex);

this method returns the nth item from an ArrayList<PaymentItem>

I have a button on my main page that renders a Custom Control on that on the main page and sets the viewScope to the correct index value.

<xp:panel id="panelPaymentEntry"
    rendered="#{javascript:(viewScope.vsShowPayment) ? true : false;}">
    <xc:ccCOMPaymentInput></xc:ccCOMPaymentInput>
</xp:panel><!-- panelPaymentEntry -->

I want to set the dataSource for ccCOMPaymentInput to the PaymentItem returned by Payments.getItem(viewScope.vsRIndex)

I added this code to the createObject

try{
    Payments.getItem(viewScope.vsRIndex);
}catch(e){
    //do nothing
}

with the var = pItem

But does not appear that the Object pItem has been created. Am I on the right track? or ?????

Bill F
  • 2,057
  • 3
  • 18
  • 39

1 Answers1

2

Generally, the cleanest way to do this is to create a custom property on the custom control to specify the context object - value is the conventional pick. So you'd have something like:

<xc:ccCOMPaymentInput value="#{javascript:Payments.getItem(viewScope.vsRIndex)}"/>

Then, within the control, you can reference it as compositeData.value. For example:

<xp:inputText value="#{compositeData.value.someTextField}"/>

The Object data source you're presumably referring to can also work, but isn't always necessary.

Jesse Gallagher
  • 4,461
  • 13
  • 11
  • when I add the custom control as you suggest: I get an error "unknown Property vlaue" I do not have a custom Property defined for ccCOMPaymentInput . In addition I need to convert viewScope.vsRIndex to an Integer but that is not hard. – Bill F Sep 15 '15 at 23:17
  • Do I need to add something to the custom control ccCOMPaymentInput ? – Bill F Sep 15 '15 at 23:37
  • 1
    The type of the custom property should be manually entered to be: java.util.Object – David Leedy Sep 15 '15 at 23:49
  • 1
    Also - the next NotesIn9 - #182 should have an related example for you. – David Leedy Sep 15 '15 at 23:51
  • @david I added a custom property to my cc Name = pItem,Type=java.util.Object, Editor is empty (not sure which editor to use. When I insert the cc into my main page and go to the Custom Properties there are no properties in the list. I must be missing something. – Bill F Sep 16 '15 at 01:52
  • 1
    Dave has a typo there: it's "java.lang.Object", not util. I also use the Javascript convention of "object", because I'm lazy. In any event, the properties when editing your custom control should look like https://dl.dropboxusercontent.com/u/23599916/Screen%20Shot%202015-09-16%20at%208.52.48%20AM.png – Jesse Gallagher Sep 16 '15 at 12:53
  • I have it working using the custom property using the java.lang.Object. Tried getting a Object Data Source to work but won't load properly, it would appear that the Object Data Source code only runs on the custom control when the main Page loads. I would really like to get it working that way. At least I can get this through proof of concept using the custom property. So thanks David and Jesse – Bill F Sep 16 '15 at 16:31
  • I USED to love Object Data Source. Now I don't. There's some concerns with that especially inside custom controls. It should work but I believe it can process a CRAZY number of times... even more then the 6-7 times of the JSF Lifecycle. I believe Paul Withers has blogged about it on his blog. Be careful with that for performance issues. – David Leedy Sep 16 '15 at 20:42
  • Sorry about giving you the wrong info at first. Heard to remember when you're not "in the moment". I forget that a lot. As jesse said it should be java.lang.Object. I'd have to check on his use of just "object". I'm sure that works (it is Jesse after all) BUT you might not be able to edit that var in the "pretty property" pane. That might require you to put the property in via source direct. I had that issue before and forget the reason. I think I stick with java.lang.Object so I can use the Pretty Panel... – David Leedy Sep 16 '15 at 20:45
  • I have it working with the custom property and even at that I notice process firing an unusual number of times. Fortunately they are all memory resident so the performance hit is not to bad. I have several documents that are linked to a parent using the unique key. A method call Getallitems builds the ArrayList of items. From my repeat I get the correct element from the array and pass it to the custom property that does crud for a payment. Took a bit of work to get the save of the payment object back into the array at the right place but its working great. – Bill F Sep 16 '15 at 22:43
  • Yeah, that's definitely something to keep in mind with anything #{}-bound - it's likely going to be executed multiple times, so it's important to make sure those accesses are efficient. Most of the time, I'll bind them to data objects or controller methods that do some internal caching, like yours effectively does. – Jesse Gallagher Sep 17 '15 at 02:14
  • in my getAllItems method I check to see if internalArray size = 0. If it is then it builds a new one, if not it just returns the already build internalArray. So the performance hit is pretty small. From my print statements in the method getAllItems can be called many times depending on what is happening on the page. – Bill F Sep 17 '15 at 17:51