如何在JSF2中获取REST资源的链接
比如说,我有一个简单的REST服务,可以获取PDF文件的内容:如何在JSF2中获取REST资源的链接,rest,jsf,Rest,Jsf,比如说,我有一个简单的REST服务,可以获取PDF文件的内容: @Path("/pdf") @Stateless public class GroupSheetEJB { . . . @GET @Path("examsheet/{groupId: \\d+}/{course: \\d+}/{semester: \\d+}/{subjectId: \\d+}") @Produces("application/pdf") public Response examSheet(@Pat
@Path("/pdf")
@Stateless
public class GroupSheetEJB {
. . .
@GET
@Path("examsheet/{groupId: \\d+}/{course: \\d+}/{semester: \\d+}/{subjectId: \\d+}")
@Produces("application/pdf")
public Response examSheet(@PathParam("groupId") int groupCode, @PathParam("course") int course,
@PathParam("semester") int semester, @PathParam("subjectId") int subjectCode) {
try {
StudyGroup grp = groups.get(groupCode);
Subject sub = subjects.get(subjectCode);
ResponseBuilder response = Response.ok(getExamSheet(grp, sub, course, semester));
return response.build();
} catch (Exception e) {
throw new NotFoundException(e.getMessage());
}
}
}
是否有任何方法可以轻松地从
组件获取此REST服务的链接?
现在我使用纯HTML标记:
<a target="examsheet" href="#{request.contextPath}/webresources/#{semesterSubjectMarksMB.examSheetLink}">REST link</a>
output
参数的值为/webresources/#{semestsubjectmarksmb.examSheetLink}
获取禁用的链接
致意。如果
a
标记对您来说足够了,为什么要使用h:link
?足够了,但我可以根据各种条件重新渲染。我只是想知道——也许有一些机制可以获取REST服务的路径。硬编码链接是好的解决方案吗?您可以在ui:fragment
片段中包装a
标记,以决定是否渲染。如果要使用JSF特定的标记,请改用h:outputLink
: