1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:corejsf="http://corejsf.com" xmlns:util="http://java.sun.com/jsf/composite/util"> <h:head> <hutputStylesheet library="css" name="styles.css"/> <title>#{msgs.windowTitle}</title> </h:head> <h:body> <hutputStylesheet library="css" name="styles.css"/> <hutputText value="#{msgs.fontSizeHeading}" style="padding-left: 30px; font-size: 2em;"/> <h:panelGrid columns="3" style="padding-left: 80px;"> <util:icon id="minus" image="#{resource['images:minus.gif']}"> <f:actionListener for="link" type="com.clarity.FontSelectionListener"/> </util:icon> <util:icon id="plus" image="#{resource['images:plus.gif']}"> <f:actionListener for="link" type="com.clarity.FontSelectionListener"/> </util:icon> <hutputText id="readout" value="#{fontSettings.size}em"/> </h:panelGrid> <hutputText id="fontPreview" value="Aa" style="font-size: #{fontSettings.size}em; font-style: italic"/> </h:body> </html> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | package com.clarity; import javax.el.ELResolver; import javax.faces.component.UIComponent; import javax.faces.context.FacesContext; import javax.faces.event.AbortProcessingException; import javax.faces.event.ActionEvent; import javax.faces.event.ActionListener; public class FontSelectionListener implements ActionListener { @Override public void processAction(ActionEvent event) throws AbortProcessingException { FacesContext c = FacesContext.getCurrentInstance(); ELResolver elResolver = c.getApplication().getELResolver(); FontSettings fs = (FontSettings) elResolver.getValue(c.getELContext(), null, "fontSettings"); if (((UIComponent)event.getSource()).getClientId().startsWith("minus")) fs.decrement(); else fs.increment(); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | package com.clarity; import java.io.Serializable; import javax.inject.Named; import javax.enterprise.context.SessionScoped; @Named @SessionScoped public class FontSettings implements Serializable { private static int INCREMENT = 1; private int size = 1; public int getSize() { return size; } public void setSize(int newValue) { size = newValue; } public void increment() { size += INCREMENT; } public void decrement() { size -= INCREMENT; } } |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |