PDA

View Full Version : setting initial value for a combo box


joemcglynn
01-27-2004, 10:21 AM
(using LPS2p)

I have a combo box (parentcombo). I am able to populate the list from my jsp/db. I am able to get the currently selected value in my senddata method.

How do I set the initially selected value in the combo box based on the value in the database (datasource)? The valid values include "null" if no value is already selected.

So, essentially I need to know how to:

1. Set the selected value in a list based on the value in another datasource

2. Deal with "null" if no value is selected

TIA

=========================================

<canvas bgcolor="#eaeaea" height="800" width="1200">
<font src="bitstream-vera-1.10/vera.ttf" name="contactsfont"/>
<font src="bitstream-vera-1.10/verabd.ttf" name="boldfont"/>
<font name="lztahoe8" src="lztahoe8.ttf"/>

<dataset name="mydata" src="http://localhost:8083/pmweb/getcomponents.jsp" autorequest="true"/>
<dataset name="parentcomponents" src="http://localhost:8083/pmweb/getparentcomponents.jsp" autorequest="true"/>
<dataset name="dsSendData" autorequest="false" src="http://localhost:8083/pmweb/componentmanager.jsp" type="http"/>


<resource name="tab_top_mid">
<frame src="art/top_btn_mid.swf"/>
<frame src="art/top_btn_mid_mo.swf"/>
<frame src="art/top_btn_mid_dn.swf"/>
</resource>

<resource name="tab_bot_mid" src="art/bot_btn_mid.swf"/>

<class name="row" height="30" bgcolor="0xE7E7D6" width="100%">

<attribute name="minheight" value="30"/>
<attribute name="maxheight" value="290"/>

<method name="sendData" args="action">
var d=canvas.datasets.dsSendData;
var p=new LzParam();
p.addValue( "action", action, true);
p.addValue( "id", open.id.getText(), true);
p.addValue( "componentName", open.componentName.getText(), true);
p.addValue( "componentStatus", open.componentStatus.getText(), true);

p.addValue( "developmentPlanned", open.developmentPlanned.getText(), true);
p.addValue( "developmentActual", open.developmentActual.getText(), true);
p.addValue( "docComplete", open.docComplete.getText(), true);
p.addValue( "testPlan", open.testPlan.getText(), true);
p.addValue( "qaComplete", open.qaComplete.getText(), true);
p.addValue( "notes", open.notes.getText(), true);
p.addValue( "engineer", open.engineer.getText(), true);
p.addValue( "tester", open.tester.getText(), true);
p.addValue( "parentComponentId", open.parentcombo.getValue(), true);
d.setQueryString( p );
d.doRequest();
</method>

<view name="small" font="contactsfont" fontsize="12" width="100%">
<basebutton resource="tab_top_mid" clickable="true" width="${parent.width}" stretches="both">
<method event="onclick">
if (classroot.height == classroot.minheight) {
classroot.open.setAttribute('visible',true);
newheight = classroot.maxheight;
} else {
classroot.open.setAttribute('visible',false);
newheight = classroot.minheight;
}
classroot.animate('height', newheight, 300);
</method>
</basebutton>

<text x="5" y="3" width="200" datapath="@componentName"/>
<text x="215" y="3" width="150" datapath="@componentStatus"/>
<text x="375" y="3" width="70" datapath="@developmentPlanned"/>
<text x="445" y="3" width="70" datapath="@developmentActual"/>
<text x="525" y="3" width="70" datapath="@testPlan"/>
<text x="605" y="3" width="70" datapath="@qaActual"/>
<text x="685" y="3" width="70" datapath="@docActual"/>
<text x="765" y="3" width="70" datapath="@engineer"/>
<text x="855" y="3" width="70" datapath="@tester"/>

</view>

<view x="10" name="open" width="100%" font="lztahoe8" visible="false">

<text name="id" visible="false" datapath="@id" x="-22" y="0"/>

<text y="10">Component Name:</text>
<edittext name="componentName" width="200" height="22" datapath="@componentName" x="140" y="5"/>
<text y="35">Component Status:</text>
<edittext name="componentStatus" height="22" datapath="@componentStatus" x="140" y="30"/>
<text y="60">Development Planned:</text>
<edittext name="developmentPlanned" height="22" datapath="@developmentPlanned" x="140" y="55"/>
<text y="85">Development Actual:</text>
<edittext name="developmentActual" height="22" datapath="@developmentActual" x="140" y="80"/>
<text x="285" y="85">Engineer:</text>
<edittext name="engineer" height="22" datapath="@engineer" x="340" y="80"/>
<text y="110">Test Plan:</text>
<edittext name="testPlan" height="22" datapath="@testPlan" x="140" y="105"/>
<text x="285" y="110">Tester:</text>
<edittext name="tester" height="22" datapath="@tester" x="340" y="105"/>

<text x="285" y="135">Parent Component:</text>
<!-- edittext name="parentComponent" height="22" datapath="@parentComponent" x="140" y="130"/ -->

<combobox name="parentcombo" x="285" y="135"
width="130"
defaulttext="choose one..." >
<textlistitem datapath="parentcomponents:/lookuplist/item" text="$path{'text()'}"
value="$path{'@value'}" />


</combobox>



<text y="135">Doc Complete:</text>
<edittext name="docComplete" height="22" datapath="@docActual" x="140" y="130"/>
<text y="160">QA Complete:</text>
<edittext name="qaComplete" height="22" datapath="@qaActual" x="140" y="155"/>
<text y="185">Notes:</text>
<edittext name="notes" multiline="true" width="400" height="80" datapath="@notes" x="140" y="180"/>

<button width="80" x="460" y="5">Update
<method event="onclick">
parent.parent.sendData("update")
parent.parent.datapath.updateData();
</method>
</button>

<button width="80" x="460" y="35">Delete
<method event="onclick">
parent.parent.sendData("delete")
parent.parent.datapath.deleteNode();
</method>
</button>

</view>

<simplelayout axis="y"/>

</class>

<view name="contactsborder" bgcolor="0x676767" x="40" y="40" height="580"
width="940" visible="false" oninit="this.setVisible(true)">

<text name="test" fgcolor="white" font="boldfont" fontsize="18" x="5" y="1">Series 60 Components</text>

<view name="header" fgcolor="white" font="boldfont" fontsize="12" y="20">
<text x="5" text="Component Name"/>
<text x="215" text="Status"/>
<text x="375" text="R/D Plan"/>
<text x="445" text="R/D Actual"/>
<text x="525" text="Test Plan"/>
<text x="605" text="QA Actual"/>
<text x="685" text="Doc Actual"/>
<text x="765" text="Engineer"/>
<text x="855" text="Tester"/>
</view>

<view datapath="mydata:/componentStatus" height="536" width="936" x="2" y="40" clip="true">

<view width="${parent.width-16}">
<row name="datarow" datapath="component">

</row>
<simplelayout axis="y"/>
</view>

<scrollbar axis="y"/>
<simplelayout axis="x"/>

</view>
</view>
</canvas>

antun
01-27-2004, 10:30 AM
I tested this in 2.0 (not 2.0p) but it should work in both. The combobox has a selectItem() method that you can use with the argument of the value attribute that you set here:


<textlistitem datapath="parentcomponents:/lookuplist/item" text="$path{'text()'}"
value="$path{'@value'}" />


I tried it as follows, but you can call the method from script when your other data comes back:


<button y="100">Select item with value item4
<method event="onclick">
mycombo.selectItem( "item4" );
</method>
</button>


-Antun

joemcglynn
01-27-2004, 10:52 AM
I added the following to my "open" view:

<method event="oninit">
// JavaScript code.
parentcombo.selectItem("1")
</method>

and I get errors in the debugger:

base/baselist.lzx:272: reference to undefined property 'subviews'
base/baselist.lzx:272: undefined object does not have a property 'length'
base/baselist.lzx:272: reference to undefined property 'length'

I'm downloading LPS2 - currently using the preview - to see if that helps.

