0

combobox data binding question

asked 2008-04-22 12:53:38 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4920521

By: gwillner

Hi!

I am experimenting with combobox data binding on zk 3.0.3. I have the following zul scriplet:

<combobox id="users" model="@{simpleWindow.users}"
value="@{simpleWindow.backingBean.userId}">
<comboitem self="@{each=user}" label="@{user.commonName}" value="@{user.userId}"
/>
</combobox>

The combobox is populated OK but when I access the backing bean, I have backingBean.userId=user.commonName . It should be userId instead, isn't it?

Thanks,

Gabor

delete flag offensive retag edit

8 Replies

Sort by ยป oldest newest

answered 2008-06-25 12:53:05 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=5053564

By: rmaugusto

Thank you !!!

link publish delete flag offensive edit

answered 2008-06-22 10:29:43 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=5044787

By: madruga0315

Hey,

That does not work because what ZK will do is simply call comboitem.setLabel(agendaTee.getTee());

so you can change the attribute in agendaTee to already have the "- OK",

or

you can implement an converter, so that ZK will call you converter when loading the data from the bean to the UI, and saving the data from the ui to the bean.

using the converter is very simple:

<comboitem self="@{each=agendaTee}" label="@{agendaTee.tee}" value="@{agendaTee, converter='package.class'}"/>

Thenyou create an class that implement the TypeConverter Interface

http://www.zkoss.org/javadoc/3.0.4/zkplus/org/zkoss/zkplus/databind/TypeConverte
r.html

If you need some examples, you can look at the converters implemented by the user Robert, they were very useful for me

https://sourceforge.net/forum/message.php?msg_id=4907490

Hope it helps,
/Madruga

link publish delete flag offensive edit

answered 2008-06-22 08:10:26 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=5044770

By: rmaugusto

I have this:

<combobox id="comboboxAgendaTee" model="@{modelAgendaTees}" readonly="true"
cols="50">
<comboitem self="@{each=agendaTee}" label="@{agendaTee.tee}"
value="@{agendaTee}"/>
</combobox>

But in comboitem label I want to concatenate the value like:
label="@{agendaTee.tee} - OK"

But it does not work


How to do that ?


Thanks




link publish delete flag offensive edit

answered 2008-04-28 01:14:59 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4931899

By: henrichen

AImage myimage = (AImage)getFellow("myimage");

->

org.zkoss.zul.Image myimage = (org.zkoss.zul.Image)getFellow("myimage");

link publish delete flag offensive edit

answered 2008-04-26 09:55:55 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4929357

By: irann

hello!

this is a class:



package org.ui;
import org.jfree.data.general.*;
import org.jfree.chart.*;
import org.jfree.chart.plot.*;
import org.jfree.chart.encoders.*;
import java.lang.Double;
import java.awt.image.BufferedImage;
import org.zkoss.image.AImage;
import org.zkoss.zul.*;
import org.zkoss.zk.ui.*;






public class Testjava {


public Testjava() {
}
public void draw(){

DefaultPieDataset pieDataset = new DefaultPieDataset();
pieDataset.setValue("C/C++", new Double(17.5));
pieDataset.setValue("PHP", new Double(32.5));
pieDataset.setValue("Java", new Double(43.2));
pieDataset.setValue("Visual Basic", new Double(10));
JFreeChart chart = ChartFactory.createPieChart3D("Sample Pie Chart 3D", pieDataset,true,true,true);
PiePlot3D plot = (PiePlot3D) chart.getPlot();
plot.setForegroundAlpha(0.5f);
BufferedImage bi = chart.createBufferedImage(500, 300, BufferedImage.TRANSLUCENT , null);
byte[] bytes = EncoderUtil.encode(bi, ImageFormat.PNG, true);
AImage image = new AImage("Pie Chart", bytes);
AImage myimage = (AImage)getFellow("myimage");
myimage.setContent(image);
}
}

the problem is:

