[Ajax4JSF] JSF1.2自定义组件 Form提交 页面刷新
freesky_zh
2009-08-04
在JSF1.2中开发了一个dropdownList标签,组件类继承自HtmlSelectOneMenu,在renderer class中实现了decode/encodeBegin方法,
it'ok for displaly, the problem is that after form submission, the next page should be shown, but the current page has been refreshed and still there, the system can't navigate to the next page. In debug mode, I found every time after form submission, the decode methode has been called, but after it, the encodeBegin method will be invoked again to refresh the current page.
I use <h:messages> to show erros which is "Validation Error: Value is not valid "
I don't know what's wrong with it. could anyone tell me the reason? Thanks a lot. |
|
freesky_zh
2009-08-04
there is an error:
Validation Error: Value is not valid |
|
terryzhou
2009-08-05
no idea..
Never develope any component by myself...Just use it. What is special function of your component? |
|
freesky_zh
2009-08-05
I have solved it, the problem is the usage, in JSF, we use <h:selectOneMenu> tag as below.
<h:selectOneMenu id="oneMenu" value="#{bean.value}" immediate="true" > <f:selectItem itemLabel="option1" itemValue="1" /> <f:selectItem itemLabel="option2" itemValue="2" /> </h:selectOneMenu> in my custom tag, the usage is as below, <tag:selectOneChoice id="xxx" value="#{bean.value}" dept="xxx" /> I get the value list according to the 'dept' atttibute, my Component class extends HtmlSelecOneMenu, but there is no children in the tag, so it cause the problem below. the solution is that in the encodeEnd() method, add children using the value list, such as private void addChildren(MyComponent alComp, List<Employee> valueList) { List<UIComponent> children = alComp.getChildren(); for (Employee employee: valueList) { UISelectItem item = new UISelectItem(); item.setItemLabel(employee.getName()); item.setItemValue(employee); children.add(item); } } in MyComponent, override the validate(FacesContext context) method. |
|
terryzhou
2009-08-06
Map is esay than List;
<f:selectItems value="#{bean.map}" /> |
|
freesky_zh
2009-08-06
thanks for you advice.
in our project, this custom tag is used in several modules, so we don't need to construct Map or List of backingbean in every module. this can be handled in the tag. so we don't use <f:selectItems>. it tag also do the formatting and masking task according to the attribute which don't need to be done individually. |
|
terryzhou
2009-08-06
few code = high quality!It's more efficiency in China.Because lots of chinese software company have never attention for QA.
Another,Facelets can replace 90(+) percent of custom component(tag) in JSF. Only Suggestion above. |