【发布时间】:2019-09-03 15:09:40
【问题描述】:
我有两种不同的表单,如果我对一个表单应用操作,则第二种表单中的字段值正在重置(清除或恢复为默认值),我不知道发生了什么?
我正在使用带有 JSF 的 Primefaces 7(jsf-api 2.2.11、jsf-impl 2.2.11 和 javax.servlet-api 3.0.1)。
我试图从下面的帖子中覆盖 Sammy 函数
https://stackoverflow.com/questions/10652881/how-to-prevent-form-submit#I%20also%20had%20this%20problem%20and%20I%20found%20a%20solution%20in
我也尝试保存缓存
< -meta http-equiv="cache-control" content="cache, store" / ->
这是我的第一个表单代码
<h:form id="createStageForm" class="form-horizontal">
<h:outputLabel >Notes :</h:outputLabel>
<h:inputText value="#{stageBean.stageDto.notes}"/>
<h:commandButton value="Save" action="#{stageBean.saveDetails}"/>
</h:form>
和第二种形式
<h:form>
<h:dataTable value="#{stageBean.items}" var="item">
<h:column>
<h:inputText value="#{item.name}" />
</h:column>
<h:column>
<h:commandButton value="-" action="#{stageBean.remove(item)}" />
</h:column>
</h:dataTable>
<h:commandButton value="+" action="#{stageBean.add}" />
</h:form>
我更新帖子以在下面设置 Bean 实现
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
@ManagedBean
@ViewScoped
public class StageBean {
private List<EmployeeDto> items;
public ArrayList<StageDto> listFromDB;
private StageDto stageDto;
@PostConstruct
public void init() {
listFromDB = SatgeDatabaseOperation.getListFromDB();
items = new ArrayList<EmployeeDto>();
items.add(new EmployeeDto());
}
private long id;
private String notes;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getNotes() {
return notes;
}
public void setNotes(String notes) {
this.notes = notes;
}
public void add() {
items.add(new EmployeeDto());
}
public void remove(EmployeeDto item) {
items.remove(item);
}
public void save() {
System.out.println("items: " + items);
}
public ArrayList<StageDto> getListFromDB() {
return listFromDB;
}
public void setListFromDB(ArrayList<StageDto> listFromDB) {
this.listFromDB = listFromDB;
}
public String saveDetails() {
return SatgeDatabaseOperation.saveDetailsInDB(stageDto);
}
}
在第二个表单上应用操作时是否有防止表单重置的方法?
【问题讨论】:
-
我不知道你的意思。什么是“休息”或“休息”?请发送minimal reproducible example。这都是简单的 jsf,没有 PrimeFaces。并发布 JSF 实现和版本
-
我的意思是在另一个表单的字段中休息或清除值,是的,这都是纯 jsf,我将使用 JSF 实现更新帖子
-
你的意思是重置而不是休息?还做一个真正的minimal reproducible example。最有可能与范围相关
-
是的,抱歉我的错字
-
那么请在reset中编辑reat。这不是minimal reproducible example。 Waaay太多的代码。请改进
标签: jsf