如何为具有复合主键的实体编写转换器?
我想使用 URl 编辑实体,例如 `\edit_representative.xhtml?emp_id=12345&project_id=45
我正在使用 Omnifaces,所以我对单个主键有类似的东西
<o:viewParam name="emp_id" value="#{projectRepEdit.projectRep}"
converter="#{projectRepConverter}"
converterMessage="Bad request. Unknown Project Representative." required="true"
requiredMessage="Bad request. Please use a link from within the system." />
但我如何将员工正在处理的 project_id 传递给转换器
编辑
根据 BalusC 的回答,我使用了第二个选项,并在我的projectRepConverter
转换器中有以下内容
String project_id = (String) component.getAttributes().get("project_id");
String emp_id= (String) component.getAttributes().get("emp_id");
ProjectRep prjRep = prjRepRepository.getByEmpIdAndProjectId(emp_id,project_id);
return prjRep;
在小脸上
<f:metadata>
<o:viewParam name="project_id" value="#{projectRepEdit.project}"
converter="#{projectConverter}"
converterMessage="Bad request. Unknown Project." required="true"
requiredMessage="Bad request. Please use a link from within the system." />
<o:viewParam name="badge" value="#{projectRepEdit.projectRep}"
converter="#{projectRepConverter}"
converterMessage="Bad request. Unknown Project Rep." required="true"
requiredMessage="Bad request. Please use a link from within the system.">
<f:attribute name="project_id" value="#{param.project_id}" />
<f:attribute name="emp_id" value="#{param.emp_id}" />
</o:viewParam>