• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Selecting a single row in a table, then saving that index in the struts form

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think this is more JSP related than struts specificaly, since what I am needing to do is in the JSP page.

I have my struts framework all set up, but I'm struggling with the page design and functionality. I have a jsp page, which is displaying a table. I need to be able to highlight and select exclusively a single row in the table when the row is clicked, and save that index in my ActionForm object. (I have a value in my ActionForm which will be a placeholder for the index).

I have the table displaying my list by using <logic:iterate>, but I have no idea how to get the row to "highlight" as selected, and save the index of the row into the ActionForm.

I've found some examples of using JavaScript to do the row highlighting, but I'm having second thoughts as to whether using JavaScript is the best way or if there is an alternative way using Struts tags, I'm willing to give that a try.

Here is some code:
My ActionForm:


in my jsp page, I am displaying the table:


Should I use JavaScript? Alternatives? This displays my table, but I need some guidance on how to do the row selection and row highlighting when the row is clicked.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ActionForm == Struts-specific. Moved to the Struts forum.
 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nathan England wrote:I need some guidance on how to do the row selection and row highlighting when the row is clicked.


  • Row selection: Use "checkbox" with value as a unique row id or whatever the value which distinguish it from other rows
  • Row highlighting: Its basically a client side user action, and no one make it possible other than Javascript..
  •  
    Nathan England
    Greenhorn
    Posts: 20
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thanks for the tips. I really struggled with this. I'm not 100% out of deep water yet, but at least I'm getting the checkboxes to set a value in my data object submitted by the form.

    I'll post what I managed to get to work so far:
    Here is the <table> where my list is displayed:


    The part that really hung me up was the iterate, I had my id="person" when it should have been id="personList"
    After hours of digging I finally found something that mentioned this. The "id" and the "property" must be the same. (I'll worry about the "why" later).
    changed:
    <logic:iterate id="person" scope="session" name="PersonSearchForm" property="personList">
    to:
    <logic:iterate id="personList" scope="session" name="PersonSearchForm" property="personList">

    Now I need to find some JavaScript code somewhere that applies some fancy highlighting and selection for the table rows and I'll be all set...
     
    Sagar Rohankar
    Ranch Hand
    Posts: 2908
    1
    Spring Java Ubuntu
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Nathan England wrote:
    The part that really hung me up was the iterate, I had my id="person" when it should have been id="personList"
    After hours of digging I finally found something that mentioned this. The "id" and the "property" must be the same. (I'll worry about the "why" later).
    changed:
    <logic:iterate id="person" scope="session" name="PersonSearchForm" property="personList">
    to:
    <logic:iterate id="personList" scope="session" name="PersonSearchForm" property="personList">


    Wrong ! the "id" and "property" are two different thing for logic:iterate tag, former defined the current element of the collection on which you're iterating and later one is come with "name" attribute to get the bean which is stored in a scope.

    You might did some mistake elsewhere, maybe the logs file can explain the cause..
     
    Nathan England
    Greenhorn
    Posts: 20
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator


    Wrong ! the "id" and "property" are two different thing for logic:iterate tag, former defined the current element of the collection on which you're iterating and later one is come with "name" attribute to get the bean which is stored in a scope.

    You might did some mistake elsewhere, maybe the logs file can explain the cause..



    Well, that's the only thing I changed after trying dozens of different approaches, so may be wrong but it worked in my case.

    Actually, I should re-state my assertion. Here is a PDF I followed that helped me do this:

    http://www.laliluna.de/download/struts-html-checkbox-en.pdf

    What I mentioned about the value of the "id" and the value of the "property" being the same, I misquoted. From the PDF:


    Note: In order to refer a property of an element within the collection to a <html:checkbox> element
    the attribute id of the <logic:iterate> tag must have the same name like the collection of the form
    bean. Furthermore the attribute indexed of the <html:checkbox> have to be set to „true“.

     
    Sagar Rohankar
    Ranch Hand
    Posts: 2908
    1
    Spring Java Ubuntu
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I haven't tried this, but the Struts docs says something diffrent about the way it renders/pass the "property" for html:chckbox,
    here is the link for html:chckbo:
    http://struts.apache.org/1.3.10/struts-taglib/tagreference.html#html:checkbox

    this the quote that may be the cause:


    property* :
    Name of the request parameter that will be included with this submission, set to the specified value.



    And your bean data is in session scope, and your not finding the checkbook value there, find it in request parameter.

    HTH
     
    I like tacos! And this tiny ad:
    a bit of art, as a gift, that will fit in a stocking
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic