0

I have a form like this:

<form id="form" method="post">
    Name: <input name="name" />
    E-Mail: <input name="email"/>
    Comment: <textarea name="comment" cols="5" rows="10"></textarea>
    <input type="submit" name="submit" value="submit"/>
</form>

for a commentary function for some developer blog. Therefore I need to insert the input into some database for some select queries later.

Now how do I tell the script which comments belong to which blog post?

My idea would be to get the name of the file or the title of the entry or something and put it into the query I'm creating. And I might manage to find out how to get the filename in OpenCMS as well - that's about five minutes of searching, if any - but what I don't know is how I get the OpenCMS variable into my Java part of the file, where I set up the actual query/queries.

I searched for that earlier already, some weeks ago, but I managed to find a way to avoid this then. Now though I can't think of a way of avoidance either, so I'm hoping that someone knows how to get this done properly.

In case you need this, here's the code for the actual blog entries so far, I'm going to append the commentary function (being an element) underneath the author information then.

                <cms:contentcheck ifexistsone="Header"><h2><cms:contentshow element="Header" /></h2></cms:contentcheck>
                <p class="BlogEntry">
                <cms:contentcheck ifexistsone="Text"><cms:contentshow element="Text" /></cms:contentcheck>  
                <cms:contentcheck ifexistsone="IntLink"><%@ include file="/system/modules/de.medienkonzepte.uform.templates/elements/internerlink.txt" %></cms:contentcheck>
                </p>
                <cms:contentcheck ifexistsone="Image">
                    <cms:contentloop element="Image">
                        <img style="padding:10px;" src="<cms:link><cms:contentshow element="ImageSrc" /></cms:link>" alt="<cms:contentshow element="Alt_Tag" />" />
                    </cms:contentloop>
                </cms:contentcheck>

            </cms:contentloop>
        </cms:contentcheck>
                 <cms:contentcheck ifexistsone="Content/Text">

        <c:set var="dateString"><cms:contentshow element="Date"/></c:set>
        <% 
         java.util.Date date = new java.util.Date(); 

         date.setTime(Long.parseLong(pageContext.getAttribute("dateString").toString())); 
         pageContext.setAttribute("date", date); 
        %>                  

                <% // Author %>
                <cms:contentcheck ifexistsone="Author"><p class="blogentry_author">Written by: <cms:contentshow element="Author"/> on <fmt:formatDate value="${date}" type="date" pattern="dd.MM.yyyy"/></p></cms:contentcheck>

        </cms:contentcheck> 
    </div> <% // ende innercontent %>
Gilles 'SO- stop being evil'
  • 104,111
  • 38
  • 209
  • 254
SuperbiaRook
  • 13
  • 2
  • 7

1 Answers1

0

a commentary function for some developer blog

Is the user on the detail page of the blog entry (only this one entry for the entire page), with a comment form at the bottom, as very common, i.e. in Wordpress blogs? Or is it a page with multiple blog entries on it?

If you're on the detail page, you can get the current filename right away with java code:

CmsJspActionElement cms = new CmsJspActionElement(pageContext, request, response);
String filename = cms.getRequestContext().getUri();

but what I don't know is how I get the OpenCMS variable into my Java part of the file, where I set up the actual query/queries.

<c:set var="filename" scope="request">output your OpenCms variable in here</c:set>

Then you can access the filename variable via

 request.getAttribute("filename")

Where are you doing the query? Right in jsp or in a java class? But doesn't matter much, you can just pass the request as parameter to it. This is a way to do it:

Mathias Conradt
  • 28,420
  • 21
  • 138
  • 192