0

I've got t:select with two values - CHANNELS, WIDGETS. If I choose first one, I will display palette with all channels and hide widgets palette (both in zones), if I select second one, I will hide channels palette zone and display widgets palette zone. Both palettes are pre-selected with items loaded up from database. Both selectedWidgets, selectedChannels are annotated as @Persist. Problem is that customer wants to delete selected widgets, then switch to channels and add them, so two operations. If he then saves, deleted widgets are still there and channels are added correctly. Is this is possible to solve it?

MartinC
  • 546
  • 11
  • 26
  • I also noticed that Persist persisted state as loaded from DB, not the actual selected state. Ok, I have deleted Persist annotation, now only problem is that I am loosing values in selected palette when switching by select. – MartinC Jul 11 '13 at 12:36
  • just to add, when the select is switched from value to other one, I do ajaxResponseRenderer.addRender() for both zones on the server side – MartinC Jul 11 '13 at 12:38

2 Answers2

1

If I understood correctly you need to save values for both palettes on form submission. So both palettes should present on the form.

To solve this you can just hide one palette and show another on select value change. No server-side operation is needed (and zones is not needed too):

<t:select t:id="select" .../>
<t:palette id="widgets" .../>
<t:palette id="channels" .../>

And js using jquery:

var $select = $('#' + selectId);
var $widgets = $('#' + widgetsId);
var $channels = $('#' + channelsId);

$select.on('change', function() {
  if ($select.val() == 1 /* or another value corespondent to channels */) {
    $widgets.hide();
    $channels.show();
  } else {
    $widgets.show();
    $channels.hide();
  }
});
sody
  • 3,731
  • 1
  • 23
  • 28
  • thanks sody. basically, I need to preserve values not only after form submission, but also when I switch palettes with select. That doesn't work for me – MartinC Jul 11 '13 at 12:51
  • Still don't understand what you need. If you need to save values to DB after select value changed you need to submit form. Or you can write js that will update your zone from url with additional request parameter populated from palette selected value. – sody Jul 11 '13 at 13:04
  • ok, I will explain again. Let us assume that Persist is disabled. Open the web page with elements described above and preload selected items from DB. E.g. 2 channels and 3 widgets. Initally, widgets palette is displayed, 3 items preselected and select value is WIDGETS. Then, I add 2 widgets and switch select to CHANNELS. what happens is: 1. channels is empty, there should be two 2. if I switch back to widgets, widgets is empty too – MartinC Jul 11 '13 at 13:12
  • in case I allow @Persist, then I always see values from DB after the switch, not the ones I select – MartinC Jul 11 '13 at 13:15
  • just to add to my example: 2. if I switch back to widgets, widgets is empty too, there should be 5 – MartinC Jul 11 '13 at 13:22
  • iF you don't need to save values to DB after each select value change the solution from my answer will work (all the values from both palettes will be saved in DB after form submission) – sody Jul 11 '13 at 13:34
  • I see. So I should get rid of zones and server-side stuff and link the short js file (I don't use jquery in project) to my page – MartinC Jul 11 '13 at 13:41
  • Im trying your solution, just a question. Will this work even if ids observed in code inspector are different? I mean "widgets" is "widgets_54564654654", etc. Thank you – MartinC Jul 12 '13 at 09:26
  • Do you have zone update in your code? If yes then you need to render your script with zone update. And you also need to bind actual components ids instead of static strings (widgets.getClientId()) – sody Jul 12 '13 at 11:15
  • yes, the form with all these elements is inside of a zone which is displayed on click and hidden when form is saved – MartinC Jul 12 '13 at 12:15
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/33358/discussion-between-martinc-and-sody) – MartinC Jul 12 '13 at 12:25
0

thanks to sody, I managed to solve this issue. First main part was to get rid of zones, just to have a form with components and submit whole thing once and second main part was to trigger the javascript mentioned by sody in the right time. If I get time, I will paste my tml, java and javascript code, I am sure someone will help me to clean it up.

MartinC
  • 546
  • 11
  • 26