0

Listitem and sql request

asked 2009-08-14 15:07:32 +0800

zkbiginner gravatar image zkbiginner
78

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

delete flag offensive retag edit

21 Replies

Sort by ยป oldest newest

answered 2009-08-14 15:50:04 +0800

YamilBracho gravatar image YamilBracho
1722 2

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

link publish delete flag offensive edit

answered 2009-08-17 07:56:37 +0800

zkbiginner gravatar image zkbiginner
78

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

link publish delete flag offensive edit

answered 2009-08-17 13:11:29 +0800

YamilBracho gravatar image YamilBracho
1722 2

Are you using zscript ?

link publish delete flag offensive edit

answered 2009-08-17 14:03:56 +0800

zkbiginner gravatar image zkbiginner
78

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

link publish delete flag offensive edit

answered 2009-08-17 14:39:30 +0800

YamilBracho gravatar image YamilBracho
1722 2

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

link publish delete flag offensive edit

answered 2009-08-17 14:49:25 +0800

zkbiginner gravatar image zkbiginner
78

ok,I will try this!

thank you very much Yamil

link publish delete flag offensive edit

answered 2009-08-17 14:49:32 +0800

robertpic71 gravatar image robertpic71
1275 1

>> 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

link publish delete flag offensive edit

answered 2009-08-17 15:08:55 +0800

zkbiginner gravatar image zkbiginner
78

zul-file for the view and a javaclass to fill the UI and process events

link publish delete flag offensive edit

answered 2009-08-17 16:55:09 +0800

robertpic71 gravatar image robertpic71
1275 1

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

link publish delete flag offensive edit

answered 2009-08-18 15:08:52 +0800

zkbiginner gravatar image zkbiginner
78

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

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2009-08-14 15:07:32 +0800

Seen: 538 times

Last updated: Aug 20 '09

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More