Image upload is now updated and cleaned up.

This commit is contained in:
tim holloway 2024-02-02 06:54:42 -05:00
parent 5083086ff4
commit 2600500344
3 changed files with 9 additions and 39 deletions

View File

@ -1063,37 +1063,21 @@ public class RecipeDetailBean implements Serializable {
// *** // ***
UploadedFile imageFile = null;
/**
* @return the imageFile set by the image upload control
*/
public UploadedFile getImageFile() {
return imageFile;
}
/**
* @param imageFile the imageFile to set
*/
public void setImageFile(UploadedFile imageFile) {
this.imageFile = imageFile;
}
/** /**
* Load/replace images. Computes thumbnail. * Load/replace images. Computes thumbnail.
* *
* @param event PrimeFaces file upload event object * @param event PrimeFaces file upload event object
*/ */
public void ajaxUploadImage(FileUploadEvent event) { public void ajaxUploadImage(FileUploadEvent event) {
PictureController.importImage(recipe, event.getFile().getContent()); PictureController.importImage(recipe,
event.getFile().getContent());
} }
/** /**
* Remove images from recipe * Remove images from recipe
*
* @param event Notused
*/ */
public void ajaxDeleteImage(AjaxBehaviorEvent event) { public void ajaxDeleteImage() {
log.info("Deleting current recipe image");
this.recipe.setImage(null); this.recipe.setImage(null);
this.recipe.setThumb(null); this.recipe.setThumb(null);
} }

View File

@ -4,8 +4,6 @@ import jakarta.faces.application.ViewExpiredException;
import jakarta.servlet.ServletContext; import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletException; import jakarta.servlet.ServletException;
import org.primefaces.application.resource.PrimeResourceHandler;
import org.primefaces.renderkit.HeadRenderer;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan; import org.springframework.boot.autoconfigure.domain.EntityScan;
@ -21,8 +19,6 @@ import org.springframework.http.HttpStatus;
"com.mousetech.gourmetj.persistence.model" }) "com.mousetech.gourmetj.persistence.model" })
public class SpringPrimeFacesApplication { public class SpringPrimeFacesApplication {
private static final String IMAGE_IIO_PROVIDER_CONTEXT_LISTENER =
"com.twelvemonkeys.servlet.image.IIOProviderContextListener";
final String errorPage = "/error/error.html"; final String errorPage = "/error/error.html";
final String error404Page = "/error/error404.html"; final String error404Page = "/error/error404.html";
final String expiredPage = "/error/viewExpired.xhtml"; final String expiredPage = "/error/viewExpired.xhtml";
@ -38,13 +34,6 @@ public class SpringPrimeFacesApplication {
@Override @Override
public void onStartup(ServletContext servletContext) public void onStartup(ServletContext servletContext)
throws ServletException { throws ServletException {
/* Note that we cannot set theme here since it was
* already set earlier. Default value is "aristo".
*/
servletContext.setInitParameter(
"joinfaces.primefaces.theme", "vela");
servletContext.setInitParameter(
"primefaces.THEME", "overcast");
servletContext.setInitParameter( servletContext.setInitParameter(
"jakarta.faces.FACELETS_SKIP_COMMENTS", "jakarta.faces.FACELETS_SKIP_COMMENTS",
"true"); "true");
@ -53,7 +42,6 @@ public class SpringPrimeFacesApplication {
"com.sun.el.ExpressionFactoryImpl"); "com.sun.el.ExpressionFactoryImpl");
servletContext.setInitParameter( servletContext.setInitParameter(
"primefaces.UPLOADER", "native"); "primefaces.UPLOADER", "native");
//servletContext.addListener(IMAGE_IIO_PROVIDER_CONTEXT_LISTENER);
} }
}; };
} }

View File

@ -149,14 +149,15 @@
rows="10" cols="45" rows="10" cols="45"
value="#{recipeDetailBean.recipe.description}" value="#{recipeDetailBean.recipe.description}"
/> />
</p:panelGrid>
<p:panel id="picPanel"> <p:panel id="picPanel">
<img id="bigPix" <img id="bigPix"
src="/img/picture/?dt=#{recipeDetailBean.currentTime}" src="/img/picture/?dt=#{recipeDetailBean.currentTime}"
/> />
</p:panel> </p:panel>
<p:panelGrid id="picButtonPanel" columns="2">
<p:fileUpload id="ctlUpload" <p:fileUpload id="ctlUpload"
label="Upload Image" label="Upload Image"
value="#{recipeDetailBean.imageFile}"
listener="#{recipeDetailBean.ajaxUploadImage}" listener="#{recipeDetailBean.ajaxUploadImage}"
global="true" mode="advanced" global="true" mode="advanced"
multiple="false" multiple="false"
@ -167,14 +168,11 @@
/> />
<p:commandButton id="ctlDelImg" <p:commandButton id="ctlDelImg"
value="Delete Image" value="Delete Image"
> action="#{recipeDetailBean.ajaxDeleteImage}"
<f:ajax update="picPanel"
listener="#{recipeDetailBean.ajaxDeleteImage}"
render="picPanel"
immediate="true" immediate="true"
/> />
</p:commandButton> </p:panelGrid>
</p:panelGrid>
</p:tab> </p:tab>
<p:tab id="ingredientsTab" <p:tab id="ingredientsTab"
title="Ingredients" title="Ingredients"