SWI-Prolog cgi_get_form(Arguments) saving and handling arguments web form - forms

I'm looking for a way of saving and after handling the arguments of a web form in SWI-Prolog when I submit the form and I call the same program to generate another form and so on. Always calling the same prolog program from one form to the next one.
The CGI SWI-Prolog library saves these arguments as a list of Name(Value) terms, i.e [Name(Value)].
if I pass the arguments like a hidden argument inside the form (TotalArguments is a list):
format('"<"input type="hidden" id="nameofform1" name="nameofform1" value="~w" />~n', TotalArguments),
I need to get rid of the id or name that concatenates on my resultant list on TotalArguments when I append it. Any idea of how to do this so that the final list looks like [nameofform1(value1), nameofform2(value2),...]?
I could also write this list of arguments and append it into a file, and consult it every time the program is called again, but this will load them always and I only need to load the arguments needed in the specific step and form handled at the moment. Because otherwise this file could contain undesirable info after some executions. Any thoughts on how to do it this way?
Any other suggestions for this kind of problem?
Edit with my solution using hidden form
I've solved it by creating:
extract_value([],_).
extract_value([A0|__ ], Valor) :-
A0 =.. [_, Value],
Valor is Value.
and then doing:
extract_value(Arguments, Value),
and submiting the hidden value of the form like:
format('<"input type="hidden" id="nameofform1" name="nameofform1" value="~w"/>~n', [Value]),
and appending it in the next form so that it looks how I wanted:
[nameofform2(value2),nameofform1(value1)]

It's a bit unclear to me what exactly you need here, but to remove the first element of a list that unifies with a given element (especially if you know for certain that the list contains such an element), use selectkchk/3. For example:
selectchk(id(_), List0, List1),
selectchk(name(_), List1, List)
in order to obtain List, which is List0 without the elements id(_) and name(_). Kind of implicit in your question, as I understand it, seems to be how to create a term like "form1(Value)" given the terms name(form1) and Value. You can do this for example with =../2. You can create a term T with functor N and arguments Args with
T =.. [N|Args]
It does not seem necessary to write anything to files here, I would simply pass the info through forms just as you outline.

Related

In SAP scripts how do you define which data is sent to an element

I need to make some changes to an SAPScript. I have the program and form name
Program: RBOSORDER01
Form: RBOSORDER02
I am looking to change some of the data shown in the form. I have debugged the program and I get see the call to write to the form, for example:
CALL FUNCTION 'WRITE_FORM'
EXPORTING
ELEMENT = 'ITEM_TEXT'
EXCEPTIONS
ELEMENT = 1
WINDOW = 2.
But how is the data passed between the program and the form. I cannot link between each. I was expecting to see a structure or a data element passed with 'ITEM_TEXT' and then this data is printed at this element "ITEM_TEXT" in the form but the link is not clear to me.
I have looked at the form also in SE71 and cannot see where you define this. Where is the link here, what am I missing?
This is in the form, so SE71 is what you need. You have to find the window first, where this element (ITEM_TEXT) is displayed, than look for the element and see what is displayed inside. The SAPSript form uses the global variables (structures, internal tables) of the print program directly by default (there are some other options as well, INCLUDE texts for example). So for example if a global variable gv_text is declared in the print program, and it is displayed in the SAPScript, than it will look like &GV_TEXT& in the form.
You can also debug the SAPScript if you switch on debugging in SE71 (can be painful, if the form is big).
Function 'WRITE_FORM' just calls the EntryPoint of the Form (SE71 / RBOSORDER02) in this case with ELEMENT='ITEM_TEXT'.
So you will end up in MAIN-Window at:
/E ITEM_TEXT
/: INCLUDE &VBDPA-TDNAME& OBJECT VBBP ID 0001 PARAGRAPH IT
In this case you have to debug what "VBDPA-TDNAME" is at this time and then you will find its value with transaction "SO10" (Standard-Text)
The INCLUDE can be a complex text and can have its own format strings.
As Jozsef said before, VBDPA-TDNAME is defined global in the print programm. (SE38n / RBOSORDER01)

How to filter by both text and property in Chrome DevTool's network panel?

I want to filter Chrome DevTool's network panel by the method property and text in the URL. For example, if I am searching for the text chromequestion in the URL and only HTTP GET requests (ignore PUT, POST, DELETE, etc).
I am able to filter by text or by method:
I am not able to combine the filter to search by both text and method:
I read the documentation at https://developers.google.com/web/tools/chrome-devtools/network-performance/reference#filters and I am able to filter by multiple properties (.e.g, domain:*.com method:GET). However, I am unable to filter by text and property (e.g., method:GET chromequestion).
Unfortunately, it's not possible to do this currently. I played around in DevTools originally, but couldn't find a way. I later had a look into how the filtering was implemented, and can confirm there's a limitation preventing you from mixing the pre-defined filters and text filters.
Implementation details
This is a bit long but I thought it might be interesting for some to see how it's implemented. I will probably look into improving the implementation, either myself or I'll log it because it's limited.
There's a _parseFilterQuery function that parses the input field and categorises the entries into two arrays. The first is called filters, and it's the pre-defined filtering options, such as method:GET etc. The second is a text array filter, split up by spaces. The parser determines the difference fairly naively, by checking for the occurrence of :, and - at the start (for negation).
Scenario 1
You only input a pre-defined filter, or multiple filters. For each filter, the specific filter function, which looks at the different properties of the request object, is pushed to a network module filters array (this._filters). Later on, for each request, the function is called on it, and a match returns true, otherwise false. This will determine whether the request is shown. There's obviously a requirement for ALL filters to return true for the row to show.
Scenario 2
This is the interesting one, where you input both a pre-defined filter and a bit of text. This covers the Stack Overflow question. The _parseFilterQuery function looks at the text filters first, before the pre-defined ones. In Scenario 1, this was empty, so it was skipped.
We pass each text word to the _createTextFilter, and push each of the resulting filters to the network module filters array. However, the implementation of this is questionable. The only time the actual word passed in is used is to check whether its a negation filter for a bit of text. If the first character is -, it means the user doesn't want to see a request with the following word in the name. For example -icon means don't show any request with that in the name/page. If there is no negation, it simply returns the WHOLE input text as a regular expression, NOT the word passed in. In my case, it returns /method:GET icon/i.
The pre-defined filters are looked at next. In this case, method:GET is pushed.
Finally, it loops over the requests calling each filter on it. However, since the first filter is /method:GET icon/i, it makes ALL other filters redundant because it will NEVER pass. The text filters only apply to name and path, so method:GET in a text filter will be invalid.

