锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
2.Form涓殑緇勪歡錛岀撼鍏ompoundPropertyModel錛屼技涔庢柟鍙緱鍒皉awinput銆傛湁寰呯‘璁ゃ?br />
3.Form濡傛灉涓嶄嬌鐢–ompoundPropertyModel錛屾敞鎰忕粰鎺т歡璁劇疆model銆?br />
4.dropdownchoice,鏈夋嫨鎯呭喌涓嬫彁浜わ紝鍗抽変腑浜嗏滆閫夋嫨鈥濄傛湇鍔″櫒绔緱鍒幫細
聽聽聽getValue():-1
聽聽聽getInput():
聽聽聽getModelObjectAsString():
5.涓涓猰odel紺轟緥錛?br />int cols=5;
int rows=5;
final String[][] values=new String[rows][cols];
form.add(new Loop("rows", rows) {
聽聽 populateitem(Item item) {
聽聽聽聽 final int row=item.getindex();
聽聽聽聽 item.add(new Loop("cols", cols) {
聽聽聽聽聽聽聽聽聽 populateitem(Item item) {
聽聽聽聽聽聽聽聽聽聽聽聽聽聽 final int col=item.getindex();
聽聽聽聽聽聽聽聽聽聽聽聽聽聽 IModel model=new Model() {
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 setobject(Component c, Object o) {
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 values[row][col]=o;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 Object getObject(Component c) {
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 return values[row][col];
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 }};
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 item.add(new TextField("cell", model));
聽聽 });
<table>
<tr wicket:id="rows"><td wicket:id="cols"><input type="text" wicket:id="cell"/></td></tr>
</table>
]]>
褰撲嬌鐢細
form.add(new Button("verifyTag"){
聽聽聽public void onSubmit() {
聽聽聽System.out.println("verifyTag錛歱roductTag.getRawInput:"+productTag.getRawInput());
聽聽聽......
聽聽聽聽if(true)
聽聽聽聽聽info("璇ヤ駭鍝佹爣璇嗗彲浠ヤ嬌鐢?);
聽聽聽}
聽聽}.setDefaultFormProcessing(false));
榪欐牱鐨勫崟涓form澶氭寜閽椂錛岄渶瑕佹敞鎰忕殑鏄痟tml妯℃澘涓殑input type 搴旇璁劇疆涓簊ubmit,鍚﹀垯澶辨晥錛?br />
<input wicket:id="verifyTag" type="submit" value="媯嫻嬪敮涓鎬? size="30"/>
鍙﹀錛屾兂寰楀埌杈撳叆鍊鹼紝鍙互浣跨敤getRawInput()鏂規硶鑾峰緱錛屼絾鏄湪form鐨刼nSubmit()涓鏂規硶浼間箮寰椾笉鍒板鹼紝鏈夊緟榪涗竴姝ュ疄楠屻?/p>
]]>
聽聽聽 聽聽聽 聽聽聽 add(new Button("saveButton")
聽聽聽 聽聽聽 聽聽聽 {
聽聽聽 聽聽聽 聽聽聽 聽聽聽 public void onSubmit()
聽聽聽 聽聽聽 聽聽聽 聽聽聽 {
聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 //save form values, redirect
@@ 聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 Product product = (Product)getModelObject();
聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 ProductProxy.addProduct(product);
聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 setResponsePage(new EditProduct());
聽聽聽 聽聽聽 聽聽聽 聽聽聽 }
The line marked @@ is wrong. You ask from the submit button the modelobject. Because the button doesn't have a model (model == null), and the form has a compound model, it will use the component id "saveButton" as an OGNL expression with the form modelobject as base.
This happened because you create an anonymous subclass on the Button. The event handler 'onSubmit' has a this pointer to the button.
This can be solved by changing the line to the following:
Product product = (Product)getParent().getModelObject();
Martijn
Here's my Form class:
聽聽聽 private static class EditProductForm extends Form
聽聽聽 {
聽聽聽 聽聽聽 public EditProductForm(String name, Product product)
聽聽聽 聽聽聽 {
聽聽聽 聽聽聽 聽聽聽 super(name, new CompoundPropertyModel(product));
聽聽聽 聽聽聽 聽聽聽
聽聽聽 聽聽聽 聽聽聽 //get collection of Category items
聽聽聽 聽聽聽 聽聽聽 IModel catsModel = new LoadableDetachableModel()
聽聽聽 聽聽聽 聽聽聽 {
聽聽聽 聽聽聽 聽聽聽 聽聽聽 protected Object load()
聽聽聽 聽聽聽 聽聽聽 聽聽聽 {
聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 return ProductProxy.getAllCategories(); //via proxy
聽聽聽 聽聽聽 聽聽聽 聽聽聽 }
聽聽聽 聽聽聽 聽聽聽 };
聽聽聽 聽聽聽 聽聽聽
聽 聽 聽聽聽 聽聽聽 //add form components
聽聽聽 聽聽聽 聽聽聽 add(new TextField("productCode").add(RequiredValidator.getInstance()));
聽聽聽 聽聽聽 聽聽聽 add(new TextField("name").add(RequiredValidator.getInstance()));
聽聽聽 聽聽聽 聽聽聽 add(new TextArea("summary").add( RequiredValidator.getInstance()));
聽聽聽 聽聽聽 聽聽聽 add(new TextField("unitPrice"));
聽聽聽 聽聽聽 聽聽聽 add(new TextField("weight"));
聽聽聽 聽聽聽 聽聽聽 add(new TextField("height"));
聽聽聽 聽聽聽 聽聽聽 add(new TextField("width"));
聽聽聽 聽聽聽 聽聽聽 add(new TextField("length"));
聽聽聽 聽聽聽 聽聽聽 add(new TextField("insuredValue"));
聽聽聽 聽聽聽 聽聽聽 add(new CheckBox("freeShipping"));
聽聽聽 聽聽聽 聽聽聽 add(new TextField("thumbnail").add(RequiredValidator.getInstance()));
聽聽聽 聽聽聽 聽聽聽 add(new TextField("photo").add(RequiredValidator.getInstance ()));
聽聽聽 聽聽聽 聽聽聽
聽聽聽 聽聽聽 聽聽聽 //add reset button
聽聽聽 聽聽聽 聽聽聽 add(new Button("cancelButton")
聽聽聽 聽聽聽 聽聽聽 {
聽聽聽 聽聽聽 聽聽聽 聽聽聽 public void onSubmit()
聽聽聽 聽聽聽 聽聽聽 聽聽聽 {
聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽
聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 setResponsePage(new EditProduct());
聽聽聽 聽聽聽 聽聽聽 聽聽聽 }
聽聽聽 聽聽聽 聽聽聽 }.setDefaultFormProcessing(false));
聽聽聽 聽聽聽 聽聽聽
聽聽聽 聽聽聽 聽聽聽 //add reset button
聽聽聽 聽聽聽 聽聽聽 add(new Button("saveButton")
聽聽聽聽聽聽聽聽聽聽聽 {
聽聽聽 聽聽聽 聽聽聽 聽聽聽 public void onSubmit()
聽聽聽 聽聽聽 聽聽聽 聽聽聽 {
聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 //save form values, redirect
聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 Product product = (Product)getModelObject();
聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 ProductProxy.addProduct(product);
聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 setResponsePage(new EditProduct());
聽聽聽 聽聽聽 聽聽聽 聽聽聽 }
聽聽聽 聽聽聽 }
聽聽聽 }
The cancel button works now but the save button is now throwing an exception:
wicket.WicketRuntimeException : Method public abstract void wicket.markup.html.form.IFormSubmitListener.onFormSubmitted () of interface java.lang.reflect.Method threw an exception ...
...
Caused by: java.lang.reflect.InvocationTargetException ...
...
Caused by: wicket.WicketRuntimeException: OGNL Exception: expression='saveButton'; path='4:editProductForm:saveButton'
...
Caused by: ognl.NoSuchPropertyException: com.myapp.model.Product.saveButton
...
Here's the form HTML just in case I'm goofing something there:
<form wicket:id="editProductForm" id="editProductForm">
...
聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 <tr>
聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 <td colspan="2">
聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 <input type="submit" wicket:id="saveButton" value="Save" />
聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽
聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 <input type="submit" wicket:id="cancelButton" value="Cancel" />
聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 <br />
聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 <br />
聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 </td>
聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 </tr>
聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 聽聽聽 </form>
What's wrong w/ this?
Thanks!
]]>
聽聽public TextFilteredPropertyColumnIntConvert(IModel displayModel, String propertyExpression) {
聽聽聽super(displayModel, propertyExpression);
聽聽}
聽聽public Component getFilter(String componentId, FilterForm form) {
聽聽聽return new TextFilterIntConvert(componentId,getFilterModel(form),form);
聽聽}聽聽
聽}聽
聽public class TextFilterIntConvert extends AbstractFilter{
聽聽private static final long serialVersionUID = 1L;
聽聽private final TextField filter;
聽聽public TextFilterIntConvert(String id, IModel model, FilterForm form){
聽聽聽super(id, form);
聽聽聽filter = new TextField("filter", model){
聽聽聽聽public IConverter getConverter() {
聽聽聽聽聽return new SimpleConverterAdapter(){
聽聽聽聽聽聽public String toString(Object value){
聽聽聽聽聽聽聽聽聽return value != null ? value.toString() : null;
聽聽聽聽聽聽}
聽聽聽聽聽聽public Object toObject(String value) {
聽聽聽聽聽聽聽Long l = new Long(0);
聽聽聽聽聽聽聽try{
聽聽聽聽聽聽聽聽l = Long.valueOf(value);
聽聽聽聽聽聽聽}catch(Exception e){
聽聽聽聽聽聽聽聽e.printStackTrace();
聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽return l;
聽聽聽聽聽聽}
聽聽聽聽聽};
聽聽聽聽}
聽聽聽};
聽聽聽filter.setConvertEmptyInputStringToNull(false);//TextField榛樿璁句負true錛屽鏋滄病鏈夎緭鍏ワ紝杞負null銆傛澶勮涓虹┖瀛楃涓?"
聽聽聽enableFocusTracking(filter);
聽聽聽add(filter);
聽聽}
聽聽public final TextField getFilter(){
聽聽聽return filter;
聽聽}聽聽
聽}
]]>
> the Request Header "accept-charset". If this is not available than we have
> our default charset.
It is already implemented The default is UTF-8 and can be configured
via getRequestCycleSettings().setResponseRequestEncoding(String)
2
> Why there's no setConverter(IConverter c) just like add(IValidator v) returning the object itself?
to elaborate a little
lets say we did let you use a setter
then we have to keep a reference to the converter in the Component, so when serialized it is one more object - that almost never changes - that has to be serialized. making components session footprint even bigger.
also if we let you use a setter we have to version the changes - so thats yet another object we have to add to session (the undo object)
by making getconverter() overridible we eliminate the two scenarios above.
-Igor
if you want one right now then you have to create your own variant that doesnt use an embedded form. it would be pretty much a copy and paste job of the current toolbar but w/out the form.
-Igor
鍐嶄竴嬈℃劅璋gor錛屾瘡嬈¢兘鏄繖浣嶈佸ぇ甯垜瑙e喅鐩稿叧闂銆?br />http://www.nabble.com/filtertable-and-checkgroup-cannot-work-together-tf2195268.html