我一直在学习教程
http://www.primefaces.org/showcase-ext/sections/dynaform/basicUsage.jsf
我已经能够创建树Dynaform对象并将其发送到页面。但我很难获得用户单击提交后输入的值。我希望能够在backbean中获得这些值。
这是提交按钮
<p:commandButton value="Submit" action="#{dynaFormController.submitForm}"
process="dynaForm" update=":mainForm:dynaFormGroup :mainForm:inputValues"
oncomplete="handleComplete(xhr, status, args)"/>
<p:commandButton type="reset" value="Reset" style="margin-left: 5px;"/>
我知道提交调用这个函数
<h:outputScript id="dynaFormScript" target="body">
/* <![CDATA[ */
function handleComplete(xhr, status, args) {
if(args && args.isValid) {
PF('inputValuesWidget').show();
} else {
PF('inputValuesWidget').hide();
}
}
/* ]]> */
</h:outputScript>
然后在豆中我们有:
public String submitForm() {
FacesMessage.Severity sev = FacesContext.getCurrentInstance().getMaximumSeverity();
boolean hasErrors = (sev != null && (FacesMessage.SEVERITY_ERROR.compareTo(sev) >= 0));
RequestContext requestContext = RequestContext.getCurrentInstance();
requestContext.addCallbackParam("isValid", !hasErrors);
return null;
}
如何从提交的表单中获取字段值?我有3个dynaform,我想提交它们,并能够在backbean中获得值。有人能解释一下吗?我试着查了一些教程,但没有找到任何解释。
谢谢。
它与普通JSF相同。
您的bean中需要一个变量,它的getter和setter。然后,将其与DynaFormControl进行比较。
@ManagedBean
@SessionScoped
public class DynaFormController implements Serializable {
private static final long serialVersionUID = 1L;
private DynaFormModel model;
private BookProperty bookProperty;
public String getBookProperty() {
return bookProperty;
}
public void setBookProperty(BookProperty bookProperty) {
this.bookProperty = bookProperty;
}
public String submitForm() {
//your code
List<DynaFormControl> controls = model.getControls();
for (DynaFormControl control : controls) {
if(control.getData() instanceof BookProperty) {
BookProperty bp = (BookProperty) c.getData();
//use the object
}
}
return null;
}
}