How to pass text-field value in JSP to tolog query?

270 views
Skip to first unread message

Siriporn Chongpratheep

unread,
Jan 4, 2014, 11:11:49 AM1/4/14
to ont...@googlegroups.com
Dear Expert,

I create a simple search page in jsp with one text field and a submit button. After submit the button, the value in text field should be passed to another jsp page to use as variable in tolog query. However, my code doesn't work. I'm not sure it's because the way of passing variable is not correct or it's because my LTM file contains numerical ID value (I exported it from Ontopoly and it's just like this.) Here is my code. Please advise.

Thanks

Quintin Siebers

unread,
Feb 20, 2014, 7:18:10 AM2/20/14
to Ontopia Mailing List
Dear Siriporn,

Assume your form submits the following to the list.jsp:

name=somevalue

Then in your list.jsp the following happens:

line 8: String name = request.getParameter("name") 
name is set to  "somevalue"

line 11: <tolog:set var="<%= name %>" reqparam="id"/>  
You instruct Ontopia to store a variable named 'somevalue' (the result of <%= name %>) with the value of whatever is stored in the 'id' request parameter (which is null): the tolog variable somevalue is set to null 

line 19: <tolog:if query="id37(%name% : id159, $CI : id213)?">
You instruct Ontopia to query the topicmap for all associations of type id137 that have two roles. The constraint for the first role specifies the use of a variable 'name' which does not exist, because you haven't set it. 

 The reason why this happens is because you've set the variable 'somevalue' instead of 'name'. I guess that what you meant to do was: 

<tolog:set var="name" reqparam="name"/>

With the provided example this would result in a variable 'name' being set to 'somevalue'. This will lead you to the next problem. Unless 'somevalue' is a valid id of a topic, the query will fail telling you it was expecting a topic but found a String. 

If you truly want to query for the name of a topic I suggest a query like:

<tolog:query name="myquery">
topic-name($topic, $topicname),
value($topicname, "<%= request.getParameter("name") %>"),
id37($topic : id159, $CI : id213)?
</tolog:query>
<tolog:if query="myquery"> ... </tolog:if>

And finally: note that you can combine your two foreach tags into one:

<tolog:query name="myquery">
topic-name($topic, $topicname),
value($topicname, "<%= request.getParameter("name") %>"),
id37($topic : id159, $CI : id213),
id227($CI : id213, $CN : id191)
order by $CI, $CN?
</tolog:query>
<tolog:foreach query="myquery"> ... </tolog:foreach>

With regards,

Quintin Siebers

--
(+31) (0)6 - 11 06 16 27


Morpheus Kennistechnologie BV
<URL: http://www.mssm.nl >
postbus 69
3500 CD Utrecht
KVK 30 26 04 30

--
You received this message because you are subscribed to the Google Groups "ontopia" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ontopia+u...@googlegroups.com.
To post to this group, send email to ont...@googlegroups.com.
Visit this group at http://groups.google.com/group/ontopia.
For more options, visit https://groups.google.com/groups/opt_out.

Siriporn Chongpratheep

unread,
Feb 28, 2014, 4:51:39 AM2/28/14
to ont...@googlegroups.com
Dear Quintin,

Thank you very much for your suggestion.

I try following your guide and now I can pass the value from field "name" (from HTML Form) into tolog variable assigned in JSP which is hereby called "charname".

However, I still have problem with the query method because the query result is not shown.

The context is I will input the cartoon character name into the field "name" in HTML Form, then the result in JSP should list all "costume-item" worn by "charname" which is connected with a relationship "wears". 
Please see my code below.


(list.jsp)


Your suggestion will be highly appreciated.

Thank you very much.
Siriporn

Quintin Siebers

unread,
Feb 28, 2014, 5:55:29 AM2/28/14
to Ontopia Mailing List
Dear Siriporn,

You are asking Tolog for names with the exact value "charname", not the value stored in the variable charname. You can fix this with:

value($character-name, %charname%),

With regards,

Quintin Siebers

--
(+31) (0)6 - 11 06 16 27


Morpheus Kennistechnologie BV
<URL: http://www.mssm.nl >
postbus 69
3500 CD Utrecht
KVK 30 26 04 30

Siriporn Chongpratheep

unread,
Feb 28, 2014, 3:17:11 PM2/28/14
to ont...@googlegroups.com
Dear Quintin,

I tried following your guide and there is no syntax error now, but the query result is not correct. Is this because of my topicmap itself?
I also attached the topic map file in case that you may want to see.

Below are my code and the result page.


Thanks

Siriporn
cartoononto_test2.ltm

Quintin Siebers

unread,
Mar 5, 2014, 9:15:46 AM3/5/14
to Ontopia Mailing List
Dear Siriporn,

The variable 'character-name' is your query is not bound, making your second query line completely redundant. Your query now asks Ontopia to give all topics of type 'character-name' and all the items that those topics 'wear.' Of that result you only display the first hit (which is a randomly chosen value).

I suggest you carefully read the documentation [1] on each of the used query predicates and how variable bindings work [2].


Quintin Siebers

--
(+31) (0)6 - 11 06 16 27


Morpheus Kennistechnologie BV
<URL: http://www.mssm.nl >
postbus 69
3500 CD Utrecht
KVK 30 26 04 30

<cartoononto_test2.ltm>

Siriporn Chongpratheep

unread,
Mar 5, 2014, 10:01:17 AM3/5/14
to ont...@googlegroups.com
Dear Quintin,

Thank you very much for your guidance.

I will study those docs carefully.

Regards,
Reply all
Reply to author
Forward
0 new messages