C:\Users\Rochdi\Desktop\laymen tbarbich\TestPHP\src\java\org\ui\Testjava.java:36:
cannot find symbol
symbol : method getFellow(java.lang.String)
location: class org.ui.Testjava
AImage myimage = (AImage)getFellow("myimage");


C:\Users\Rochdi\Desktop\laymen tbarbich\TestPHP\src\java\org\ui\Testjava.java:37:
cannot find symbol
symbol : method setContent(org.zkoss.image.AImage)
location: class org.zkoss.image.AImage
myimage.setContent(image);


i need your help!

thanks





link publish delete flag offensive edit

answered 2008-04-24 00:28:30 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4924379

By: robertpic71

Hi Gabor,

1.) It seems not possible (without extra javacode) to view the user.commonName and map the userId. But in a "rich domainmodel" the underlying domainclass should handle user and not the userid.

i.e.
<combobox id="users" model="@{simpleWindow.users}"
selectedItem="@{simpleWindow.ticket.responsible}">
<comboitem self="@{each=user}" label="@{user.commonName}"/> </combobox>

domain:
class Ticket implements Serializable{
....
@ManyToOne
@JoinColumn(name="USER_ID")
private User responsible;
....
User getResponsilee() {
...
void setResponsible(User _responsible) { ...

A CRUD program has only load the underlying ticket and fill the prompters. The combobox will map the right user into the ticket.

Of course, i have many legacy data (imported, without defined joins). For this cases i would wish something like a "selectedValue" for the combobox..

Some other things:
* Yes. Comboitems label's always update the Combobox value.
* When you use selectedItem, you don't have to write the value for the combobox (because ZK maps the label from the selectedItem to the combobox value)
* Without event-processing the value-attribute in the comboitem is useless!

* instead of selectedItem you could use the combobox-value an map where you want - but you could not map the hidden value from the comboitems - only the labels.

<combobox id="users" model="@{simpleWindow.users}"
value="@simpleWindow.backBean.user.commonName}">
<comboitem self="@{each=user}" label="@{user.commonName}"/>

LOADING: simpleWindow.backBean.user.CommonName --> combobox.value
SAVING: comboitem.label (user.commonName) --> combobox.value --> simpleWindow.backBean.user.CommonName

/Robert


link publish delete flag offensive edit

answered 2008-04-23 15:29:16 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4923318

By: gwillner

Robert!

The only combination that seems to work is following:

<combobox id="users" model="@{simpleWindow.users}"
selectedItem="@{simpleWindow.selectedUser}"
value="@simpleWindow.selectedUser.commonName}">
<comboitem self="@{each=user}" label="@{user.commonName}" value="@{user.userId}"
/>
</combobox>

Model relates to a list of User instances and selectedItem is a User instance.

- Is it really so, that if I use bi-diractional mapping I have to map against the label instead of the value?
- Is it possible to preset a combo to a certain value? I tried this in the window code (but it did not work):

public class ContactWindow extends Window {
private User selectedUser = contactDAO.getAllUsers().get(0);
private EmailCopyType selectedEmailCopyType = EmailCopyType.TO; ..

- Is it possible to map enums? I tried this:

<combobox id="emailCopyTypes" model="@{simpleWindow.emailCopyTypes}"
selectedItem="@simpleWindow.selectedEmailCopyType}"
value="@{simpleWindow.selectedEmailCopyType.value}">
<comboitem self="@{each=copyType}" label="@{copyType.value}"
value="@{copyType.value}"/>
</combobox>

Any clues?

Thanks in advance.

Gabor




link publish delete flag offensive edit

answered 2008-04-22 16:44:36 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4920977

By: robertpic71

Try:
<combobox model="@{simpleWindow.users}" selectedItem="@{simpleWindow.backingBean}"
value="@{simpleWindow.backingBean.userId}">

Combobox works a little bit different to listbox. See this smalltalk:
http://www.zkoss.org/smalltalks/comboboxEnhancement/

The selectedItem gets the selected object form the combox (see smalltak). I'm not sure about your backingBean (= user?).

/Robert

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: 2008-04-22 12:53:38 +0800

Seen: 928 times

Last updated: Jun 25 '08

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