How should list be represented in ASP (Answer Set Programming)?

A processor 'a' takes care the header 'a' of a message 'a_b_c_d' and passes the payload 'b_c_d' to the another processor in the next level as following:
msg(a, b_c_d).
pro(a;b;c;d).
msg(b, c_d) :- pro(X), msg(X, b_c_d).
msg(c, d) :- pro(X), msg(X, c_d).
msg(d) :- pro(X), msg(X, d).
#hide. #show msg/2. #show msg/1.
How should I represent list 'a_b_c_d' in ASP, and change the above to general cases?
No, official way, but I think most people don't realize you can construct cons-cells in ASP.
For instance, here's how you can get items for all lists of length 5 from elements 1..6
element(1..6).
listLen(empty, 0).
listLen(cons(E, L), K + 1) :- element(E); listLen(L, K); K < 5.
is5List(L) :- listLen(L, 5).
#show is5List/1.
resulting in
is5List(cons(1,cons(1,cons(1,cons(1,cons(1,empty))))))
is5List(cons(1,cons(1,cons(1,cons(1,cons(2,empty))))))
is5List(cons(1,cons(1,cons(1,cons(1,cons(3,empty))))))
...
There is no 'official' way to handle lists in ASP as far as I know. But, DLV has built-in list handling similar to Prolog's.
The way you implement a list, the list itself cannot be used as a term and thus what if you want to bind between variables in the list and other elements of a rule? Perhaps you would like something such as p(t, [q(X), q(Y)]) :- X != Y.
You can try implementing a list as (a, b, c) and an append predicate but the problem is ASP requires grounding before computing answer-sets. Consequently a list defined in this way whilst more like lists in Prolog would mean the ground-program contains all ground-instances of all possible lists (explosion) regardless of whether they are used or not.
I therefore come back to my first point, try using DLV instead of Clingo if possible (for this task, at least).
By using index, I do have a way to walk a list, however, I do not know this is the official way to handle a list in ASP. Could someone has more experience in ASP give us a hand? Thanks.
index(3,a). index(2,b). index(1,c). index(0,d).
pro(a;b;c;d). msg(3,a).
msg(I-1,N) :- pro(P), msg(I,P), index(I,P), I>0, index(I-1,N).
#hide. #show msg/2.
You can use s(ASP) or s(CASP) ASP systems. Both of them support list operations like prolog. You might need to define the list built-in in ASP .

bindFromRequest and asFormUrlEncoded return different values

I have a form where a field name is the same as one of the method/url parameters on the submit, say someInt. I.e. my form has #(dummyForm:Form[Dummy], someInt:Int) and dummyForm has a field "someInt" -> number and the controller is defined as def submit(someInt:Int) =.... Sample code here.
Let's say I submit the form with dummy.someInt value 222 and url parameter 555, I find the following:
request.body.asFormUrlEncoded shows one someInt, namely the value entered in the input field: (someInt,ArrayBuffer(222))
bindFromRequest, however somehow binds the form value to the url parameter value, 555 in this case
Is this expected behaviour? I would have thought bindFromRequest would be able to differentiate between the two? Is there a preferred way to prevent this type of conflict (besides having different names)?
(There is a workaround in this case. Instead of using the parameterless version of bindFromRequest, it seems to work as desired if you explicitly specify the asFormUrlEncoded set of values, i.e. bindFromRequest(request.body.asFormUrlEncoded.getOrElse(Map())). I am using Scala - have not tried to replicate in Java.)
In the bindFromRequest function, request.queryString is explicitly append to the list of values.

in XML:TWIG, how to stop parsing once find the interested element

I only want to parse an interested element of xml (e.g. see below: class element with name equals to math) and I want to stop once the first element hitting this condition is parsed. (since There is only one class whose name is math, it is unnecessary to continue once the element is already found).
However, if I implement as follows, the code continues to read the whole file after it found the element i am interested (the xml file is very long so it takes long time). my question is how to stop it once the first class element with name = math is parsed?
my $twig = new XML::Twig(TwigRoots => {"class[\#name='math']" => \&class});
$twig->parsefile( shift #ARGV );
besides, I also want to delete this class from xml file (not only from memory) after it is parsed so that next time when parsing a class with other names, the class element will not be parsed. Is it possible to do that?
It seems what you're looking for are XML::Twig's finish_print and finish_now :
finish_print
Stops twig processing, flush the twig and proceed to finish printing
the document as fast as possible. Use
this method when modifying a document
and the modification is done.
finish_now
Stops twig processing, does not finish parsing the document (which
could actually be not well-formed
after the point where finish_now is
called). Execution resumes after the
Lparse> or parsefile call. The content
of the twig is what has been parsed so
far (all open elements at the time
finish_now is called are considered
closed).