I have a filter on my site that is in the image below:
Therealpurposeofthisisto"search" travel destinations (eg Paris, Barcelona, Bahia etc ...) and display the same.
I have the following table structure represented by bean's below (with comments in both classes):
Destination.java
@Entity
@Table(name="destination")
public class Destination implements Serializable {
private static final long serialVersionUID = 1L;
//Resto dos atributos omitidos para facilitar o etendimento
//Cada atributo abaixo equivale a uma tabela, na qual possui os atributos no qual será baseado o filtro
@OneToOne(cascade={CascadeType.PERSIST, CascadeType.MERGE})
@JoinColumn(name="fk_economic")
private EconomicProfile economicProfiles;
@OneToOne(cascade={CascadeType.PERSIST, CascadeType.MERGE})
@JoinColumn(name="fk_general")
private GeneralProfile generalProfiles;
@OneToOne(cascade={CascadeType.PERSIST, CascadeType.MERGE})
@JoinColumn(name="fk_social")
private SocialProfile socialProfiles;
@OneToOne(cascade={CascadeType.PERSIST, CascadeType.MERGE})
@JoinColumn(name="fk_trip")
private TripProfile tripProfiles;
@OneToOne(cascade={CascadeType.PERSIST, CascadeType.MERGE})
@JoinColumn(name="fk_weather")
private WeatherProfile weatherprofile;
//fim dos filtros
//Getter and Setter
}
Below is an example of a target-related table:
@Entity
@Table(name="economic_profile")
public class EconomicProfile implements Serializable{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="id_economic")
private Long id;
//Os atributos abaixo correspondem ao filtro de "Procuro por..." na imagem em anexo.
@Column(name="economic_travel")
private Boolean economic;
@Column(name="intermediate_travel")
private Boolean intermediate;
@Column(name="luxury_travel")
private Boolean luxury;
//Getter and setter
}
Well, I chose to do this, because in each filter at the time of registering the destination the user can choose more than one to register.
Okay, now that the time comes that hit me doubts. How to correctly pass parameters to my action? So how can I bind by matching the selected value in each dropdown with the corresponding column in my profile?
To be clearer, I'll give you an example below:
<f:form id="form-filter-perfect-travel" modelAttribute="destination" action="${pageContext.request.contextPath}/perfect-travel-filter" method="get" class="form-filtro">
<div class="box-select">
<label>PROCURO POR</label>
<f:select class="select01" path="economicProfiles">
<option value="">Selecionar...</option>
<option value="economic">Viagem Económica</option>
<option value="intermediate">Viagem Intermediária</option>
<option value="luxury">Viagem de Luxo</option>
</f:select>
</div>
</f:form>
GET request:
... / viatge / perfect-travel-filter? economicProfiles = intermediate
I think it's clearer now. The question is how do I get the value selected to pass as a parameter in a query query that would return my targets), like query below example:
select
d.id_destination
d.tenant_id,
d.appear_website,
d...
from
destination d
inner join
economic_profile ON id_destination = id_economic
where
(luxury_travel = ? || economic_travel = ? || intermediate_travel = ?);