primefaces: ValidateFile: with variable in sizeLimit not working
Describe the bug
If i use p:valiadteFile with a variable in sizeLimit (fileUploadView.size) it doesn’t consider it at runtime.
<h:form id="frmTest">
<p:growl id="growl" sticky="true" showDetail="true"/>
<p:inputText value="#{fileUploadView.size}" >
<p:ajax update="xx,input20" />
</p:inputText>
<h:outputText id="xx" value="#{fileUploadView.size}" />
<p:fileUpload id="input20" update="growl"
listener="#{fileUploadView.handleFileUpload}"
mode="advanced" dragDropSupport="true" auto="true" >
<p:validateFile sizeLimit="#{fileUploadView.getSizeLimit(fileUploadView.size)}" allowTypes="/(\.|\/)(gif|jpeg|jpg|png)$/" />
</p:fileUpload>
</h:form>
@Named
@RequestScoped
public class FileUploadView {
private UploadedFile file;
private String size;
public void upload() {
if (file != null) {
FacesMessage message = new FacesMessage("Successful", file.getFileName() + " is uploaded.");
FacesContext.getCurrentInstance().addMessage(null, message);
}
}
public void handleFileUpload(FileUploadEvent event) {
FacesMessage message = new FacesMessage("Successful", event.getFile().getFileName() + " is uploaded.");
FacesContext.getCurrentInstance().addMessage(null, message);
}
public UploadedFile getFile() {
return file;
}
public void setFile(UploadedFile file) {
this.file = file;
}
public String getSizeLimit(String limit) {
if (limit != null) {
return limit;
}
return "100000";
}
@PostConstruct
public void init() {
setSize("70000");
}
public String getSize() {
return size;
}
public void setSize(String size) {
this.size = size;
}
}
Reproducer
No response
Expected behavior
No response
PrimeFaces edition
None
PrimeFaces version
14.0.2
Theme
No response
JSF implementation
Mojarra
JSF version
4.0
Java version
17
Browser(s)
No response
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 17 (14 by maintainers)
Commits related to this issue
- #12283: VE aware attribute handler for behaviours/validators — committed to jungm/primefaces by jungm 2 years ago
- #12283: add IT to test dynamic attribute for p:validateFile — committed to jungm/primefaces by jungm 2 years ago
- Fix #12283: Handle ValueExpression attributes on p:validateFile (#12287) * #12283: VE aware attribute handler for behaviours/validators * #12283: add IT to test dynamic attribute for p:validateFil... — committed to melloware/primefaces by jungm 2 years ago
IMO validator needs support for StateHelper like Components, thats whats missing in specs
We implemented it, @jungm could provide and we can migrate to it
not sure but the code in the behavior implements full-state saving, seems we didnt implement delta state here like MF does
maybe we should create a second issue about it