Recent

Author Topic: Any Docs for THTMLDatasetContentProducer  (Read 3949 times)

Michael Collier

  • Sr. Member
  • ****
  • Posts: 329
Any Docs for THTMLDatasetContentProducer
« on: February 24, 2012, 06:05:21 pm »
I'd like to try THTMLDatasetContentProducer but didn't find anything on the wiki. Specifically I need details for producing the content, I guessed a few methods but didn't work.

I tried the ProduceContent method (raised exception), do I need to use the other events to produce anything? The source mentions that this method is for testing only?

The cgi works in all other respects, I can handle the action, open connection to MySQL, open query, etc and have set the actions ContentProducer property to HTMLDatasetContentProducer1

I was expecting/hoping to do something like this for the action OnRequest event
Response.Content := HTMLDatasetContentProducer1.ProduceContent;
Handled := True

I can use HTML by hand and produce a <table></table> but would prefer to use this component


devEric69

  • Hero Member
  • *****
  • Posts: 652
Re: Any Docs for THTMLDatasetContentProducer
« Reply #1 on: May 14, 2020, 09:27:35 am »
I was expecting/hoping to do something like this for the action OnRequest event
Code: Pascal  [Select][+][-]
  1. AResponse.Content := HTMLDatasetContentProducer1.ProduceContent;
  2. Handled := True;
I can use HTML by hand and produce a <table></table> but would prefer to use this component

Assuming that there is a TWebAction named act_get_my_html, you must ask to write in AResponse, the return of an internal stream (when answering with html Producer objects solution, we must use the methods of the writer, which manages a memory stream for a purpose of rapidity; no string type here like with the fpTemplate solution which uses text \ string processing in the Php way) by a recursive " foreach " that traverses the polymorphic objects of the THtmlCustomElement \ TDOMElement hierarchy written by aWriter forming a DOM Tree, with this call ( it's the Producer's job to convert its internal stream into text in the response; that's how the pattern was designed, although there is a text-html rendering method for debugging purposes only; caution: sometimes it returns '' in some overriden ProduceContent methods of the html DOM elements ;) ):
Code: Pascal  [Select][+][-]
  1. procedure TFPWebModule1.act_get_my_htmlRequest(Sender: TObject; ARequest: TRequest; AResponse: TResponse; var Handled: Boolean);
  2. begin
  3.   HTMLEntityProducer1.HandleRequest(ARequest, AResponse, Handled);
  4.   Handled := True;
  5. end;

~~~~~~~~

Here is another example, always with an html Producer object, allowing to create a web application RAD way, i.e. with drag-drop of components:

Code: Pascal  [Select][+][-]
  1. procedure TFPWebModule1.HTMLEntityProducer1WriteEntity(Sender: THTMLContentProducer; aWriter: THTMLWriter);
  2. begin
  3.   aWriter.Startbody;
  4.     aWriter.Startparagraph;
  5.       aWriter.heading2('Hello, world from inside §1');
  6.       aWriter.Text('Here is text written inside the current paragraph.');
  7.     aWriter.Endparagraph;
  8.     aWriter.paragraph('This is another text written inside a self "started and ended paragraph.');
  9.     aWriter.Startparagraph;
  10.       aWriter.heading2('Hello, world from inside §2');
  11.       aWriter.Text('Here is the final text.');
  12.     aWriter.Endparagraph;
  13.   aWriter.Endbody;
  14. end;

Code: Pascal  [Select][+][-]
  1. procedure TFPWebModule1.act_get_my_htmlRequest(Sender: TObject; ARequest: TRequest; AResponse: TResponse; var Handled: Boolean);
  2. begin
  3.   (*
  4.     ask HTMLEntityProducer1 for its objects DOM tree 's stream content:
  5.   *)
  6.   HTMLEntityProducer1.HandleRequest(ARequest, AResponse, Handled);
  7.   Handled := True;
  8. end;
« Last Edit: May 14, 2020, 10:14:38 am by devEric69 »
use: Linux 64 bits (Ubuntu 20.04 LTS).
Lazarus version: 2.0.4 (svn revision: 62502M) compiled with fpc 3.0.4 - fpDebug \ Dwarf3.

egsuh

  • Hero Member
  • *****
  • Posts: 1760
Re: Any Docs for THTMLDatasetContentProducer
« Reply #2 on: June 08, 2020, 01:43:25 pm »
Any progress on this? I'm looking at this component, to review the content of a dataset via web.
I think this should display the content of a dataset in tabular format, without any further codes, but not.

Code: Pascal  [Select][+][-]
  1.    datasource1.dataset := sqlitedataset1;
  2.    dsetcont.datasource := datasource1;
  3.    webaction1.contentproducer := dsetcontent;   // dsetcontent = THTMLDataSetContentProducer
  4.  
   

Using aWriter.... works for THTMLEntityProducer,  but not for THTMLDataSetContentProducer.
« Last Edit: June 08, 2020, 02:01:51 pm by egsuh »

devEric69

  • Hero Member
  • *****
  • Posts: 652
Re: Any Docs for THTMLDatasetContentProducer
« Reply #3 on: June 08, 2020, 05:33:08 pm »
For information, not knowing what you know about this component.

I tried to make this component 100% operational, 2 weeks ago (I gave myself 2 days, not having more time; so I copied the unit in my project directory, and debugged it with LazLogger and "raise HTMLException"). The problem is the time - as usual - to find the 0,???1% of lines to modify ^^.

Indeed, I think that writing with HTML words encapsulated in Pascal objects rather than using the template engine, only makes sense to me if it saves time. For a newbee - i know you're not - who doesn't know Web programming, but who knows how to create a database and how to create a .htaccess and a .htpassword files, using this component saves time.

Quickly, from memory, roughly the idea seemed to me to be that we should create an HTML table (loop on SQL records, to create each HTML row), with creation of an "edit" button in the last column of each HTML row.
There's a inter-pages HTML navigator provided, that can present, HTML table URL by HTML table URL, all x records of an SQL table.

The "edit" button of each HTML row calls a server-side web action, which should display the single row for its edition (labels column, followed by the html controls column for input). And there should be  two buttons "save changes" and "undo changes".

It's very far from ajax, but it's RAD which allows to hide technical problems for someone who wants to quickly publish and manage a SQL table, on the web or on an intranet.

nb: when editing, it's called THTMLDatasetEditContentProducer i.e. it's one step further.
« Last Edit: June 08, 2020, 06:16:33 pm by devEric69 »
use: Linux 64 bits (Ubuntu 20.04 LTS).
Lazarus version: 2.0.4 (svn revision: 62502M) compiled with fpc 3.0.4 - fpDebug \ Dwarf3.

 

TinyPortal © 2005-2018