Xpages validation fighting with view control

I have a simple xpage as follows:

(1) three fields (item, qty, price) bound to an order form

(2) a submit button

(3) a view bound the OrdersView with a pager. I have made the first column of the view selectable (checkbox) and added a delete button which uses a simple action to delete any selected documets.

When you fill in the three fields and submit a new line is appended to the view showing the orders.

Here’s the problem. If you use the built-in validation function and make those 3 fields required it seems to prevent both the view pager and the Delete Selected button from working. It seems to treat view paging and deleting from another data source as an opportunity to validate the empty fields. Is there a workaround to this?

Subject: Partial update?

Have you tried activating partial update options for both the Pager and the Delete button? I had a similar prob recently and got that to work using partial update. What didn’t work, though, was re-sorting of view columns: here we obviously can’t choose “Partial Update” resulting in field validation being triggered :frowning: (see this topic: http://www-10.lotus.com/ldd/nd85forum.nsf/ShowMyTopicsAllFlatweb/226f4882014c2dce8525754700524082?OpenDocument)

Subject: Tried both Partial Update and No data validation options

I tried the following combinations without success:

  1. For the View Paging issue (triggers validation in other fields on form) I tried the Partial Refresh option on both the View, the View Pager, and then individually. If you use Partial Refresh, the pager just doesn’t work.

  2. For the delete button issue (triggers validation in other fields on the form) I tried…

(a) the No data validation option - This just stops the button from doing anything

(b) Partial Update option

(c) both a and b.

I’d be happy to email my NSF to someone who can figure this out.

Subject: Looks like a bug - PMR opened EOM

Subject: Lotus says “working as designed”

So, looks like the built-in validation functions on xpages are fine as long as you don’t want to use a view on the same page it seems.

Subject: A workaround…

I ran into the same problem with required fields on a Xpage form under the Tabbed Panel control. Here’s a possible work-around:

First, turn off client-side validation. This is done in the Application Properties, XPages tab.

Next, set a flag on the server to check when you want to validate vs. when you don’t.

I used the XPages’ BeforePageLoad event and the following code:

sessionScope.validateForm=“false”;

Next, on the field you want to conditionally require, for the ‘Required field’ check box compute the value with the following Javascript:

sessionScope.validateForm;

Next, to enable the checking use the following code in your Submit button or some such event - be sure to put it right at the top so the validation happens before the rest:

sessionScope.validateForm=“true”;

I do whatever server actions I intend, then reset the value to false at the end:

sessionScope.validateForm=“false”;

I’m sure there is a better way but this is at least one possible solution.

Subject: Excellent Suggestions Ken

Ken, that solution sounds like it would work here. I had already turned off the client side validation (hate those dialog boxes anyway). Interpreting what you said, it sounds like the key is to use the built-in validation feature, but to turn it off until you really need it to avoid it being triggered by other events like paging through a view or deleting docs from another datas ource on the same page. Another xpages expert, John Mackey, who has experience going back to the predecessors of xpages (Lotus Component Designer & Workplace Designer) has kindly offered to look at my code and offer his suggestions. He’s done some pretty amazing things with xpages like a user-driven survey application which shows how xpage applications can go way beyond traditional Notes development without a huge amount of effort, at least once you “get” an xpage development. His blog and xpage examples at jmackey.net.

Subject: Great approach but I think there is an issue

I think this is a great approach since it isolates the validation to the button action.

When looking at this this weekend I believe there is an issue with the timing of setting the sessionScope variable.

By the time the button action fires off, the validation phase has already occurred. So the sessionScope variable does not get set in time for the validation phase (here’s a link to the JSF lifecycle phases: IBM Developer). Therefore it does not validate the fields.

Can you check to see if you see the same behavior the first time the button is clicked?

I tried to fire off an error in the code, but it comes back to the timing. If you set the field to be required via server side script, the XPage needs to be reloaded for that to be in affect.

By accessing the component (JSF), you can manipulate the properties directly:

tmp=getComponent(“SKU1”); //get input control

//some if statement goes here

tmp.setValid(false);

tmp.setRequired(true);

return;

But… once it is loaded and is required, you have the issue with the pager again.

I was looking into adding a message via script by using facesContext.addMessage() and just performing the validation logic manually but having the messages control display the error message with any other errors. I’m having trouble with accessing the right classes for this. I am still looking into it…

John

Subject: using addMessage in an XPage

I found that the following will work to programatically write a value to the error messages display control in an XPage:

facesContext.addMessage(“TheIDforErrorMessagesDisplayControl”, javax.faces.application.FacesMessage(“The error message”));

Subject: Possible solution

Hi there,

I had the same issue with the tabbed panel validation and don’t know if you sorted out or not, but I came up with this.

Define the onclick event on each tabPanels of your tabbedPanel and add the following code:

var tab:com.ibm.xsp.component.UITabbedPanel = getComponent(<id_of_tabbedPanel>);

tab.setSelectedTab(<id_of_tab>);

Can use full update or partail update to refresh only the content part of the page and check the “No data validation” checkbox.

Another alternative is to use viewScope or sessionScope variables and set the name of the tab you select, like viewScope.selectedTab = “tabPanel1”. Then put viewScope.selectedTab expression in the tabbedPanel’s selectedTab property.

Tibor