对于作业,我有一个需要4个整数(代表一个IP地址)的表格。在2页之间切换时,只有选中复选框时,才能保留IP地址和子网信息。到目前为止,我所做的所有尝试都是在页面加载时重置所有内容(因此,每当我提交表单时)或根本不清除。关于如何处理这个的任何建议?
支持Bean
@ManagedBean(name="controllerBean" )
@SessionScoped
public class CalculatorController implements Serializable{
CalculatorModel model;
public CalculatorModel getModel(){
return model;
}
public CalculatorController(){
super();
model = new CalculatorModel();
}
}
表格的一部分
<h:form id="calculator">
<table border="1">
<tr>
<th><h5>IP Address</h5></th>
<th><h5>Prefix Length</h5></th>
</tr>
<tr>
<td>
<h:panelGrid columns="4">
<h:inputText
id="firstOctet"
label="First Octet"
required="true"
size="1"
maxlength="3"
requiredMessage="Enter a valid "
value="#{controllerBean.model.firstOctet}">
</h:inputText>
表单包含3个inputTexts(对于其他八位字节),一个按钮和几个表来显示计算结果。
答案 0 :(得分:0)
这对你的任务来说可能为时已晚,希望你明白这一点。我就是这样做的:
<table border="1">
<tr>
<th><h5>IP Address</h5></th>
<th><h5>Prefix Length</h5></th>
</tr>
<tr>
<td>
<h:panelGrid columns="4">
<h:inputText
id="firstOctet"
label="First Octet"
required="true"
size="1"
maxlength="3"
requiredMessage="Enter a valid "
value="#{controllerBean.model.firstOctet}">
</h:inputText>
<!-- more inputs here-->
<h:selectOneBoolean value="#{controllerBean.saveValues}" />
<h:outputLabel value="Save Values?" />
<h:commandButton action="#{controllerBean.submit}" value="Go to other page"/>
和控制器bean:
@ManagedBean(name="controllerBean" )
@SessionScoped
public class CalculatorController implements Serializable{
CalculatorModel model;
boolean saveValues;
/* ...Getters and setters for CalculatorModel and saveValues... */
public CalculatorController(){
super();
model = new CalculatorModel();
}
public String submit() {
if (!saveValues) {
model.setFirstOctet(0);
// ... etc
model.setPrefixLength(0);
}
return "next-view-id";
}
}