我想分享我使用primefaces,f:viewParam和p:commandButton的经验,并提出几个问题.看一下这个页面:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head></h:head>
<h:body>
<f:metadata>
<f:viewParam required="true" name="id_file" value="#{bean.idFile}" />
</f:metadata>
<h:form id="tableform" prependId="false">
<p:commandButton actionListener="#{bean.myMethod())}" icon="ui-icon-search" title="View" />
</h:form>
<p:messages id="messages" showDetail="true" autoUpdate="true" closable="true" />
</h:body>
</html>
Run Code Online (Sandbox Code Playgroud)
支持bean有一个"myMethod()"方法,什么都不做.当您进入页面时,它需要"id_file"参数并将其放在辅助bean的idFile属性中.然后单击按钮,调用myMethod.然后再次单击,您会得到一个模糊的验证错误,并且永远不会调用myMethod:
j_idt1: Validation Error: Value is required.j_idt1: Validation Error: Value is required.
Run Code Online (Sandbox Code Playgroud)
首先,请记住,如果没有p:消息,您无法看到此消息,您必须挖掘primefaces在ajax调用上发送的XML.其次,经过4个小时的调试后,我试图改变f:viewParam,如下所示:
<f:viewParam name="id_file" value="#{bean.idFile}" />
Run Code Online (Sandbox Code Playgroud)
没有"必需":神奇地一切都开始工作,我可以点击1,2,3等,每次调用myMethod.所以,问题是ajax submit验证了用f:viewParam指定的参数,对我来说听起来很傻,但好吧,我可以忍受它.
我的问题是:
为什么在第一次点击按钮时没有出现此验证错误?如果你看一下ajax POST,它们是完全相同的
在部分ajax调用中验证视图参数(在我的想法中,属于视图)应该可以吗?
有没有办法告诉primefaces不要对特定的ajax请求进行验证(process ="@ this"无法解决)?
谢谢,我希望我的经验能让您避免花费数小时进行调试!
假设我已经定义了这些 REST 端点:
@RequestMapping(path = "/user")
@RestController
public class ConfigUserController {
[...]
@GetMapping(path = "/variables/")
public ResponseEntity<List<Variable>> getAllVariables(...)
[...]
}
@GetMapping(path = "/variables/{name}")
public ResponseEntity<Variable> getVariableByName(...)
[...]
}
@PutMapping(path = "/variables/{name}/{value}")
public ResponseEntity<Variable> setVariableByName(...)
[...]
}
}
Run Code Online (Sandbox Code Playgroud)
我定义了两个过滤器(日志记录和授权),在过滤器内我想获取与当前请求匹配的 url-patter。使用上面的例子:
基本上我需要的是获取过滤器的 doFilter(ServletRequest request, ServletResponse response, FilterChain chain) 方法内的映射注释中定义的路径。
理想情况下,我希望能够像这样访问过滤器中的 url-pattern 值:
@Component
@Order(3)
public class MyAuthorizationRequestFilter extends GenericFilterBean {
[...]
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws …Run Code Online (Sandbox Code Playgroud)