You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jipu Jiang <j....@nesc.gla.ac.uk> on 2008/11/12 19:36:29 UTC

Second box of DoubleSeclect tag wont show the default value even though it's right here.

Hello everyone,

Can anyone help me to solve this issue with doubleselect box of struts2?

I would like to display some database data on a page by using some struts2
tags. So we should go to the action class fist to fetch the data, then
dispatch the request to the jsp page when success. Everything shows up real
nice except the second list of the doubleselet tag. For example, I have a
list with all the countries, each of which contains a list of cities. E.g.
UK contains London, Manchester, Liverpool, Glasgow, etc (assume in such
order). So the doubleselect box will display countries as the first select
box, and related cities will display in the second select box. Then if the
Action class got UK and Liverpool, the doubleselect tag should display both
of them. But instead, the doubleselect tag shows UK as the first box, and
London as the second. When selecting other countries, same thing happens.
And it is always the first option in the second list to be displayed.

I have double checked the getter and setters for the double select list,
they are all good. And the jsp page can get these values. If anyone want to
see the code, please see the previous message below.

I have been struggling with this problem for many days. Could anyone point
me a path to solve this problem? It will be greatly appreciated.

Many thanks in advance,
Jipu 


On 11/11/2008 01:34, "Jipu Jiang" <j....@nesc.gla.ac.uk> wrote:

> Hi Felippe,
> 
> Thank you for your fast reply. I have double checked with what you have
> suggested. But the problem is still here.
> 
> Regarding to the situation, the second list contains all the options
> actually. If I show only the doubleselect box without default values to
> show, all the options are there. And if I change the selection of fist
> select box, the second one will change accordingly. This means the
> doubleselect box is up and running well.
> 
> But the problem is I have default values to show when user see the
> doubleselect box, and the default value for second list was not shown
> correctly (some option is selected, but not the right one).
> 
> For example, the first list contains countries, and second list contains
> associated cities. E.g. UK list contains Edinburgh, Oxford, London,
> etc.(in such order), and if the database stores a record with
> country=UK, and City=London, the doubleselect list should display the
> fist list as UK, and second list as London. But the problem is the first
> list can show UK, while the second list show only the first one in the
> tertiaryoptions list. As in this example, it shows Edinburgh - the fist
> element of the second list. And it supposes to show London - the third
> one of second list..
> 
> In this implementation, I have the action class contains identifier
> variable, and associated getters and setters. In the JSP, I set the name
> of doubleselect tag to be "%{'identifier.' + paramName}", so when the
> page renders, the value in identifier variable can be shown directly on
> the page. I have tested this with textfield, checkbox, select, etc. they
> all worked fine to show default values, except the doubleselect tag.
> 
> I wonder is anything wrong with my implementation, or doubleselect list
> just don't have such ability?
> 
> Another guess I had is the Javascript used in doubleselect tag. The
> second select list is actually generated by javascript. This might be
> the reason to cause above issues. May be I've been paranoid?
> 
> Anyway, I have been stuck with this issue for a long time now. Still
> cant figure out why. Your help would be very much appreciated.
> 
> Thanks again Felippe,
> 
> Cheers,
> Jipu
> 
> -----Original Message-----
> From: Felippe Scheidt [mailto:felippescheidt@gmail.com]
> Sent: Monday, November 10, 2008 8:17 PM
> To: Struts Users Mailing List
> Subject: Re: HELP!!! DoubleSeclect tag with default values
> 
> Hi Jipu,
> 
> Well, if i understood correctly, the second list, "tertiaryoptions" is
> been
> completed with only one city, and there is another cities of course. The
> doubleselect tag bind the two lists behind through ValueStack. For this
> works correctly, verify the first list, "menu.menuoptions". This is
> probably
> a list of MenuOption. Verify if MenuOption contains a list of
> tertiaryoptions, something like this:
> public class Menuoption{
> ...
>   List<TertiaryOption> tertiaryoptions;
> ...
> }
> 
> This is a way to doubleselect binds this two collections.
> 
> Felippe.
> 
> 
> 
> On Mon, Nov 10, 2008 at 2:33 PM, Jipu Jiang <j....@nesc.gla.ac.uk>
> wrote:
> 
>> Hi Felippe,
>> 
>> Thank you so much for the response. Sure, here is the code:
>> 
>> JSP:
>> 
>> <s:form id="editRecordForm" action="updateRecord" theme="simple">
>>        <table class="query-page-table">
>>                <tr>
>>                        <s:iterator value="sections" id="sec"
>> status="secs">
>>                                <table class="section-table">
>>                                        <tr>
>>                                                <td colspan="3">
>>                                                        <h3>
>> 
>> <s:property value="name" />
>>                                                        </h3>
>>                                                </td>
>>                                        </tr>
>> 
>>                                        <s:iterator value="parameters"
>> id="para" status="paras">
>>                                                <tr>
>>                                                        <td
>> class="parameter-label">
>> 
>> <s:property value="label" />
>>                                                        </td>
>>                                                        <td>
>>                                                                <s:if
>> test="type == \"menu\"">
>> 
>> <s:set name="menuoptions" value="menu.menuoptions"></s:set>
>> 
>> <s:set name="tertiaryParamName"
> value="menu.tertiaryParamName"></s:set>
>> 
>> <s:if test="menu.tertiary == 1">
>> 
>> <s:doubleselect name="%{'identifier.' + paramName}"
>> 
>> headerKey="" headerValue="--- Please Select ---"
>> 
>> list="menu.menuoptions" listKey="value" listValue="value"
>> 
>> doubleId="%{'editRecordForm_identifier_' + menu.tertiaryParamName}"
>> 
>> doubleName="%{'identifier.' + menu.tertiaryParamName}"
>> 
>> doubleList="tertiaryoptions" doubleListKey="name"
>> 
>> doubleListValue="name" />
>> 
>> </s:if>
>> 
>> <s:else>
>> 
>> <s:select name="%{'identifier.' + paramName}"
>> 
>> listKey="value" label="%{para.label}" list="menu.menuoptions"
>> 
>> listValue="value" emptyOption="false" headerKey=""
>> 
>> headerValue="--- Please Select ---" theme="simple" />
>> 
>> </s:else>
>>                                                                </s:if>
>>                                                        </td>
>>                                                </tr>
>> 
>>                                        </s:iterator>
>>                                </table>
>>                        </s:iterator>
>>                </tr>
>>                <tr>
>>                        <td colspan="3" align="right">
>>                                <br />
>>                                <s:submit value="Update Record"
>> theme="simple"></s:submit>
>>                                <s:reset theme="simple"></s:reset>
>>                        </td>
>>                </tr>
>>        </table>
>> 
>> </s:form>
>> 
>> 
> ------------------------------------------------------------------------
>> Here is the updateRecordView Method in the UpdateRecordAction.java:
>> 
>>        public String updateRecordView() throws Exception {
>>                try {
>>                        this.sections =
>> this.parameterManager.getSections();
>>                        this.identifier =
>> this.identifierManager.getIdentifierByRegisterId(this.id);
>>                        return SUCCESS;
>>                } catch (CannotCreateTransactionException e) {
>>                        log.error("CannotCreateTransactionException:
>> Hibernate transaction exception!!! Timeout.");
>>                        e.printStackTrace();
>>                        return EXPIRE;
>>                } catch (Exception e) {
>>                        log.error("Exception caught in
>> readRecordView()!!!");
>>                        return ERROR;
>>                }
>>        }
>> 
>> 
>> User access goes to updateRecordView action first, and fetch data from
>> database. If successful, it goes to the jsp page to show the
> parameters
>> and associated values. But the doubleselect tag shows only the value
> of
>> fist select box, second box shows the first option in from the list,
> not
>> the one suppose to display.
>> 
>> Any help would be much appreciated.
>> 
>> Many thanks,
>> Jipu
>> 
>> -----Original Message-----
>> From: Felippe Scheidt [mailto:felippescheidt@gmail.com]
>> Sent: Monday, November 10, 2008 12:22 PM
>> To: Struts Users Mailing List
>> Subject: Re: HELP!!! DoubleSeclect tag with default values
>> 
>> Can you paste your code please?
>> 
>> Scheidt.
>> 
>> 
>> On Mon, Nov 10, 2008 at 9:04 AM, Jipu Jiang <j....@nesc.gla.ac.uk>
>> wrote:
>> 
>>> Dear all,
>>> 
>>> I was trying to display a JSP page with some parameters from the
>>> database. Everything shows up perfectly except the second dropdown
>> list
>>> of the doubleselect tag, which should display the value from java
>> action
>>> but it always shows the first value of the second list.
>>> 
>>> For example, the first list contains countries and the second list
>>> contains cities. E.g. if I select UK from the first select box, the
>>> second should be London, Birmingham, Edinburgh etc.
>>> 
>>> Now the default values of the select boxes depend on what's in the
>>> database. I can get the first select box to show UK, but the second
>> one
>>> always shows London, which is the first one in the second list.
>> Instead,
>>> it should show other cities based on values in database.
>>> 
>>> I guess it's because of javascript. Does anyone know how to deal
> with
>>> such problem?
>>> 
>>> Also, when I assign values to the doubleHeaderKey and
>> doubleHeaderValue
>>> of doubleselect tag, the second select box shows no header at all.
> How
>>> can I make this work?
>>> 
>>> Many thanks in advance,
>>> Jipu
>>> 
>>> 
> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>> 
>>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>> 
>> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org