-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hello,
I've a page that is used to create a new Order, it's afterCompose creates a new order object and put it in the session. The NewOrder.zul is annotated to be binded to this session order. So far so good.
After I set constraint attributes to some components the afterCompose stops it's execution when the first component with constraint is "violated". For example, I'm creating a new order object and it's properties are all null the customer combobox's constraint is set to "no empty, strict" and it's the first component of the form.
<combobox model="@{customerList}" selectedItem="@{order.customer}" constraint="no empty, strict"/> <combobox id="otherCombo" model="@{otherData}/>
In the afterCompose() I create a new order and fill the models to be used by the combos:
createNewOrder(); // order = new Order() loadCustomerData(); loadOtherComboData();
When createNewOrder() is executed the page shows the constraint error (the not empty message) and stops, both combos aren't filled by the model, if I remove the combobox's constraint everything is loaded correctly.
It shouldn't stop because of a new object. IMO the first load is supposed to show no errors and when the user start to enter the data the error should be appearing.
Are binding and constraint incompatibles? How could I solve this?
Regards,
Felipe Cypriano
A complete code that reproduces my problem:
TestComposer.java
import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.util.GenericForwardComposer; import org.zkoss.zkplus.databind.BindingListModel; import org.zkoss.zkplus.databind.BindingListModelList; import java.util.ArrayList; import java.util.List; public class TestComposer extends GenericForwardComposer{ @Override public void doAfterCompose(Component component) throws Exception { super.doAfterCompose(component); page.setVariable("newObject", null); // to simulate a property of a newly created object List list = new ArrayList(); list.add("a"); list.add("b"); BindingListModel modelList = new BindingListModelList(list, false); page.setVariable("modelList", modelList); List list2 = new ArrayList(); list2.add("otherData"); BindingListModel modelList2 = new BindingListModelList(list2, false); page.setVariable("modelList2", modelList2); } }
Test.zul:
<?xml version="1.0" encoding="UTF-8"?> <?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" ?> <zk> <window apply="TestComposer"> <combobox id="first" model="@{modelList}" selectedItem="@{newObject}" constraint="no empty, strict"> <comboitem self="@{each=item}" label="@{item}"/> </combobox> <combobox id="otherCombo" model="@{modelList2}"> <comboitem self="@{each=item}" label="@{item}"/> </combobox> </window> </zk>
If you remove the constraint the code works, but it should work like this too, doesn't it?
Regards,
Felipe Cypriano
Hi Guys,
How I'm supposed to use constraints if isn't compatible with data binding? How do you are using it right now? This problem only happens with me?
The problem seems to be that the constraint is getting applied when the binding is loading the object's data, and it should apply the constraints when saving the user input data, shouldn't it?
I think the behavior of textbox is what I told, replacing the combobox to textbox works fine and don't cause any problem.
I found a solution, It's not what I want, but works.
Don't put the constraint in zul file, and when the user click on save button active all constraints and check them all:
onClick:
searchCliente.setConstraint("no empty") cmbLocalCobranca.setConstraint("no empty, strict") cmbCondicaoPagamento.setConstraint("no empty, strict") searchTransportadora.setConstraint("no empty") // Code to check them all
Feature Request to add a way to force the validation: ID: 2809002
Sorry to reactivate this old thread. I had the same problem today.
The reason why it works with textbox is, because there seems to be an explicit workaround for components which have their binding definition in a "value" attribute (as Textbox).
See class org.zkoss.zkplus.databind.Binding.myLoadAttribute:
//Bug #1876198 Error msg appears when load page (databind+CustomConstraint) //catching WrongValueException no longer works, check special case and //use setRowValue() method directly if ((comp instanceof InputElement) && "value".equals(_attr)) {
Asked: 2009-06-17 15:01:05 +0800
Seen: 1,159 times
Last updated: Feb 27 '20