[opencms-dev] How to show a page with data submitted from a form
Alexandre Magaz Graça
alexm at asic.udl.cat
Fri Aug 20 12:49:39 CEST 2010
Hi Paul,
Tanks a lot for the explanation, it looks much clearer now. I'll go the
property way to avoid duplication.
Cheers,
Àlex
Al 20/08/10 00:26, En/na Paul-Inge Flakstad ha escrit:
> Hi Àlex and Steve,
>
> I'll try to explain.
>
> You can't put JSP code in the xmlpage itself and have it run directly. The xmlpage
> type is associated with a JSP template, which means when you request the page,
> the JSP template is run, and it is this file that produces the output to the screen.
>
> This means that if you need to run some JSP code, just put it in the template.
>
> One way to do this is to copy your existing template (referred to in the property
> "template") and modify it to fit your needs. Of course, you'll end up with two
> (and eventually ninety-eight) JSP templates that are partly duplicates...
>
> So a better way to approach it is to make use of a property whenever you need
> to do "something out of the ordinary". In this property (you would probably
> define your own property for this) you put the path to the JSP file that does
> "something out of the ordinary" - or, in your specific case, processes the form.
> In your regular template, you simply check if the property has a value. If it does,
> you read the value (a path to another JSP file), and simply include that file
> from your template.
>
> The process simplified would go something like this (note #3):
> 1. Template called because the xmlpage was requested
> 2. Normal template "head" code stuff
> 3. Read property "xxx" to check for a value
> 3.1 If yes, the value should be the path to another file. Include it.
> 3.1.1 The included file does something (like output form data)
> 3.2 If no, do nothing, continue to next step
> 4. Print the xmlpage content (this can of course also be done prior to #3)
> 5. Normal template "foot" code stuff
> 6. Done!
>
> This way you can avoid duplicate code, as one template JSP will be
> sufficient. Moreover, you get your form-processing code bits in a separate
> file, keeping things nice and tidy, and - even more interesting - you will be
> able to re-use your created system logic at a later time, by just creating a JSP
> that does the specific task needed. All you'll need to do is put the path to that
> JSP in your property.
>
> (When Steve refers to the "jsp-body" property, it is probably just a property
> he's defined himself for such a purpose. It is simply a placeholder for a path
> to some file, to allow for a more generic solution for including other files
> from a template that is shared by many files. This is why he says that his
> main template is "controlled by page properties". New properties are easily
> created by choosing "Define..." from the advanced properties dialog.)
>
> Note also that included files don't _have_ be JSP files. They can be whatever
> type, as long as you support it by coding the include bit correctly.
>
> I hope this clearified the issue for you. :)
>
> The important thing to remember is that in OpenCms, web pages are typically
> produced by JSP files (templates). This means that if you need to run some
> kind of code, it's just a matter of getting the code into your template in some
> way.
>
> Cheers,
> Paul
> ________________________________________
> Fra: opencms-dev-bounces at opencms.org [opencms-dev-bounces at opencms.org] på vegne av Alexandre Magaz Graça [alexm at asic.udl.cat]
> Sendt: 19. august 2010 12:02
> Til: opencms-dev at opencms.org
> Emne: Re: [opencms-dev] How to show a page with data submitted from a form
>
> Hi,
>
> Sorry for the delayed response, I've been in holidays.
>
> Al 29/06/10 13:39, En/na Steve Bryan ha escrit:
>> Hi
>>
>> As an alternative to loading template from the JSP - you could just submit
>> to a regular xmlpage (ie action="result.html"). In OpenCms 'html' pages are
>> not static and can run jsp code via the template.
>>
>> You could write a new template for this page or adapt the existing one, to
>> do the processing you describe, since the template can run sections of jsp
>> to check parameters etc.
>>
>
> I don't sure if I understand you. Do you mean I can put code in a
> xmlpage? If it is possible, how? I tried adding JSP code, but it didn't
> work. Or what you mean is that the xmlpage is associated with a template
> which can run code when it's loaded? If that's the case, I'm not sure I
> see the advantage. When I submit the form I want the submitted fields to
> be shown in the result page, there's nothing else, so the xmlpage would
> be empty and the template would hold all the JSP and HTML code to show
> the fields.
>
>> In our sites we never have jsps including template - we always have xmlpages
>> and these either include content elements, or run jsp, according to logic in
>> the main template controlled by page properties (eg 'jsp-body=xxx').
>>
>
> What is this jsp-body property? What do you do with it?
>
> Thanks,
> Àlex
>
>> Steve
>>
>> -----Original Message-----
>>
>> Date: Mon, 28 Jun 2010 13:41:43 +0200
>> From: Alexandre Magaz Gra?a<alexm at asic.udl.cat>
>> Subject: [opencms-dev] How to show a page with data submitted from a
>> form
>> To: opencms-dev at opencms.org
>> Message-ID:<4C288A77.3050901 at asic.udl.cat>
>> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>>
>> Hi,
>>
>> I have an HTML page (page with free text) with a form and I would like
>> the data submitted through it to be displayed in another page. My idea
>> was to have something like this in the HTML page:
>>
>> <form ... action="result.jsp">
>>
>> Then make the JSP process and display the submitted data. The thing is I
>> can't find any way of loading the template from the JSP so it looks like
>> any other page in the web site.
>>
>> Is there any way of doing this? Or is my approach just wrong?
>>
>> I'm using OpenCms 7.0.5.
>>
>> Thanks,
>> ?lex
>>
>>
>>
>>
>> _______________________________________________
>> This mail is sent to you from the opencms-dev mailing list
>> To change your list options, or to unsubscribe from the list, please visit
>> http://lists.opencms.org/mailman/listinfo/opencms-dev
>
>
> _______________________________________________
> This mail is sent to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list, please visit
> http://lists.opencms.org/mailman/listinfo/opencms-dev
>
> _______________________________________________
> This mail is sent to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list, please visit
> http://lists.opencms.org/mailman/listinfo/opencms-dev
More information about the opencms-dev
mailing list