Assume I have a table of N rows with two columns. I will have one checkbox on column-1 and zero or more on column-2. Column-1 may represent categories and column-2 represents associated things. Just like below:
Now user can select EJB and Hibernate of first row, HDTV of the third row, and no value from second row and submit
Now I'm looking at adding EJB and Hibernate to a list and add that list to a map with Books as Key. In the same way HDTV to a list and Electronics as the Key.
I tried to accomplish the above thing with the below code, but I actually ended up with a Map with three keys, Books, Foods and Electronics and for each corresponding key, all the elements in the list.
Can some one guide me about this problem.
[ August 07, 2008: Message edited by: Schandha Ravi ]
[ August 07, 2008: Message edited by: Schandha Ravi ]
There's a lot of Java in that JSP (bad bad idea) so it's hard to see what's going on.
Are you expecting JSP code to execute as a result of the onclick event? If so, that can't happen.
Bear, I too agree with you regarding the usage of that much java in jsp. I'll try to use Expression Language and tags instead.
But as you mentioned, if we can't get JSP code executed as a result of onClick event, can you suggest me an alternative to accomplish the same.
I should be able to send the servlet with information about categories and the corresponding items selected , when submit button is clicked.
I do have couple of constraints here.
1) I can't use Ajax. Its out of scope and not considered at this stage in project.
2) Calling server in the event handler, sounds good, but it results in multiple trips to the server as there could be N number of check boxes and multiple checks.
Initially I thought, what I was looking at is quite simple but apparently that is not the case here .
How would these typical advertisement pages work? I mean, all those web pages, where in customer is opted to select one or more options for multiple categories. Can't we cache all the selections and corresponding categories ,map each category to the collection of items selected, bundle all of them together and send to servlet all at a time at one single click.
Am I over ambituous
Let me try to make my question more clear here.
I get the following details from the servlet as session attributes
A) Categories which is an ArrayList
B) Items which is a Map. Each element of Category has a corresponding Arraylist of items.
Categories - Books, Foods, Electronics
Books - HFSJ , RJB, Hibernate
Foods - Pizza, Muffins
Electronics - HDTV, Laptops
In a table of two columns, categories goes on first column, Items on second column and each represented by a check box.
Now as a user we can select any of these checkboxes to show our interest. Say I'm intersted in Pizza and Laptops. So I select Pizza and Laptops and it implies that we selected Foods and Electronics too.
Now upon submit the form only once, I should be able to send only
Foods - Pizza
Electronics - Laptops.
We may be able to navigate through request parameters in servlet , but it does not tell us what maps to what. There should be a way servlet should map Pizza to Foods and Laptops to electronics.
This is what I'm trying to achieve. I know that I might be complicating things here with my logic. But if you can guide me anything better, that would be great. Thanks in advance.
Note : We would not be aware what categories and items are displayed in advance. Those are dynamic.
yes servlet would have the info that Pizza belogs to Food. But Food may contain the other information like Muffins or Bread. But user may not be selecting them. And more over for the servlet, also would not generate this information. It gets from some other service as a collection. So , I'm not able figure out that ok out of these many items, not every thing is selected, only few of the choices are selected and those are related to one particular category.
If my question is too confusing, would you mind letting me know, how do I get problem solved. I'm sure there is some link which I'm missing.
After going through the entire conversation, I get a feeling to have my below code checked, for its design. Would some one mind to look into this and provide me the feedback. I used few jsp codes in onclick events. I should say this is working fine, but wanted to see if it is appropriate or not.
As I mentioned earlier , I have this table with two columns 1 and 2 with check boxes present. For each row, I should have column-2 displayed only when the check box of column-1 is clicked. When it is unchecked , column2 should be invisible. To achieve this, I coded as below
With the above code, I was able to get what I was looking at.
As you mentioned
It isn't clear to me why the client has to tell the server that Pizza is in the Food category, when the server already has that information.
It makes me think that, I can try to compare the request parameter values with the values available to the servlet. I believe this may lead to solution. However, I'm just thinking if it would make my servlet fatter (Ofcourse I do not want my jsp fatter too ).
But I'm just curious to know if there is a way we can bunch all the selected values as one single entity and send them as a request parameter.
I'm extremely sorry If I'm asking the same question again and again... still a long to go for me in this technology