NetTalk Central

Author Topic: Two question on serving web pages  (Read 5694 times)

Rob Kolanko

  • Sr. Member
  • ****
  • Posts: 253
    • View Profile
Two question on serving web pages
« on: March 27, 2012, 04:20:21 PM »
Two question on serving web pages

At the start of a NetWebForm, I wish to evaluate a function and based on the result continue with the NetWebForm or jump to another form. I added code, in the  “procedure setup” embed, before any template code to run the function and call p_web._sendfile method to direct to a different web page when required. The p_web._sendfile method will show the correct form, however the form has two web page headers. Looking the generated source, the first header has a “div id” of “busy”. I tried setting the second parameter of the p_web._sendfile method to  NET:NoHeader but still two headers appear. Is there any way to clear any generated web page before calling the p_web._sendfile method, so that only that  webpage  called appears?

Also with NetWebForm, is there a hand code method to change the  URL from the URL entered in the “URL on a save” field on the NetWebForm template  from within the form validation routines?  Thus after the form has been generated and the save button has been accepted.

Thanks
Robert Kolanko

kevin plummer

  • Hero Member
  • *****
  • Posts: 1195
    • View Profile
    • Production Accounting and Software Payroll
Re: Two question on serving web pages
« Reply #1 on: March 27, 2012, 09:30:36 PM »
Hi Rob,

to answer your first question I would be inclined to do that in the Webhandler _SendFile method where you can simply change the Loc:filename based on a condition.

for your 2nd Q, you can set the “URL on a save” as a session value. Obviously if you want to set this SSV after the form opens then you need to refresh the save button.

Cheers,

Kevin

Rob Kolanko

  • Sr. Member
  • ****
  • Posts: 253
    • View Profile
Re: Two question on serving web pages
« Reply #2 on: March 28, 2012, 08:49:04 AM »
Hello Kevin,
Thank-you for your response.

However in Q1, I am using the Webhandler _SendFile method and the method  will load the correct web page, however the web page has two web page headers.

In Q2, I do not know the URL until after the user presses the save button thus there is no opportunity to refresh the save button.

I attached an example of question 1 and question 2. Basically, I wish to change the destination web page of a button after the button is pushed. There must be a way, because this is what happens when an alert message is displayed. Isn’t it?

Robert Kolanko

[attachment deleted by admin]
« Last Edit: March 28, 2012, 11:45:23 AM by Rob Kolanko »

kevin plummer

  • Hero Member
  • *****
  • Posts: 1195
    • View Profile
    • Production Accounting and Software Payroll
Re: Two question on serving web pages
« Reply #3 on: March 28, 2012, 05:16:30 PM »
Rob I'm on C63 so can't open your test file.

Q1 - you can set the page header globally or on the form. So I suspect the form with 2 headers has a header set on the form template and if so remove it.

Q2 - at what point do you know the URL? If it is only after they click the save button then the _sendfile method seems like a good place to redirect them.

Rob Kolanko

  • Sr. Member
  • ****
  • Posts: 253
    • View Profile
Re: Two question on serving web pages
« Reply #4 on: March 28, 2012, 11:29:09 PM »
It is unfortunate that you can not compile the C8 test app.  You will easily see the results.

Q1 - I am not sure what your response is about, the page is a simple NetWebForm. There is no specific header template.  If this form is called from a regular button, only one header is displayed. But when _sendfile is used to display the same NetWebForm page  from the Procedure Setup embed of different NetWebForm , the redirected page is displayed with two headers, and in this test program a second footer as well. I believe under the covers, the sever has already created in memory, the header and footer of the form before the form generation has been executed.
 
Q2 - If  _sendfile is used after the save button, then believe it or not, both the redirected page and the page that save button set  to are combined together and shown. The _sendfile method returns to code, so I added a return statement to stop executing within the form, but the problem still exists.

A typical scenario to use this redirection is when the user has entered a combination of field values that is not an error, but the program must warn the user of the consequences and the “are you sure?” prompt. I need this message on a different web form. The program does not know that the warning condition exists until the user press the button. Thus the program can send the user to one of two pages based on the condition, only the URL that the button was assigned to during generation will work. There does not appear to be a way to select different web page. Either before the form is completed (Q2) or in the assigned web page (Q1).
« Last Edit: March 28, 2012, 11:31:15 PM by Rob Kolanko »

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: Two question on serving web pages
« Reply #5 on: April 01, 2012, 11:20:32 PM »
Hi Robert,

