Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6468241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T05:52:17+00:00 2026-05-25T05:52:17+00:00

I have a web app which has 3 page views. 1.an index page where

  • 0

I have a web app which has 3 page views.

1.an index page where all Items in db are listed ,and details of only the Item with latest creationDate are shown.

2.An itemDetails page where details of a selected item are shown.This page also lists all the items in db.

Clicking on a listed item will bring up the itemDetails page.

(These two pages also contain a text input field ,where user can enter a word to search for items matching names.)

3.A search results page,which shows a listing of items that match a search query.

I implemented the the first two pages and created the static public functions.Now,I want to implement the search.I created the function and a results page which lists the search results.

My problem is that ,if I click on an item from search results,it will bring up the itemDetails page which shows details of that item and a listing of all items in db ,since that is how the itemDetails function was implemented.I would rather have the click take me to a page, which shows the details of item and items which were results of the search query. I know it is not possible in the above implementaion since state is not retained between two requests.

So,how should I do this?I cannot think clearly about this.Can you shed some light?

The code is like

package controllers;
...
public class Application extends Controller {
    ...
    public static void index() {
        //all items
        List<Item> items = Item.find("order by creationDate desc").fetch();
        //the latest created item
        Item item = items.get(0);       
        render(items,item);
    }

    public static void itemDetails(Long id) {
        //selected item     
        Item item = Item.findById(id);
        //all items
        List<item> items = Item.find("order by creationDate desc").fetch();
        render(items,item);
    }
    public static void search(String keyword) {
        String kw = keyword.trim();
        String pattern = "%"+kw+"%";
        String query="select distinct item from Item item where item.name like :pattern";
        List<Item> items = Item.find(query).bind("pattern", pattern).fetch();
        render(items);
    }
...
}

index.html page is

#{extends 'main.html' /}
#{set title:'Home' /}
#{if item}
    //show the details of item
#{/if}
#{if items.size()>0}
    #{list items:items, as:'item'}
       <a href="@{Application.itemDetails(item.id)}">${item.name}</a>
    #{/list}
#{/if}
#{else}
        There are currently no items        
#{/else}
#{form @Application.search(keyword)}
  <input type="text" name="keyword" id="keyword" size="18" value=""/>
  <input type="submit" value="search"/>
#{/form}

itemDetails.html page:

is similar to the index page ..for the time being I have copied all the contents of index page .

search page:

#{extends 'main.html' /}
#{set title:'search results' /}

#{if items.size()>0}
    #{list items:items, as:'item'}
       <a href="@{Application.itemDetails(item.id)}">${item.name}</a>
    #{/list}
#{/if}

#{else}
    <div class="empty">
        could not find  items with matching name here.
    </div>  
#{/else}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T05:52:18+00:00Added an answer on May 25, 2026 at 5:52 am

    I see a couple possibilities. First you could add a new public static void itemSearchDetails(Long id, String keyword) action to your controller. Then add a new itemSearchDetails.html page. Finally change the link in the search.html page to <a href="@{Application.itemSearchDetails(item.id)}">${item.name}</a>

    Here is the approach I would take. Modify the itemDetails() method to include a keyword parameter.

     public static void itemDetails(Long id, String keyword) {
        //selected item     
        Item item = Item.findById(id);
        List<item> items;
        if (StringUtils.isNotBlank(keyword) ) {
          String query="select distinct item from Item item where item.name like :pattern";
          items = Item.find(query).bind("pattern", pattern).fetch();
        } else {
          items = Item.find("order by creationDate desc").fetch();
        }
        render(items,item);
    }
    

    Then change the corresponding calls in the HTML files.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a user profile page on my web app which has contact information.
I have a JSP page (home page) in a Web App, which has different
I have a JSF/Seam web app which has a page with a form which,
Hi I have a web app which has a listbox of all the available
I have a business web app which is served using SSL only. One of
So I have a main JSP index page, index.jsp, which has several includes. Something
My web-app has a media upload facility which associates each uploaded media item with
I have an ASP.NET MVC web app which has a really basic subscription system
I have a web app which has standard things for learning based app like
I have a web app which lets the user select the excel spreadsheet and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.