-
FEATURED COMPONENTS
First time here? Check out the FAQ!
how I can recover the value of a listitem and use it in an SQL query like this:
<listbox width="100px" id="listbox" rows="1" mold="select" onSelect="">
<listitem label="s1" selected="true"/>
<listitem label="s2"/>
<listitem label="s3" />
</listbox>
I want to retrieve the selected value every time and use it in this query:
ResultSet rs = stmt.executeQuery("select * from seqaplanifier where Site = 'value recovered '");
Regards
It could be something like:
Listitem li = listbox.getSelectedItem( String value = (String) li.getValue(); ResultSet rs = stmt.executeQuery("select * from seqaplanifier where Site = '" + value + "'");
HTH
Hi,
I have tried using the proposed t, but it does not work ... for information, the code of the java application does not integrate directly into the page. ZUL .....
I do not know yet how to retrieve the value selected for use in the SQL ......
Any other idea please, i need helps...
Regards
Are you using zscript ?
hi YamilBracho,
my request is in a java file and not in the .zul file. I don't know if it makes a big things?
it is possible to import a . zul file in java page? if so how???
Regards
So you have a java code taht works a composer of your zul page, isn't it ?
In this context, you could have a button to execute the query and you would have a "onClick$YourButton" method in your java code.
In thie method you put the above code, say:
public void onClick$btnGenerateSQL() { Listitem li = listbox.getSelectedItem( String value = (String) li.getValue(); ResultSet rs = stmt.executeQuery("select * from seqaplanifier where Site = '" + value + "'"); .... }
HTH
ok,I will try this!
thank you very much Yamil
>> it is possible to import a . zul file in java page? if so how???
I'm not sure about your request, do you want:
- a java-only resolution (no zul-file, no XML for the UI)
- or zul-file for the view and a javaclass to fill the UI and process events
I prefer paint my GUI within zul-files and couple this with a java controller/composer.
/Robert
zul-file for the view and a javaclass to fill the UI and process events
A good way to couple the UI and the (java)controller is the apply-keyword to assign a composer/controller.
I the most cases you will assign the composer/controller to a root UI-Element i.e. window.
<window .... apply="your.package.YourClass"/>
The composer has implement composer or extend i.e. GenericForwardComposer.
There some other great features with the GenericForwardComposer:
The (Forward) Composer creates event-listeners for your events.
i.e.
<button id="save" label="Save"/>
composer:
public void onClick$save() {
// process save-button
...
}
Eventname (i.e. onClick) + "$" + id-name --> autowired event
In your case:
If you do not need an extra button, try: onSelect$listboxid (give your listbox an id and handle the onSelect event)
A good place for the first output is:
@Override
public void doAfterCompose(Component win) throws Exception {
super.doAfterCompose(win);
// do your initcode here
}
The next is, how do want to setup your Listbox(content):
pure Java:
add UI Listitems with pure javacode (no domainbeans required)
Model and Java:
create a model (could be also an array) and a Java Listitemrenderer, the renderer converts the modeldata to listitem's.
Databinding:
Create a model + a template Listitem with annotations
Check also the tutorial, this works with:
JDBC, DAO's, domainbeans, composer, autowired events and databinding.
For the first time, it's simpler to wrap the resultset into UI-Elements, like the simple access smalltalk. But this is (old) PHP-style. But for most flexible code, you have to implement more tears (DAO for access, domainbeans as datacontainer...).
/Robert
hi,
i tried all proposition and it don't works i don't know why??
look what i did:
in the zul page
.......
........
<window id="win" title="Gestion planning" width="1000px" border="normal" apply="PlanningPrincipale.SeqAPlanifierControle">
.......
.......
<listbox width="100px" id="listbox" rows="1" mold="select" onSelect="">
<listitem label="S1" selected="true"/>
<listitem label="S2"/>
<listitem label="S3" />
</listbox>
.......
.......
then in the class SeqAPlanifierControle i have this method:
public List onClick$sit(){
Statement stmt = null;
Connection conn = null;
List allSequences = new ArrayList<SeqAPlanifierBean>();
try {
String value ;
Listitem li = listbox.getSelectedItem();
value = (String) li.getValue();
//get connection
conn = DriverManager.getConnection(url, user, pwd);
stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from seqaplanifier where Site = '" + value + "'");// where Site = '" + value + "'where Site like '%S1%'
// fetch all events from database
SeqAPlanifierBean seq;
while (rs.next()) {
seq = new SeqAPlanifierBean();
seq.setId(rs.getString(1));
seq.setDdepart(rs.getDate(2));
seq.setDuree(rs.getString(3));
seq.setSite(rs.getString(4));
seq.setOrigine(rs.getString(5));
seq.setDestination(rs.getString(6));
seq.setGroupe(rs.getString(7));
seq.setTrajet(rs.getString(8));
seq.setVehicule(rs.getString(9));
seq.setPoids(rs.getString(10));
allSequences.add(seq);
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
try {
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
return allSequences;
}
when I selected a site in the listitem, then I sue the Go button, my list is still empty
Regards
Asked: 2009-08-14 15:07:32 +0800
Seen: 538 times
Last updated: Aug 20 '09