>> At the start of a NetWebForm, I wish to evaluate a function and based on the result continue with the NetWebForm or jump to another form.

this is a common thought pattern, especially coming from windows, but it's very difficult to pull off. That's because the form procedure is called over and over again in small little bites. It's not like a windows form where it comes in once at the top and is easily changed.

Looking at your example;
the code at the top of FormA is very wrong. If you put a trace in here you'll see lots of calls coming in - the p_stage parameter being different each time.

But worse, the call here to _sendfile is also not going to work. This is an architecture thing, but boils down to the _sendfile begin called twice - once for the original form, then you recurse in to it with your call - hence the two headers.

So let's ack up a bit and consider two other ways to attack the problem.

a) The URL that comes to this form in the first place should probably be set correctly - ie make the decision at generate time, not click-time.

b) failing that, make this form (form A) capable of handling multiple cases - perhaps by hiding/unhiding tabs etc. Thus one form, which looks different, but is at heart the same form procedure. or

c) if that's not a possibility then move the "business logic" into the WebHandler completely, so FormA is not called in the first place, it goes straight to Form2.htm.

It's not really possible to say which is best in your case, without understanding a bit more about the context of the decision.

cheers
Bruce



Rob Kolanko

  • Sr. Member
  • ****
  • Posts: 253
    • View Profile
Re: Two question on serving web pages
« Reply #6 on: April 02, 2012, 08:08:29 AM »
Hi Bruce,
Thank-you for your response. Now, I understand the logic why my methods would not work. However the problem still exists, the business logic dictates that the button’s destination is not  known at the page generation. I do not believe that this is an unusual requirement.  The same requirement exists when validating the fields to a form after the submit button has been press,  embed code can be added to validate the entered fields where the error message is copied to the loc:alert field and the invalid field name is copied to loc:invalid and magically the web page destination of the submit button is not displayed, but a pop-up form. I need the same capability, but show my form, instead of the popup. Your suggested solution b may be possible, but is not practical as the submit destination page “form 1” is quite complex and by integrating  “form 2” into this page will increase the complexity to the point that it may become inefficient and hard to maintain. That leaves solution c. Please help me with a starting point, such as which embed and/or logic to employ. My guess is be there is a point that all web page request pass through, then code will be added to check if the page is “form 1” then change it to “form 2” under the proper conditions.

Thanks
Robert Kolanko

kevin plummer

  • Hero Member
  • *****
  • Posts: 1195
    • View Profile
    • Production Accounting and Software Payroll
Re: Two question on serving web pages
« Reply #7 on: April 02, 2012, 02:32:08 PM »
from my original post

to answer your first question I would be inclined to do that in the Webhandler _SendFile method where you can simply change the Loc:filename based on a condition.


so just search for _sendfile in the web handler to find the embed.

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: Two question on serving web pages
« Reply #8 on: April 02, 2012, 11:19:17 PM »
Hi Robert,

Kevin's answer is the best one - put the "decision logic" in the WebHandler.

From your answer though I can see there are some "misunderstandings" and so I thought I'd pick those out - it might be helpful as you go forward. Remember the web is a different place, and while some things may _look_ the same, underneath they can be very different.

>> and magically the web page destination of the submit button is not displayed, but a pop-up form. I need the same capability, but show my form, instead of the popup.

Applies to popup mode - not page mode:
While it's tempting to see the popups as "new windows" or perhaps "new procedures", they're actually just parts of the original page that have suddenly been "unhidden".
The reason it can abort the Cancel, and return to the existing form is because the existing form is, well, there.

When a form is saved, there's a fair bit of interaction that goes on. Firstly with the "form that was" (validating and so on) and then "with the form that will be" - ie the place you are going to.

Chaining from one form to another is best done in page mode. In page mode it doesn't need to know "in advance" where it might go, so there's a fair bit more freedom involved. In your case if you

>> My guess is be there is a point that all web page request pass through,

yes, this is the WebHandler. If you inspect the _Sendfile method there you'll see how it sends the requests on to the appropriate procedure.

Rob Kolanko

  • Sr. Member
  • ****
  • Posts: 253
    • View Profile
Re: Two question on serving web pages
« Reply #9 on: April 03, 2012, 01:00:23 PM »
Thank-you for your responses guys. Sorry Kevin, I am new to developing with Net Talk, I thought that you were asking me to use the webhandler _sendfile method rather than change it. I did not know that the other methods were calling this method to display pages. Anyway, I was able to move the business logic into this method and I was able to do what I wanted.

Regards
Robert Kolanko