我在搜索表单中遇到了一点问题,因为我在搜索字段中输入的所有数据都以空值传递给我的 java 代码。我是 jsf2 的新手。
这是我的 xhtml 页面,格式如下:
<h:form>
<ul>
<li>
<h:outputLabel for="equipmentName" value="#{bundle.NomeEquipamento_Title}"/>
<h:inputText value="#{materialController.selected.equipmentName}" class="w_130" id="equipmentName" required="false" validatorMessage="#{bundle.NomeEquipamento_Title} inválido."/>
</li>
<li>
<h:outputLabel for="channelCode" value="#{bundle.CodigoCanal_Title}"/>
<h:inputText value="#{materialController.selected.channelCode}" class="w_80" id="channelCode" required="false" validatorMessage="#{bundle.CodigoCanal_Title} inválido."/>
</li>
<li><h:commandButton type="reset" class="bt_limpar button29" style="margin-top:13px;"><span class="screen_reader_text">Limpar</span></h:commandButton></li>
<li><h:commandLink action="#{materialController.pesquisa}" class="bt_pesquisar button29" style="margin-top:13px;" immediate="true"><span class="screen_reader_text">Pesquisar</span></h:commandLink></li>
</ul>
</h:form>
这是我的 DTO,具有两个属性“设备名称”和“通道代码”:
public class SearchCommercialsDTO implements Serializable{
private String equipmentName;
private Integer channelCode;
/**
* Default constructor
*/
public SearchCommercialsDTO() {}
/**
* Constructor
* @param equipmentName
* @param channelCode
*/
public SearchCommercialsDTO(String equipmentName, Integer channelCode) {
this.equipmentName = equipmentName;
this.channelCode = channelCode;
}
public String getEquipmentName() {
return equipmentName;
}
public void setEquipmentName(String equipmentName) {
this.equipmentName = equipmentName;
}
public Integer getChannelCode() {
return channelCode;
}
public void setChannelCode(Integer channelCode) {
this.channelCode = channelCode;
}
}
这是我的管理豆:
@ManagedBean(name = "materialController")
@SessionScoped
public class MaterialController implements Serializable {
private SearchCommercialsDTO current;
private int selectedItemIndex;
public MaterialController() {
}
public SearchCommercialsDTO getSelected() {
if (current == null) {
current = new SearchCommercialsDTO();
selectedItemIndex = -1;
}
return current;
}
public String pesquisa() {
try{
getFacade().find(current);
JsfHelper.addSuccessMessage(ResourceBundle.getBundle("/Bundle").getString("PesquisaRealizada"));
return preparaPesquisa();
} catch (Exception e) {
JsfHelper.addErrorMessage(e, ResourceBundle.getBundle("/Bundle").getString("PersistenceErrorOccured"));
return null;
}
}
}
当我单击“Pesquisar”按钮时,会发布帖子,但“SearchCommercialsDTO”属性“current”会与所有属性值“null”一起传递,即使我在输入文本字段中键入了一些内容。
我的代码中缺少什么?
谢谢!