Redraw jcaptcha using ajax by clicking the reload button If you reload the whole screen, jcaptcha will also be reloaded ...
xhtml
<!--jcaptcha display-->
<div class="jcaptchaItemBlook">
<h:graphicImage id="jcaptchaImage" value="/jcaptcha" />
</div>
<!--ajax mounting part-->
<h:commandButton class="jcaptchaReloadBtn" value="Image update" immediate="true">
`<f:ajax listener="#{controller.reload}" render="jcaptchaImage" event="click" />
</h:commandButton>
java
public String reload() throws CaptchaServiceException {
return "#{request.contextPath}/jcapcha" + Math.floor(Math.random() * 100);
}
xhtml
<!--jcaptcha display-->
<div class="jcaptchaItemBlook">
<img id="jcaptchaImage" src="#{request.contextPath}/jcaptcha" />
</div>
--The parts other than the description of the failure example are the same as the success example. --Since value could not be set as the return value of ajax with the img tag, graphicImage was adopted --When "# {request.contextPath} / jcapcha" is set in the graphicImage tag on the xhtml side, the contextPath is displayed twice, so delete it. --On the java side, it is necessary to add "# {request.contextPath} / jcapcha" as the return value.
--The problem that FireFox and IE do not refresh even though it works fine in chrome was discovered during testing!
xhtml
<!--jcaptcha display-->
<div class="jcaptchaItemBlook">
<p:graphicImage id="jcaptchaImage" value="/jcaptcha" cache="false" />
</div>
--Needed to change to primeFaces tag. --Add cache = "false".
xhtml
<!--jcaptcha display-->
<h:panelGroup class="jcaptchaItemBlook">
<p:graphicImage id="jcaptchaImage" value="/jcaptcha" cache="false" />
</h:panelGroup>
<!--ajax mounting part-->
<h:commandButton class="jcaptchaReloadBtn" value="Image update" immediate="true">
<f:ajax listener="#{controller.reload}" render="jcaptchaImage" event="click" />
</h:commandButton>
java
@Getter
@Setter
private String captchaImage;
public void reload() throws CaptchaServiceException {
this.setCaptchaImage("/jcaptcha");
}
--Changed to use setter by setting the return value to void according to the basics of ajax. -I felt it was subtle if it was
http://d.hatena.ne.jp/kaiseh/20090502/1241286415 http://www.in-vitro.jp/blog/index.cgi/Library/20050827_01.html
https://yoshio3.com/2011/01/18/jsf-20-ajax-support/ https://stackoverflow.com/questions/5822665/jcaptcha-refresh-only-image-not-whole-page
https://www.primefaces.org/docs/vdl/4.0/primefaces-p/graphicImage.html http://download.oracle.com/otn-pub/jcp/jsf-2.0-fr-eval-oth-JSpec/jsf-2_0-fr-spec.pdf
Recommended Posts