Sie sind auf Seite 1von 6

public List<String> fillReg() {

try {
java.sql.Connection con = null;
String url = "jdbc:mysql://localhost:3306/vehicles?
autoReconnect=true&useSSL=false";
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection(url, "root", "admin123");
String SQL = "SELECT REGISTRATION FROM tblvehicles;";
PreparedStatement prep = con.prepareStatement(SQL);

ResultSet res = prep.executeQuery();

while (res.next()) {
registrations.add(res.getString("REGISTRATION"));
}

con.close();
prep.close();

System.out.print("Connected to database");

}
catch (Exception e) {
e.printStackTrace();
}

return registrations;
}

public void fVehicle() throws SQLException, ClassNotFoundException {

java.sql.Connection con = null;


String url = "jdbc:mysql://localhost:3306/vehicles?
autoReconnect=true&useSSL=false";
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection(url, "root", "admin123");
String SQL = "SELECT DISTINCT * FROM tblVehicles WHERE
REGISTRATION= ?";
PreparedStatement prep = con.prepareStatement(SQL);
newConsumption consum = new newConsumption();

ResultSet res = prep.executeQuery();


res.beforeFirst();

while(res.next()){
consum.setVehicle(res.getString(1));
}

<h:selectOneMenu name="Registration" value="#{form_data.registration}"


label="Insert Vehicle" id="registration"
styleClass="registration"
required="true" title="Insert
registration"
>
<f:selectItem itemLabel="Select
registration mark" itemDisabled="true" />
<f:selectItems
value="#{helper.registrations}" itemValue="#{form_data.registration}"/>

<p:ajax update="vehicle"
listener="#{helper.fVehicle()}"/>

</h:selectOneMenu>

<h:form id="form">

<table id="table_car">

<tr>
<td class="lab">Registration:</td>
<td>
<p:selectOneMenu id="registration"
styleClass="registration"
value="#{form_data.registration}" >

<f:selectItems value="#{help.registrations}"
var="form_data" itemLabel="#{form_data.registration}"
itemValue="#{form_data.registration}" />
<p:ajax event="change" update="vehicle"
listener="#{help.fillVeh()}" />
</p:selectOneMenu>
<h:messages styleClass="error"
for="registration"/>
</td>
</tr>

<tr>
<td class="lab"> Vehicle</td>
<td>
<h:selectOneMenu id="vehicle" styleClass="vehicle"
value="#{form_data.vehicle}">
<f:selectItems value = "#{help.vehicles}"
var="form_data" itemValue =
"#{form_data.vehicle}"
itemLabel="#{form_data.vehicle}"/>

</h:selectOneMenu>
<h:messages styleClass="error" for="vehicle"/>
</td>
</tr>

</table>

<p:selectOneMenu id="country" value="#{dropdownView.country}"


style="width:150px">
<p:ajax listener="#{dropdownView.onCountryChange}" update="city" />
<f:selectItem itemLabel="Select Country" itemValue=""
noSelectionOption="true" />
<f:selectItems value="#{dropdownView.countries}" />
</p:selectOneMenu>

<h:commandButton value="Insert new consumption"


action="response" styleClass="btnInsert" >
<f:actionListener binding="#{helper.addConsumption()}" />
</h:commandButton>
</h:form>

private List<newConsumption> registrations;


public List<newConsumption> getRegistrations() {
return registrations;
}

public void setRegistrations(List<newConsumption> registrations) {


this.registrations = registrations;
}

private List<newConsumption> vehicles;

public List<newConsumption> getVehicles() {


return vehicles;
}

public void setVehicles(List<newConsumption> vehicles) {


this.vehicles = vehicles;
}

private String reg_;

public String getReg_() {


return reg_;
}

public void setReg_(String reg_) {


this.reg_ = reg_;
}

public helper() throws SQLException {


registrations = new ArrayList<newConsumption>();
fillReg();
}

public void fillReg() {


try {
java.sql.Connection con = null;
String url = "jdbc:mysql://localhost:3306/vehicles?
autoReconnect=true&useSSL=false";
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection(url, "root", "admin123");
String SQL = "SELECT * FROM tblvehicles;";
PreparedStatement prep = con.prepareStatement(SQL);

ResultSet res = prep.executeQuery();


res.beforeFirst();

while (res.next()) {
newConsumption reg = new newConsumption();
reg.setRegistration(res.getString("REGISTRATION"));
registrations.add(reg);
}

con.close();
prep.close();

System.out.print("Connected to database");

}
catch (Exception e) {
e.printStackTrace();
}
}

public void fillVeh() {


try {
java.sql.Connection con = null;
String url = "jdbc:mysql://localhost:3306/vehicles?
autoReconnect=true&useSSL=false";
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection(url, "root", "admin123");
String SQL = "SELECT * FROM tblvehicles WHERE REGISTRATION= '" + reg_ +
"'";

PreparedStatement prep = con.prepareStatement(SQL);

ResultSet res = prep.executeQuery();


res.beforeFirst();

while (res.next()) {
newConsumption veh = new newConsumption();
veh.setVehicle(res.getString("VEHICLE"));
vehicles.add(veh);
}

con.close();
prep.close();

System.out.print(this.getReg_());
}
catch (Exception e) {
e.printStackTrace();
}
}

<p:selectOneMenu id="vehicle" value="#{form_data.vehicle}"


style="font-size:14px"
styleClass="menuOne">
<f:selectItem itemLabel="Select" itemValue="" />
<f:selectItems value="#{help.vehicles}"
var="form_data"
itemLabel="#{form_data.vehicle}" itemValue="#{form_data.vehicle}" />
</p:selectOneMenu>

6
down vote
accepted
You are right, its because of default locale. You have several options:

1.Set default locale from faces-config:

<locale-config>
<default-locale>de</default-locale>
<supported-locale>en_US</supported-locale>
<supported-locale>es</supported-locale>
<supported-locale>de</supported-locale>
<supported-locale>fr_FR</supported-locale>
<supported-locale>it_IT</supported-locale>
<supported-locale>pt_br</supported-locale>
</locale-config>
2.Set locale from backed bean and read via converter:

<f:convertNumber locale="#{bean.locale}" />


3.Set local on converter:

<f:convertNumber locale="en-US" />


Well thanks to BalusC he answered all the questions:) there you can find also view
example, so i felt little bit guilty and get output for available locals (1000000
formatted):

