FillSelect and populating other fields

X-Application Version: 3.1.2
Tamino Version : 3.1.1
Platform : Win2k,
WebContainer : iPlanet 6
JDK Version : 1.3.1.01

Is there a way to use the FillSelect with an onChange event to populate hidden fields with data corresponding to the selected item?

For example, I have a DTD as follows:






I’d like to display the Short_Name in the selection box and upon making a selection, I’d like to populate editable fields with the corresponding Text associated with the selected Short_Name.

Is there a way to do this using the tags provided? Any help would be appreciated.

Regards,
Michelle

Hello Michelle,

I can give you a sketch how I would try to implement it. My proposal is:


  • create a page ‘standardtext.jsp’ containing a HTML form with id=?selectForm? and action=?standardtext.jsp?. The form should contain two hidden fields with
    a) the name :action and value read
    b) the name :docid without value
    Furthermore, add a HTML select field to your form. Use X-Applications select tag to fill the box with the Short_cuts values of your Standard_Text documents. Have a look at the contribution form of X-Application. My colleague sent this tag and examples it to replace the old fillselect tag of X-Application.

  • add the onChange event to the HTML select tag with JavaScript function for sending the form and setting the value :docid. It could look like this

    value = // get the text from the select tag
    document.forms[‘selectForm’].elements[’:docid’].value=’/Standard_Text[Short_Cut=?? + value + ?]’;
    document.forms[‘selectForm’].submit()

  • add a display part where you check if a document is available and if yes where you show the content.

    <bdm:if condition=?exists? select=?/StandardText/Text?>
    Text : <bdm:display select=?/StandardText/Text?/>
    </bdm:if>



Remarks:

  • Set the coding parameter within the web.xml file to false because you use the request parameters :action and :docid.
  • Filling the select tag is used every time when you select a new document (StandardText). could be optimized by using frames.
  • The code works only if the short_cut is a key value for your document.
  • To allow the modification of the Text of your StandardText, use directcommand (type=modify), action (type=commit) and edit tags within the display part.


If there are problems when implementing it, sent a new post.

Thanks,
Christian.

Thanks Christian for the reply. I implemented a page as you suggested, but received an error which I’ve pasted below.

Is there a way to do this without having to reload the page? I was thinking of something along the lines of populating a client-side Javascript array that matches the values in the selection list. The client I am working with would like the ability to make a selection using the Short_Text and populate another text box with the corresponding full Text.

I understand the suggested implementation of using the key that was selected and going back to Tamino for the full text, but is there a way to load that data into an array on the client-side to avoid going back to the server?

Thanks for the help!
Michelle


Error received:

Internal error: servlet service function had thrown ServletException (uri=/text/testpage3.jsp): javax.servlet.ServletException: 157: Exception when creating query., stack: javax.servlet.ServletException: 157: Exception when creating query.
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:453)
at _jsps._testpage3_jsp._jspService(_testpage3_jsp.java:262)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:240)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.access$6(JspServlet.java:230)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:511)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:582)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.iplanet.server.http.servlet.NSServletRunner.invokeServletService(NSServletRunner.java:887)
at com.iplanet.server.http.servlet.WebApplication.service(WebApplication.java:1045)
at com.iplanet.server.http.servlet.NSServletRunner.ServiceWebApp(NSServletRunner.java:951)
, root cause: DesignException: 157: Exception when creating query.
com.softwareag.xtools.xapplication.store.StoreException
collection for the doctype ‘’ is not registered.
at com.softwareag.xtools.xapplication.store.TaminoStore.getRegisteredDoctypeCollection(TaminoStore.java:865)
at com.softwareag.xtools.xapplication.store.TaminoStore.readTsd(TaminoStore.java:1317)
at com.softwareag.xtools.xapplication.businessdocument.Schema.read(Schema.java:152)
at com.softwareag.xtools.xapplication.businessdocument.SchemaCache.lookup(SchemaCache.java:70)
at com.softwareag.xtools.xapplication.businessdocument.BusinessDocumentWorkspace.query(BusinessDocumentWorkspace.java:176)
at com.softwareag.xtools.xapplication.jsp.SessionContext.setQuery(SessionContext.java:497)
at com.softwareag.xtools.xapplication.jsp.taglib.ModuleTag.doStartTagCore(ModuleTag.java:134)
at com.softwareag.xtools.xapplication.jsp.JspTag.doStartTag(JspTag.java:120)
at _jsps._testpage3_jsp._jspService(_testpage3_jsp.java:73)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:240)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.access$6(JspServlet.java:230)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:511)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:582)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.iplanet.server.http.servlet.NSServletRunner.invokeServletService(NSServletRunner.java:887)
at com.iplanet.server.http.servlet.WebApplication.service(WebApplication.java:1045)
at com.iplanet.server.http.servlet.NSServletRunner.ServiceWebApp(NSServletRunner.java:951)

Hello Michelle,

the reason for the exception seams to be that you address a doctype within your query which is not registered within the web.xml file of your application.

If ?Standard_Text? is the root of your document, you must register which collection is used to store document of this doctype. If Standard_Text is not your document root, you must define queries starting from the root element. E.g.

/Root[SubElement/Standard_Text/Shot_Name=?XYZ?]

Concerning your question about preloading the text into a JavaScript array, you can use the Browse tag if Standard_Text is the root of your documents. For example:




var textArray = new Array(
<bdm:directcommand document=?stdTextList? type=?query? … queryparm=?Short_Name~=*?/>
<bdm:browse document=?stdTextList? … pagesize=?100000?>
?<bdm:display select=?/Standard_Text/ShortName?/>?, ?<bdm:display select = ?/Standard_Text/Text?
</bdm:browse>
),




Remark:


  • directcommand of type query loads document lists. It must be enclosed by a form tag (see documentation).
  • if Standard_Text is not the document root you have to use a browse tag with enclosed loop (see also documentation and simple examples for loop and browse tag).


I have never tried out to create JavaScript Code with our JSP tags, but I don?t see any reason why it should not work.

Good look,
Christian.

Christian,

Thanks so much for your help. I was able to use the directcommand and browse tags to load a Javascript array. I also used the $POS parameter to help load proper occurrence of the array. Now, based upon the selection from the select box, I can switch the text accordingly.

Again, many thanks!
Michelle

Hello Michelle,

nice to hear that it works.

I don’t know your project and if it is allowed to give more information about it.

When reading your mail it came into my mind to ask you if it could be possible to send a small sample of your realization to the community.

Perhaps, if we have the time, we could extend the simple examples of X-Application for the next version by the use case you implemented.

Thank you,
Christian.

Hi Christian, I’d be happy to post a sample of what I did. First, I’m using two schemas, one (Service_Agreement) which I’ll modify and update Tamino, the other (Standard_Text) I will just read from to fill a selection box.

The attached page only shows the use of the directcommand and browse to load the Standard_Text and populate a Javascript array. The code can be plugged into the main page where Service_Agreement is used.

Enjoy!
Michelle

P.S.
A quick question: When storing the data from a textarea field, do you happen to know how to maintain line breaks and returns? So when the page accessed again, the data that was stored into Tamino will have line breaks and returns as entered. Any help would be appreciated.
testpage4.jsp (2.19 KB)

Hello Michelle,

thanks for your example. I will make a link to this topic from the contribution list. For the next version of X-Application we check how to integrate it into the simple examples.

Line Breaks within Content Fields

When you enter a text containing line break and spaces at the end of beginning of the text, the text is correctly stored within Tamino. If use the display tag without rawContent=?true? (the default). The text is trimmed. Using rawContent=?true? does not trim the text. If you fill your textarea with this display option the original line breaks should appear.

Remark: X-Application does not replace line breaks by
tags. If you want to display line breaks within HTML pages and

 are candidates to do this.

Bye,
Christian.