0

I'm working on a jsp containing some checkboxes. My jsp is linked to a form (called SuiviTransfertForm), and this form has an attribute called checkboxUID, which is an array containing the ids of my checked checkboxes.

private String[] checkboxUID = {};

This attribute is mapped with the checkboxes of my jsp like this :

<html-el:multibox name="suiviTransfertForm" property="checkboxUID"/>

I would like to follow a link on this jsp and get the content of checkboxUID when I'm on the next page.

On the next page, I'm getting back my form like this :

SuiviTransfertForm suiviTransfertForm = (SuiviTransfertForm) form;

The problem is that checkboxUID is correctly filled if I stay on the same page, but always empty when I'm changing page. I can't find a way to achieve this.

Many thanks for your help !

tho24
  • 1
  • The way is to remove multibox tag and replace it with something like [this](https://stackoverflow.com/a/42654697/573032). – Roman C Aug 31 '17 at 12:05
  • Hi Roman, thank you for your answer. Can you take a look at my reply below ? – tho24 Aug 31 '17 at 13:33
  • I saw your answer is not valid on SO. You shouldn't answer if you don't have not solved a problem. What version of struts do you use? The link above is using Struts2 tags,but `html-el:multibox` is Struts1 tag and it cannot be used in Struts2. Empty checkboxes are resulting from empty list. You should fill the list before you show it in JSP. – Roman C Aug 31 '17 at 16:15

2 Answers2

0

When you're clicking the link it's not submit the form. Hence you cannot get any values from form. Try sending through URL (script way - though it's not a best practice)

var arrayValues = [12,34,54,67];  //Get the selected checkbox values when clicking link
var QueryString = JSON.stringify(arrayValues);
var a = document.getElementById('yourlinkId'); 
a.href = 'myLink?params='+QueryString;

or you can use jQuery for simple code,

$('#yourlinkId').attr({"href" : '/myLink?params=' + arrayValues.join(',')});

Try and let me know if it helps.

Vinoth Krishnan
  • 2,925
  • 6
  • 29
  • 34
0

I finnaly fixed the problem by listing my checked checkboxes and setting them to the form after clicking my link.

Many thanks for your help guys !

tho24
  • 1