0

MVVM Radio button with form binding

asked 2013-10-03 03:47:05 +0800

Senthilchettyin gravatar image Senthilchettyin flag of India
2623 3 8
http://emrpms.blogspot.in...

Hi

I have radio button Yes/No with form binding as follows

    <radiogroup id="addresstop" selectedItem="@bind(fx.printaddres)">
                            <radio id="top1" label="Yes" value="1" />
                            <radio id="top2" label="No" value="0" />
                        </radiogroup>

printaddress is defined as int in the database. The problem is when i select yes, it is correctly storing value 1 in the database, when again when i open the screen , it is not selecting the Yes Radio button

delete flag offensive retag edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2013-10-03 04:19:31 +0800

rickcr gravatar image rickcr
704 7

I requested this to be fixed a while back... http://forum.zkoss.org/question/80397/how-can-i-bind-an-int-value-to-radiogroup-for-selecteditem-it-wants-string/

Issue is the radio button doesn't work with an int :( Has to be a string... so you can fix this various ways...

I just added a getter and setter on VM getPrintAddress() returns String version..... setPrintAddress() converts my form String to my model's int.

Annoying I know.

link publish delete flag offensive edit
0

answered 2013-10-03 06:50:27 +0800

Senthilchettyin gravatar image Senthilchettyin flag of India
2623 3 8
http://emrpms.blogspot.in...

Hi Thank you.

I have written the converter as follows. But just wondering how can i call this in the value property as per above example

package com.product.webapp.component;

import org.zkoss.bind.BindContext; import org.zkoss.bind.Converter; import org.zkoss.zk.ui.Component;

public class MyRadioButtonConverter implements Converter { /** * Convert Date to String. * * @param val * date to be converted * @param comp * associated component * @param ctx * bind context for associate Binding and extra parameter (e.g. * format) * @return the converted String */

/**
 * The method coerceToUi() is invoked when loading ViewModel's property to
 * component and its return type should correspond to bound component
 * attribute's value[1]. The coerceToBean() is invoked when saving. If you
 * only need to one way conversion, you can leave unused method empty.
 */

public Object coerceToUi(Object val, Component comp, BindContext ctx) {
    String strI = String.valueOf(val);
    return strI;
}

/**
 * Convert String to Integer.
 * 
 * @param val
 *            date in string form
 * @param comp
 *            associated component
 * @param ctx
 *            bind context for associate Binding and extra parameter (e.g.
 *            format)
 * @return the converted Date
 */
public Object coerceToBean(Object val, Component comp, BindContext ctx) {
    return Integer.parseInt((String) val);
}

}

link publish delete flag offensive edit
Your answer
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
1 follower

RSS

Stats

Asked: 2013-10-03 03:47:05 +0800

Seen: 154 times

Last updated: Oct 03 '13

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