ja_JP Japanese (Japan) 1,000,000


es_PE Spanish (Peru) 1.000.000
en English 1,000,000
ja_JP_JP Japanese (Japan,JP) 1,000,000
es_PA Spanish (Panama) 1,000,000
sr_BA Serbian (Bosnia and Herzegovina) 1.000.000
mk Macedonian 1.000.000
es_GT Spanish (Guatemala) 1,000,000
ar_AE Arabic (United Arab Emirates) 1,000,000
no_NO Norwegian (Norway) 1 000 000
sq_AL Albanian (Albania) 1.000.000
bg Bulgarian 1 000 000
ar_IQ Arabic (Iraq) 1,000,000
ar_YE Arabic (Yemen) 1,000,000
hu Hungarian 1 000 000
pt_PT Portuguese (Portugal) 1.000.000
el_CY Greek (Cyprus) 1.000.000
ar_QA Arabic (Qatar) 1,000,000
mk_MK Macedonian (Macedonia) 1.000.000
sv Swedish 1 000 000
de_CH German (Switzerland) 1'000'000
en_US English (United States) 1,000,000
fi_FI Finnish (Finland) 1 000 000
is Icelandic 1.000.000
cs Czech 1 000 000
en_MT English (Malta) 1,000,000
sl_SI Slovenian (Slovenia) 1.000.000
sk_SK Slovak (Slovakia) 1 000 000
it Italian 1.000.000
tr_TR Turkish (Turkey) 1.000.000
zh Chinese 1,000,000
th Thai 1,000,000
ar_SA Arabic (Saudi Arabia) 1,000,000
no Norwegian 1 000 000
en_GB English (United Kingdom) 1,000,000
sr_CS Serbian (Serbia and Montenegro) 1.000.000
lt Lithuanian 1 000 000
ro Romanian 1.000.000
en_NZ English (New Zealand) 1,000,000
no_NO_NY Norwegian (Norway,Nynorsk) 1 000 000
lt_LT Lithuanian (Lithuania) 1 000 000
es_NI Spanish (Nicaragua) 1,000,000
nl Dutch 1.000.000
ga_IE Irish (Ireland) 1,000,000

Das könnte Ihnen auch gefallen