Hello everyone, I'm working on my new search page which uses tapestry query
parameters. The query parameters are dynamically set from a select menu. So
far it seems to be working, however I do not know how to clear the query
parameter from the url when the select menu is set to blank. I end up
getting a null pointer exception. Below is my code. btw, if anybody sees any
room for performance modifications, feel free to comment. This is very new
to me. Thanks


<html t:type="layout"
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd";
xmlns:p="tapestry:parameter" pageTitle="Used Cars For Sale in region goes
here">
   <br/><br/><br/><br/>
    <t:Form t:id="searchForm">
        <t:Select t:id="searchYear" value="vehicleYear"
model="yearSearchModel"/>
        <t:Select t:id="searchMake" value="vehicleMake"
model="makeSearchModel"/>
        <t:Select t:id="searchModel" value="vehicleModel"
model="modelSearchModel"/>
        <t:Submit/>
    </t:Form>
    
    <t:Loop source="vehicles" value="vehicle">
        <t:PageLink page="used_car_for_sale"
context="vehicle.id">${vehicle.year} ${vehicle.make} ${vehicle.model}
${vehicle.trimLevel}</t:PageLink><br/>
    </t:Loop>
</html>



public class UsedCarsForSale {

    @ActivationRequestParameter(value = "year")
    private String year;  
    @ActivationRequestParameter(value = "make")
    private String make;    
    @ActivationRequestParameter(value = "model")
    private String model;
    
    @Property
    private VehicleYear vehicleYear;
    @Property
    private VehicleMake vehicleMake;
    @Property
    private VehicleModel vehicleModel;

    @Inject
    private YearDAO yearDAO;
    @Inject
    private MakeDAO makeDAO;
    @Inject
    private ModelDAO modelDAO;
    
    @Inject
    private SelectModelFactory selectModelFactory;
    @Property
    private Vehicle vehicle;

    @Inject
    private Session session;

    @Inject
    private PageRenderLinkSource pageRenderLinkSource;
    
    void onPrepareFromSearchForm() {
        System.out.println(year);
        if(this.year != null) {
            this.vehicleYear = this.yearDAO.find(year);
        }        
        if(this.make != null) {
            this.vehicleMake = this.makeDAO.find(make);
        }        
        if(this.model != null) {
            this.vehicleModel = this.modelDAO.find(model);
        }
    }

    Object onSuccess() {
        this.year = vehicleYear.getName();
        this.make = vehicleMake.getName();
        this.model = vehicleModel.getName();
        return pageRenderLinkSource.createPageRenderLink(this.getClass());
    }

    public List<Vehicle> getVehicles() {
        Criteria criteria = this.session.createCriteria(Vehicle.class);
        criteria.createAlias("vehicleYear", "vehicleYear");
        criteria.createAlias("vehicleMake", "vehicleMake");
        criteria.createAlias("vehicleModel", "vehicleModel");
        
        if (year != null) {
            criteria.add(Restrictions.eq("vehicleYear.name", year));
        }
        if (make != null) {
            criteria.add(Restrictions.eq("vehicleMake.name",
make).ignoreCase());
        }
        if (model != null) {
            criteria.add(Restrictions.eq("vehicleModel.name",
model).ignoreCase());
        }
        
        return criteria.list();
    }

    public SelectModel getYearSearchModel() {
        return this.selectModelFactory.create(this.yearDAO.findAll(),
"name");
    }
    
    public SelectModel getMakeSearchModel() {
        return this.selectModelFactory.create(this.makeDAO.findAll(),
"name");
    }
    
    public SelectModel getModelSearchModel() {
        return this.selectModelFactory.create(this.modelDAO.findAll(),
"name");
    }
    
}




--
View this message in context: 
http://tapestry.1045711.n5.nabble.com/How-to-remove-query-parmeter-from-url-string-tp5716922.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to