Skip to content

Commit

Permalink
bimage: Continue changes for b:image
Browse files Browse the repository at this point in the history
  • Loading branch information
yeray.santana committed Aug 30, 2015
1 parent e99b42c commit b7d3ebd
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 39 deletions.
46 changes: 27 additions & 19 deletions src/main/java/net/bootsfaces/component/image/Image.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,23 @@ public Image() {
private static final Collection<String> EVENT_NAMES = Collections.unmodifiableCollection(Arrays.asList(
"click", "dblclick", "mousedown", "mousemove", "mouseout", "mouseover", "mouseup"));

public Collection<String> getEventNames() {
return EVENT_NAMES;
}

public String getDefaultEventName() {
return "click";
}

public String getFamily() {
return COMPONENT_FAMILY;
}

protected enum PropertyKeys {
alt,
binding,
disabled,
height,
lang,
name,
onclick,
oncomplete,
Expand Down Expand Up @@ -92,24 +100,6 @@ public void setAlt(String _alt) {
}


/**
* An el expression referring to a server side UIComponent instance in a backing bean. <P>
* @return Returns the value of the attribute, or null, if it hasn't been set by the JSF file.
*/
public javax.faces.component.UIComponent getBinding() {
javax.faces.component.UIComponent value = (javax.faces.component.UIComponent)getStateHelper().eval(PropertyKeys.binding);
return value;
}

/**
* An el expression referring to a server side UIComponent instance in a backing bean. <P>
* Usually this method is called internally by the JSF engine.
*/
public void setBinding(javax.faces.component.UIComponent _binding) {
getStateHelper().put(PropertyKeys.binding, _binding);
}


/**
* Boolean value to specify if the button is disabled. <P>
* @return Returns the value of the attribute, or null, if it hasn't been set by the JSF file.
Expand Down Expand Up @@ -146,6 +136,24 @@ public void setHeight(String _height) {
}


/**
* Code describing the language used in the generated markup for this component. <P>
* @return Returns the value of the attribute, or null, if it hasn't been set by the JSF file.
*/
public String getLang() {
String value = (String)getStateHelper().eval(PropertyKeys.lang);
return value;
}

/**
* Code describing the language used in the generated markup for this component. <P>
* Usually this method is called internally by the JSF engine.
*/
public void setLang(String _lang) {
getStateHelper().put(PropertyKeys.lang, _lang);
}


/**
* Icon name, mandatory. <P>
* @return Returns the value of the attribute, or null, if it hasn't been set by the JSF file.
Expand Down
49 changes: 45 additions & 4 deletions src/main/java/net/bootsfaces/component/image/ImageRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@

import java.io.IOException;

import javax.faces.application.FacesMessage;
import javax.faces.application.ProjectStage;
import javax.faces.application.Resource;
import javax.faces.application.ResourceHandler;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import javax.faces.render.FacesRenderer;

import net.bootsfaces.component.ajax.AJAXRenderer;
import net.bootsfaces.render.A;
import net.bootsfaces.render.CoreRenderer;
import net.bootsfaces.render.Tooltip;

Expand Down Expand Up @@ -43,13 +48,49 @@ public void encodeBegin(FacesContext context, UIComponent component) throws IOEx
ResponseWriter rw = context.getResponseWriter();
String clientId = image.getClientId();

// put custom code here
// Simple demo widget that simply renders every attribute value
rw.startElement("image", image);

rw.startElement("img", image);
Tooltip.generateTooltip(context, image, rw);
rw.writeAttribute("id", clientId, "id");
rw.writeURIAttribute("src", this.getImageSource(context, component, "value"), "value");

renderPassThruAttributes(context, image, A.IMAGE);

writeAttribute(rw, "class", image.getStyleClass(), "styleClass");

rw.endElement("image");
AJAXRenderer.generateBootsFacesAJAXAndJavaScript(FacesContext.getCurrentInstance(), image, rw);

rw.endElement("img");
Tooltip.activateTooltips(context, image);
}

/**
* <p>
* Determine the path value of an image value.
* </p>
*
* @param context the {@link FacesContext} for the current request.
* @param component the component to obtain the image information from
* @param attrName the attribute name that needs to be queried if the
* name and library attributes are not specified
*
* @return the encoded path to the image source
*/
public static String getImageSource(FacesContext context, UIComponent component, String attrName) {


String value = (String) component.getAttributes().get(attrName);
if (value == null || value.length() == 0) {
return "";
}

ResourceHandler handler = context.getApplication().getResourceHandler();
if (handler.isResourceURL(value)) {
return value;
} else {
value = context.getApplication().getViewHandler().
getResourceURL(context, value);
return (context.getExternalContext().encodeResourceURL(value));
}
}
}
3 changes: 3 additions & 0 deletions src/main/java/net/bootsfaces/render/A.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ public static String asString(Map<String, Object> attrs, Object o) {
public static final String[] TAB_ATTRS = A.concatAll( H.TAB);
public static final String[] TAB_VIEW_ATTRS = A.concatAll( H.TAB_VIEW);
public static final String[] SELECT_ONE_MENU_ATTRS = A.concatAll( H.SELECT_ONE_MENU);
public static final String[] IMAGE = A.concatAll( H.IMAGE);



/**
* Joins two arrays efficiently.
Expand Down
29 changes: 21 additions & 8 deletions src/main/java/net/bootsfaces/render/H.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,28 @@ public final class H {

// NOTE: disabled, styleClass are handled by component
public static final String[] ALLBUTTON = {
"accesskey",
"dir",
//DISABLED,
"lang",
STYLE,
"tabindex",
TITLE
"accesskey",
"dir",
//DISABLED,
"lang",
STYLE,
"tabindex",
TITLE
};



public static final String[] IMAGE = {
"alt",
"height",
"lang",
"style",
"title",
"width",
};




// Suppress default constructor for noninstantiability
private H() {
throw new AssertionError();
Expand Down
Loading

0 comments on commit b7d3ebd

Please sign in to comment.