Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

<display:column + <html:select

Tags:

jsp

struts

I'm creating a application using Struts where I fetch a list of people from the database and a list of schools and then I use the html:select so the user can select the school for each element, here's the part of the jsp page where I am stuck.

<display:table id="list" name="myForm.list" >
  <display:column title="ID" property="id"/>
  <display:column title="Name" property="name" sortable="true"/>
  <display:column title="School" >
    <html:select property="idSchool">
      <logic:notEmpty name="myForm" property="SchoolCombo">
        <bean:define id="SchoolCombo" name="myForm" property="SchoolCombo"/>
        <html:options collection="SchoolCombo" property="id" labelProperty="name"/> 
      </logic:notEmpty>
    </html:select>
  </display:column>
</display:table>

The list on myForm is a list of people with an id, a name and a idSchool, that is an int with no initial value. The School combo is a list of schools that came from the database with an id and a name.

What can I do so, for each element of the list I can set the idSchool on the jsp page and then, I can use the form to update a table that stores the person and with school he's on?

If I wasn't clear enough, please ask so I can explain the problem better.

like image 912
user3320407 Avatar asked Nov 11 '22 12:11

user3320407


1 Answers

As I understand, I am giving you a general solution to this problem, you have to do the additional work which is required for a complete solution.. I am explaining this by using Struts2 <s:tag> so, you have alter according to your requirement. First, place where you are iterating thru the list and add the unique elements as hidden fields. These hidden fields can be retrieved on the serverside from request param list. When you click on the any record it gets identifed by the unique id that you set as the hidden field( ItemRec-explained below).

<s:iterator value="TheListOfItems" status="ItemRec">

    <s:hidden name="TheListOfItems[%{#ItemRec.index}].id" value="%{id}" /> 
    <s:hidden name="TheListOfItems[%{#ItemRec.index}].attribut2" value="%{attribut2}" />
    <s:hidden name="TheListOfItems[%{#ItemRec.index}].attribut3" value="%{attribut3}" />
    <the actual values/records get iterated here>

</s:iterator>

on the server side you can do the following to retrieve them like this

String id= getRequest().getParameter("id");
like image 108
yeppe Avatar answered Jan 03 '23 10:01

yeppe