1

OK, I've posted a couple times but help me get the architecture of this straight with an app I'm trying to do. I'm a beginner xpages guy.

I have an order system for customers to make orders for products for this company. I have separate Products and Customers DBs that contain what I need. In my Order DB, how I understand it, on the main xpage, I have a section to take in Customer info and another to take in Item info. The user enters the customer ID on a type-ahead field that doesn't store on the xpage but is used to display customer info for this order. I fill in the fields with the onchange event to show the user all applicable info.

Then I have the item stuff defined. There is an area that utilizes a type ahead field to look up items to order. The type ahead takes the value and looks up the data to display. Only the item number, qty and price needs to be stored on the document1 document, and the other info needs to be displayed for the user to review, such as description, qty on hand, etc.

My question is, do I create a panel with a table with the item info on it and set those "display only" fields back to the item source document? Since I'm not storing that info on document1 but still need to display it, do I bind those fields? Also, do I use partial or full for each of the two processes above? I hope this isn't too confusing to you, just trying to get this straight in my head. If anyone has five minutes of their time to talk to me to get this straight, I'd appreciate it.

1 Answers1

1

Mike,

There are many right answers here, and I hope you get several. For me, I prefer to bind everything to scoped variables, but primarily viewScope. Then in your button event, persist the data to your backend datasource. When I first started developing XPages, I did bind to documents, but after a while experience (and the advice of others) taught me to simply bind everything to viewScope, and then use a java method or SSJS in your event to process everything. This helps to avoid the temptation to spread business logic all through your application.

Specifically in your case, bind everything to viewScope, and populate those in your event (button, onChange, or even beforePageLoad). Be sure to include that table in a panel and include it in a partial refresh. Avoid full refresh unless absolutely necessary.

Steve Zavocki
  • 1,840
  • 4
  • 21
  • 35
  • I don't understand. I haven't implemented a view yet so how can I have a viewScope? I will have a view on the order form showing all the items ordered selected by the order ID I've set which is a unique number. Since there are multiple areas on the form utilizing different DBs, there are separate processes. Am I not to use the onchange events for these two type ahead fields? Maybe I'm not understanding binding. – Mike Gonzalez Oct 20 '15 at 18:19
  • 1
    Mike, viewScope doesn't have anything to do with 'views'. As a beginner there is a lot to learn (I have been there). Notes in 9 is your friend. Start off by watching this intro to scoped variables: http://xpages.tv/xtv3.nsf/episode_user.xsp?action=openDocument&documentId=90E which will help with the concepts. This understanding is foundational to developing in XPages. – Steve Zavocki Oct 20 '15 at 18:24
  • I definitely want to be efficient. Right now I'm creating a scoped variable with the Customer type ahead field (AJAX for the field). Then in the onchange event, I'm taking that variable which is the Customer ID and getting the doc from the Customer DB and setting fields from that doc on the Order xpage. IS there an easier and more efficient way to do this? – Mike Gonzalez Oct 20 '15 at 19:22
  • 1
    It is hard to answer in this format, but I think that sounds about right. When you load the page, you don't know which customer to load, so you then load that data in the onchange of your customer combobox. That would be the proper event to use. From there get your customer data from the document and set it to viewScope variables. Make the onchange event to a partial refresh on the panel that displays your data. In your panel bind everything to viewScope, same as you set in the onchange event. When the user changes the combobox, then it will load fresh data. – Steve Zavocki Oct 20 '15 at 19:30
  • Sorry to be so dense. Are you saying I shouldn't be filling in the fields from the onchange event but instead, simply set the viewScope variable and then code each field to do a lookup based upon the variable / OR set different viewScope variables on the onchange event. one for each field needing to be displayed and then each field pull in the value for it's own variable? – Mike Gonzalez Oct 20 '15 at 21:06
  • Bind your static fields directly to a viewScope variable. Set the corresponding viewScopes in your onchange event and do a partial refresh of the panel containing your static fields. – Steve Zavocki Oct 20 '15 at 21:17
  • If you don't get it figured out, I could discuss this with you in chat tomorrow (I am in central time, USA). SO doesn't like too many back and forth comments. Also, edit your question to include any other details that will help other people answer. – Steve Zavocki Oct 20 '15 at 22:24
  • Steve, I would love to discuss this with a seasoned xpages person and would return that favor to others in the future. I have a complex application here that I'm trying to figure out, which includes certain information from my customer DB, product DB and main order DB that I want to DISPLAY and other data that I want to STORE on my order or item records. Once for customer info on the main xpage and multiple items for that customer on the same xpage. If you can take some time to explain how xpages is architectured, my cell is 330-698-1043 and email is epi@enviroprointl.com. – Mike Gonzalez Oct 22 '15 at 14:33
  • Mike, I will try to reach out to you later today. – Steve Zavocki Oct 22 '15 at 17:19