0
I have a filter on my site that is in the image below:
The real goal of the same is to "search" travel destinations (Ex:. Paris, Barcelona, Bahia etc...) and present on the screen the same.
I have the following structure of tables 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 table related to the destination:
@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 it this way, because in each filter when registering the destination the user will be able to choose more than one to register.
Okay, now that the time has come to question me. How to correctly pass the parameters for my action? That is how I can bind by relating the selected value in each dropdown to the corresponding column in my profile?
To be clearer I will give 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 has become clearer now. The question is how to take the selected value to pass as a parameter in a query (query that will return my destinies), as the 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 = ?);
With JS you can easily, just include the parameter in the URL in
onChange
of each selector, for example, no?– Bruno César
It would not be the case @Brunocésar. You would need to pass in a certain way the value that was selected in the dropdown and attach it in the correct parameter within the query
– João Manolo
Exactly, you’re using spring taglib, the path will generate you the
name
from select, which is the name you used as parameter. In this example of yours, takename
(economicProfiles) and the value of the selected option.– Bruno César
I understood Bruno, but the question is this. Each value of my BD column and a Boolean and each value of my select (option) is a text. How can I perform this "crossing"? Is there any other simpler way?
– João Manolo
John, you can select only one economicProfile? For example, this is also valid:
economicProfiles=intermediate,luxury
? I don’t know how your controllers are or how you’re generating queries, but there are many ways to handle this, some you’ll need to handle in the controller/service and pass the object with the options to the persistence layer.– Bruno César
Then Bruno I can select only one yes. The problem is how to convert these parameters passed via html to action to be converted to the exact column in the database so yes to perform a select.
– João Manolo