What you are suggesting is that I can use the mycombo.selectItem(open.parentComponentId.getText( )) to set the "id" so that the correct value shows in the list?

antun
01-27-2004, 10:57 AM
What you are suggesting is that I can use the mycombo.selectItem(open.parentComponentId.getText( )) to set the "id" so that the correct value shows in the list?

I think so - but what exactly is parentComponentId in your app - is it a text field?

-Antun

joemcglynn
01-27-2004, 11:14 AM
Yes, it is a (hidden) text field.

I just installed LPS2, and I get the same errors as my last post.

The parentcombo should display a set of text items, with integers as the "value" (if I have the vernacular right). parentComponentId is an integer that corresponds to one of the items in the combo box.

note that in this version I have the selectItem() hardcoded to "1", which is a valid value - just to test selecting an item. When the code reads

<method event="oninit">
// JavaScript code.
Debug.write(open.parentComponentId.getText())
parentcombo.selectItem(open.parentComponentId.getT ext())
</method>

I still get the errors, but the correct (expected) values for parentComponentId are echoed in the debug window as follows:

--- debug window start ---
0
base/baselist.lzx:254: reference to undefined property 'subviews'
base/baselist.lzx:254: undefined object does not have a property 'length'
base/baselist.lzx:254: reference to undefined property 'length'
0
1
--- debug window end ---



Here is the complete source:

================

<canvas bgcolor="#eaeaea" height="800" width="1200">
<font src="bitstream-vera-1.10/vera.ttf" name="contactsfont"/>
<font src="bitstream-vera-1.10/verabd.ttf" name="boldfont"/>
<font name="lztahoe8" src="lztahoe8.ttf"/>

<dataset name="mydata" src="http://localhost:8083/pmweb/getcomponents.jsp" autorequest="true"/>
<dataset name="parentcomponents" src="http://localhost:8083/pmweb/getparentcomponents.jsp" autorequest="true"/>
<dataset name="dsSendData" autorequest="false" src="http://localhost:8083/pmweb/componentmanager.jsp" type="http"/>


<resource name="tab_top_mid">
<frame src="art/top_btn_mid.swf"/>
<frame src="art/top_btn_mid_mo.swf"/>
<frame src="art/top_btn_mid_dn.swf"/>
</resource>

<resource name="tab_bot_mid" src="art/bot_btn_mid.swf"/>

<class name="row" height="30" bgcolor="0xE7E7D6" width="100%">

<attribute name="minheight" value="30"/>
<attribute name="maxheight" value="290"/>

<method name="sendData" args="action">
var d=canvas.datasets.dsSendData;
var p=new LzParam();
p.addValue( "action", action, true);
p.addValue( "id", open.id.getText(), true);
p.addValue( "componentName", open.componentName.getText(), true);
p.addValue( "componentStatus", open.componentStatus.getText(), true);

p.addValue( "developmentPlanned", open.developmentPlanned.getText(), true);
p.addValue( "developmentActual", open.developmentActual.getText(), true);
p.addValue( "docComplete", open.docComplete.getText(), true);
p.addValue( "testPlan", open.testPlan.getText(), true);
p.addValue( "qaComplete", open.qaComplete.getText(), true);
p.addValue( "notes", open.notes.getText(), true);
p.addValue( "engineer", open.engineer.getText(), true);
p.addValue( "tester", open.tester.getText(), true);
p.addValue( "parentComponentId", open.parentcombo.getValue(), true);
d.setQueryString( p );
d.doRequest();
</method>

<view name="small" font="contactsfont" fontsize="12" width="100%">
<basebutton resource="tab_top_mid" clickable="true" width="${parent.width}" stretches="both">
<method event="onclick">
if (classroot.height == classroot.minheight) {
classroot.open.setAttribute('visible',true);
newheight = classroot.maxheight;
} else {
classroot.open.setAttribute('visible',false);
newheight = classroot.minheight;
}
classroot.animate('height', newheight, 300);
</method>
</basebutton>

<text x="5" y="3" width="200" datapath="@componentName"/>
<text x="215" y="3" width="150" datapath="@componentStatus"/>
<text x="375" y="3" width="70" datapath="@developmentPlanned"/>
<text x="445" y="3" width="70" datapath="@developmentActual"/>
<text x="525" y="3" width="70" datapath="@testPlan"/>
<text x="605" y="3" width="70" datapath="@qaActual"/>
<text x="685" y="3" width="70" datapath="@docActual"/>
<text x="765" y="3" width="70" datapath="@engineer"/>
<text x="855" y="3" width="70" datapath="@tester"/>

</view>

<view x="10" name="open" width="100%" font="lztahoe8" visible="false">

<method event="oninit">
// JavaScript code.
parentcombo.selectItem("1")
</method>


<text name="id" visible="false" datapath="@id" x="-22" y="0"/>
<text name="parentComponentId" visible="false" datapath="@parentComponentId" x="-22" y="0"/>

<text y="10">Component Name:</text>
<edittext name="componentName" width="200" height="22" datapath="@componentName" x="140" y="5"/>
<text y="35">Component Status:</text>
<edittext name="componentStatus" height="22" datapath="@componentStatus" x="140" y="30"/>
<text y="60">Development Planned:</text>
<edittext name="developmentPlanned" height="22" datapath="@developmentPlanned" x="140" y="55"/>
<text y="85">Development Actual:</text>
<edittext name="developmentActual" height="22" datapath="@developmentActual" x="140" y="80"/>
<text x="285" y="85">Engineer:</text>
<edittext name="engineer" height="22" datapath="@engineer" x="340" y="80"/>
<text y="110">Test Plan:</text>
<edittext name="testPlan" height="22" datapath="@testPlan" x="140" y="105"/>
<text x="285" y="110">Tester:</text>
<edittext name="tester" height="22" datapath="@tester" x="340" y="105"/>

<text x="285" y="135">Parent Component:</text>
<!-- edittext name="parentComponent" height="22" datapath="@parentComponent" x="140" y="130"/ -->

<combobox name="parentcombo" x="285" y="135"
width="130"
defaulttext="choose one..." >
<textlistitem datapath="parentcomponents:/lookuplist/item" text="$path{'text()'}"
value="$path{'@value'}" />



</combobox>



<text y="135">Doc Complete:</text>
<edittext name="docComplete" height="22" datapath="@docActual" x="140" y="130"/>
<text y="160">QA Complete:</text>
<edittext name="qaComplete" height="22" datapath="@qaActual" x="140" y="155"/>
<text y="185">Notes:</text>
<edittext name="notes" multiline="true" width="400" height="80" datapath="@notes" x="140" y="180"/>

<button width="80" x="460" y="5">Update
<method event="onclick">
parent.parent.sendData("update")
parent.parent.datapath.updateData();
</method>
</button>

<button width="80" x="460" y="35">Delete
<method event="onclick">
parent.parent.sendData("delete")
parent.parent.datapath.deleteNode();
</method>
</button>

</view>

<simplelayout axis="y"/>

</class>

<view name="contactsborder" bgcolor="0x676767" x="40" y="40" height="580"
width="940" visible="false" oninit="this.setVisible(true)">

<text name="test" fgcolor="white" font="boldfont" fontsize="18" x="5" y="1">Series 60 Components</text>

<view name="header" fgcolor="white" font="boldfont" fontsize="12" y="20">
<text x="5" text="Component Name"/>
<text x="215" text="Status"/>
<text x="375" text="R/D Plan"/>
<text x="445" text="R/D Actual"/>
<text x="525" text="Test Plan"/>
<text x="605" text="QA Actual"/>
<text x="685" text="Doc Actual"/>
<text x="765" text="Engineer"/>
<text x="855" text="Tester"/>
</view>

<view datapath="mydata:/componentStatus" height="536" width="936" x="2" y="40" clip="true">

<view width="${parent.width-16}">
<row name="datarow" datapath="component">

</row>
<simplelayout axis="y"/>
</view>

<scrollbar axis="y"/>
<simplelayout axis="x"/>

</view>
</view>
</canvas>