-
1. Re: form call methods with null value when loading
ilya_shaikovsky Sep 6, 2010 10:46 AM (in response to chalu)please show the code.
-
2. Re: form call methods with null value when loading
chalu Sep 12, 2010 5:12 PM (in response to ilya_shaikovsky)well.
here is xhtml:
....
<h:form id="AddTaskForm" ><h:panelGrid width="680px" columns="2" border="0"><rich:panel header="#{messages.tasks_newtask_header}" style="background-color: #ebf3fd;"><h:inputHidden id="id" value="#{taskFormBean.id}"/><h:inputHidden id="projectId" value="#{taskFormBean.projectId}"/><h:outputText value="*" style="color:#ff0000;"/>#{messages.registration_are_mandatory}.<h:panelGrid id="upg" columns="2" border="0" cellspacing="0" cellpadding="0"><h:panelGroup><h:outputText value="#{messages.task_name}" /><h:outputText value="*" style="color:#ff0000;"/></h:panelGroup><h:panelGroup><h:inputText id="name" value="#{taskFormBean.name}" styleClass="inputbox"/><h:message for="name" styleClass="errors" /></h:panelGroup><h:panelGroup><h:outputText value="#{messages.task_project_phase}" /></h:panelGroup><h:panelGroup><h:selectOneMenu value="#{taskFormBean.phaseId}" id="phaseId" ><f:selectItems value="#{taskFormBean.phases}" /></h:selectOneMenu></h:panelGroup><h:form id="AddTaskForm" >
<h:panelGrid width="680px" columns="2" border="0">
<rich:panel header="#{messages.tasks_newtask_header}" style="background-color: #ebf3fd;">
<h:inputHidden id="id" value="#{taskFormBean.id}"/>
<h:inputHidden id="projectId" value="#{taskFormBean.projectId}"/>
<h:outputText value="*" style="color:#ff0000;"/>#{messages.registration_are_mandatory}.
<h:panelGrid id="upg" columns="2" border="0" cellspacing="0" cellpadding="0">
<h:panelGroup>
<h:outputText value="#{messages.task_name}" />
<h:outputText value="*" style="color:#ff0000;"/>
</h:panelGroup>
<h:panelGroup>
<h:inputText id="name" value="#{taskFormBean.name}" styleClass="inputbox"/>
<h:message for="name" styleClass="errors" />
</h:panelGroup>
<h:panelGroup>
<h:outputText value="#{messages.task_project_phase}" />
</h:panelGroup>
<h:panelGroup>
<h:selectOneMenu value="#{taskFormBean.phaseId}" id="phaseId" >
<f:selectItems value="#{taskFormBean.phases}" />
</h:selectOneMenu>
</h:panelGroup>
...
<h:panelGroup>
<h:outputText value="" />
</h:panelGroup>
<h:panelGroup>
<h:commandButton value="#{messages.task_save}" action="#{taskFormBean.save}" styleClass="submitButton"/>
<h:commandButton value="Cancel" action="#{taskFormBean.cancel}" styleClass="submitButton"/>
</h:panelGroup>
in faces-config I have
taskFormBean mapped into class without any methods, which works with another form fields.
In class I have:
public List<SelectItem> getPhases() {
log.info("call getPhases for project id = "+this.projectId);
List<SelectItem> projectPhases = new ArrayList<SelectItem>();
if(this.projectId!=null && this.projectId.intValue()>0){
SelectItem it = new SelectItem();
it.setValue(0);
it.setLabel("---");
projectPhases.add(it);
try{
if(localProjects == null)
localProjects = (ProjectLogicLocal)ServiceLocator.getEJB(ProjectLogicLocal.LocalJNDIName);
for(ProjectPhase p:localProjects.listBaseProjectPhasesByProject(projectId)){
SelectItem i = new SelectItem();
i.setValue(p.getId());
i.setLabel(p.getName());
projectPhases.add(i);
}
log.info("have phases: "+projectPhases.size());
}
catch(BusinessException e){
super.storeErrorMessage(e.getMessage());
}
catch(Exception e){
log.error(e.getMessage());
e.printStackTrace();
}
finally{
localProjects = null;
}
}
else{
SelectItem i = new SelectItem();
i.setValue(0);
i.setLabel("---");
projectPhases.add(i);
}
return projectPhases;
}
and method save:
public String save() throws Exception{
log.info("call save form data: "+toString());
return "success";
}
When I let the phase field not selected as other fields, I have in my log:
23:08:16,568 INFO [TaskFormBean] call constructor
23:08:16,568 INFO [TaskFormBean] call getPhases for project id = null
23:08:16,570 INFO [TaskFormBean] call save form data: id = 0, parrentTaskId = 0, name = , projectId = 500, budgetHours = 0.0, percentageComplete = 0.0, dueDate = null, phase = 0, active = false, allowHours = false, hoursToConfirm = false, description =
23:08:16,588 INFO [TaskFormBean] call getPhases for project id = 500
23:08:16,619 INFO [TaskFormBean] have phases: 6
23:08:16,623 INFO [TaskFormBean] call getParentTasks()
23:08:16,670 INFO [TaskFormBean] count of tasks: 6
but if I choose one phase, I got:
23:09:58,872 INFO [TaskFormBean] call constructor
23:09:58,873 INFO [TaskFormBean] call getPhases for project id = null
23:09:58,942 INFO [TaskFormBean] call getPhases for project id = null
23:09:58,945 INFO [TaskFormBean] call getParentTasks()
23:09:58,974 INFO [TaskFormBean] count of tasks: 0
23:09:58,995 INFO [lifecycle] WARNING: FacesMessage(s) have been enqueued, but may not have been displayed.
sourceId=AddTaskForm:phaseId[severity=(ERROR 2), summary=(AddTaskForm:phaseId: Validation Error: Value is not valid), detail=(AddTaskForm:phaseId: Validation Error: Value is not valid)]
there is no validation defined in faces-config....If I change phaseId to any another name, error is still here with new name...