javadev-chiennx / struts2-jquery-plugin

Automatically exported from code.google.com/p/struts2-jquery-plugin
0 stars 0 forks source link

Second example about loading second selectbox by reloadTopic does not work #10

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create one selectbox that would be fired by some publisher

<sj:select id="secondSelect" reloadTopics="firstSelectChanged"
src="secondSelect.action"/>

"Fired when firstSelectChanged is pulished"

2. Debug actions to see if src is being called. Mine is not. It's calling
the page action, not the src parameter action.

What is the expected output? What do you see instead?
Expected: right action called and select box filled with options
See: First Page Action called and no select box filled

What version of the product are you using? On what operating system?
struts2-jquery-plugin 1.0.3
Firefox 3.5
struts 2.1.6
java 1.6.13

Please provide any additional information below.

Another example with problems:

1. Same as before.

2. Create a method in first action to answer type text/html to send an json
string: {"key":"value"}

3. select box is filled with just one line with the string (Expected: many
options in select box)

Original issue reported on code.google.com by andrew.b...@gmail.com on 2 Aug 2009 at 3:30

GoogleCodeExporter commented 8 years ago
I've fixed some problems associated with this sample.
- I've updated the sample on the home page to include the 'elementId' attribute 
on
the secondSelect (required to submit the firstSelect's value) and i've added the
'name' attribute to the first select (required to submit the name/value request
parameter for the first select).
-I've also updated the source and downloads (new version 1.0.3.1) to fix an 
issue in
which the SelectTag was not rendering the elementId attribute properly although 
I'm
not sure if that's what you were running into.

I'm can't find any issues with the json string filling the select boxes. are 
you sure
you're retuning a proper json object string. I'm using the json result 
available in
the struts2-json-plugin. My action config for the select box src actions looks
something like:

{{{
         <action name="firstSelect" class="com.apposit.blank.control.SelectAction"> 
            <result type="json" name="success">
                <param name="root">firstSelectList</param>
            </result>
            <result type="httpheader" name="error">
                <param name="error">500</param>
                <param name="errorMessage">${message}</param>
            </result>
         </action>

        <action name="secondSelect" class="com.apposit.blank.control.SelectAction" > 
            <result type="json" name="success">
                <param name="root">secondSelectList</param>
            </result>
            <result type="httpheader" name="error">
                <param name="error">500</param>
                <param name="errorMessage">${message}</param>
            </result>
         </action>
}}}

For my tester sample, 'firstSelectList' and 'secondSelectList' are simple
List<Integer> fields of the SelectAction. The SelectAction action also declares 
a
'firstSelect' with setter to receive the updated value of the first select field
(used to determine new list value for second select box).

The jsp page code looks like this:

<div> 
         First Select:<sj:select id="firstSelect" name="firstSelect"
onChangeTopics="firstSelectChanged" src="firstSelect.action"/>
        </div>
        <div>
         Second Select:<sj:select id="secondSelect" reloadTopics="firstSelectChanged"
src="secondSelect.action" elementIds="firstSelect"/>
        </div>

If you're still having problems perhaps you could send me some sample code or I 
could
send you a simple sample I'm using...

Original comment by obinna@gmail.com on 4 Aug 2009 at 10:30

GoogleCodeExporter commented 8 years ago

Original comment by obinna@gmail.com on 11 Aug 2009 at 7:53

GoogleCodeExporter commented 8 years ago
where I can see some examples about how the action class firstSelect and 
secondSelect
looks?

Original comment by mileid...@gmail.com on 11 Aug 2009 at 11:50

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Found the solution, here is the code:

public class SelectAction {

    private Map<String, String> map = new HashMap<String, String>();
    private String firstSelect;

    public Map<String, String> getMap() {
        return map;
    }
    public void setMap(Map<String, String> value){
        map = value;
    }   
    public void setFirstSelect(String firstSelect) {
        this.firstSelect = firstSelect;
    }

        public String getFirstSelect(){
        for (int i = 0; i < 10; i++) {
            map.put(String.valueOf(i), String.valueOf(i));
        }
        return Action.SUCCESS;
    }

    public String getSecondSelect(){
        for (int i = 0; i < 10; i++) {
            map.put(String.valueOf(i), firstSelect + " - " + String.valueOf(i));
        }
        return Action.SUCCESS;
    }
}

Original comment by mileid...@gmail.com on 11 Aug 2009 at 3:12

GoogleCodeExporter commented 8 years ago
Hi, 

I have problems to adapt this sample to my code. Here is what I'd like to do :
http://groups.google.com/group/jquery-en/browse_thread/thread/1560b8227e55521e#

My struts.xml file doesn't accept this syntax :

<action name="firstSelect" class="com.apposit.blank.control.SelectAction"> 
            <result type="json" name="success">
                <param name="root">firstSelectList</param>
            </result>
            <result type="httpheader" name="error">
                <param name="error">500</param>
                <param name="errorMessage">${message}</param>
            </result>
         </action>

An idea on how to proceed ?

Original comment by sii.nben...@gmail.com on 24 Sep 2009 at 9:03

GoogleCodeExporter commented 8 years ago
Hi,

I have got somthing similar requirement. On a jsp i have search criteria and 
one struts2 jquery grid to display search results.
1. On page load the grid fires call to one action automatically to load the 
default result.
2. My query is when i click on search button the grid should get populated 
according as per the search criteria.

would appreciate if some one can help in this, i heard some thing of 
relaodTopics...

Original comment by mratyunj...@gmail.com on 27 Oct 2010 at 2:09