Web

Zbystřete své smysly technickými doplňky

<br /> {<br /> &quot;name&quot;:&quot;Ramjet Inspector&quot;,<br /> &quot;version&quot;:&quot;1.8&quot;,<br /> ... další povinné informace ...<br /> &quot;background&quot;:{<br /> &quot;scripts&quot;: [&quot;background.js&quot;]<br /> },<br /> &quot;permissions&quot;:[<br /> &quot;cookies&quot;,<br /> &quot;tabs&quot;,<br /> &quot;notifications&quot;,<br /> &quot;http://*/*&quot;,<br /> &quot;https://*/*&quot;,<br /> ],<br /> &quot;web_accessible_resources&quot;:[<br /> &quot;skin/INFO.png&quot;,<br /> &quot;skin/WARNING.png&quot;,<br /> &quot;skin/ERROR.png&quot;<br /> ]<br /> } var openNotifications = 0; //REGISTRACE LISTENERU NA ZMĚNY V COOKIES chrome.cookies.onChanged.addListener(function (data) { //zajímá nás pouze vytvoření cookie if (data.cause == "explicit" && data.

K čemu je nám užitečný komponentový web framework?

<recordListing> <dataSource class="com.fg.SomeProvider"/> </recordListing> <recordListing> <dataSource class="com.fg.SomeProvider"/> <column id="firstName"/> <orderableColumn id="lastName"/> <column id="age"/> <pagination/> </recordListing> <recordListing> <dataSource class="com.fg.SomeProvider"/> <column id="firstName"/> <orderableColumn id="lastName"> <columnFilter> <textInput id="filter.byName"/> </columnFilter> </orderableColumn> <column id="age"> <columnFilter> <textInput id="filter.fromAge"> <validators><number/></validators> </textInput> <textInput id="filter.toAge"> <validators><number/></validators> </textInput> </columnFilter> </column> <pagination/> </recordListing>

Máte jistotu, že do session ukládáte pouze serializovatelné objekty?

public class SerializabilityCheckFilter implements Filter { private static final Log log = LogFactory.getLog(SerializabilityCheckFilter.class); public void init(FilterConfig filterConfig) throws ServletException { //nothing necessary to do } public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { try { chain.doFilter(request, response); } finally { if (request instanceof HttpServletRequest) { HttpServletRequest httpRequest = (HttpServletRequest) request; HttpSession session = httpRequest.getSession(false); if (session != null) { boolean serializable = true; StringBuilder items = new StringBuilder(); Enumeration<String> names = session.

Commons File Upload contains a severe memory leak

public FileItem createItem(String fieldName, String contentType, boolean isFormField, String fileName) { DiskFileItem result = new DiskFileItem(fieldName, contentType, isFormField, fileName, sizeThreshold, repository); FileCleaningTracker tracker = getFileCleaningTracker(); if (tracker != null) { tracker.track(result.getTempFile(), this); } return result; } private static final class Tracker extends PhantomReference { private final String path; private final FileDeleteStrategy deleteStrategy; Tracker(String path, FileDeleteStrategy deleteStrategy, Object marker, ReferenceQueue queue) { super(marker, queue); this.path = path; this.deleteStrategy = (deleteStrategy == null ?

Monitoring embeded video plays

$(document).ready(function() { $("#video object").live("click", "alert('Played')"); }) var flashvars = { file: "/video/myvideo.flv", allowfullscreen: "false", allowscriptaccess: "always", image: "/img/thumbnail.jpg", bufferlength: "0", screencolor: "000000" }; swfobject.embedSWF( "/swf/u/jw-flv-player.swf", "video", "509", "382", "8.0.0", null, flashvars, { wmode: "transparent", allowFullScreen: "true" }, null, function (domObj) { $(domObj.ref).attr("onclick", "alert('Played')"); }); <!-- JW PLAYER --> <script type="text/javascript"> //<![CDATA[ var flashvars = { file: "/video/myvideo.flv", allowfullscreen: "false", allowscriptaccess: "always", image: "/img/thumbnail.jpg", bufferlength: "0", screencolor: "000000" }; swfobject.embedSWF( "/swf/u/jw-flv-player.

Zrychlete svoji webovou aplikaci pomocí Partial Update

$("#partialUpdateCnt").partialUpdate(); //první parametr je url pro partial update, //druhý parametr je ID DOM objektu jehož obsah se má vyměnit po odpovědi serveru <a href="..." onclick="return $.partialUpdate.execute(this.href, 'partialUpdateCnt');"/> <a href="..." onclick="$.post( this.href + '@partialUpdateCnt', function(data) { $('#partialUpdateCnt').replaceWith(data); }); return false; "/> var data = $("#formId").serializeArray(); $("#doplnIdKomponenty").partialUpdate(); http://www.domena.cz/stranka.html#kotva?parametr1=hodnota1

Jak jednoduše simulovat v testech HTTP server

import ResourcePublishServer server; public class ExampleTest extends TestCase { private CrlJob crlJob = new CrlJob(); @Override protected void onSetUp() throws Exception { server = new ResourcePublishServer(applicationContext); server.start(); super.onSetUp(); } @Override protected void onTearDown() throws Exception { server.stop(); super.onTearDown(); } public void testDownloadCrl() throws Exception { String crlAsResourceUrl = server.calculateUrl("/crl/kcanbusr3.crl"); // Vytvorime si certifikacni autoritu s CRL adresou ukazujici na testovaci HTTP server IAuthorityBo auth = authorityTestData.createWithCrlUrl(crlAsResourceUrl); crlJob.executeInternal(); assertEquals(1, crlDao.find(auth).size()); } }

iBatis 3.0 preview - část druhá

<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN" "http://ibatis.apache.org/dtd/ibatis-3-mapper.dtd"> <mapper namespace="domain.blog.mappers.AuthorMapper"> ... další definice ... SqlSession session = sqlMapper.openSession(); try { BlogMapper mapper = session.getMapper(BlogMapper.class); List posts = mapper.selectAllPosts(null, 0, 2); assertEquals(2, posts.size()); assertEquals(1, posts.get(0).get("ID")); assertEquals(2, posts.get(1).get("ID")); } finally { session.close(); } public interface BoundBlogMapper { @Select({"SELECT * FROM blog"}) List selectBlogs(); @Select({"SELECT * FROM blog"}) List selectBlogsAsMaps(); @Select("SELECT * FROM post ORDER BY id") @TypeDiscriminator( column = "draft", javaType = String.

JavaScript timers - naše staré hodiny, bijí čtyři hodiny

var serverTimeDifference; function setServerTime(serverTime) { serverTimeDifference = new Date().getTime() - serverTime.getTime(); } function getActualTime() { var actualTime = new Date(); actualTime.setTime(actualTime.getTime() - serverTimeDifference); return actualTime; }

Překonaný ResourceBundle, Spring MessageSource vítězí v prvním kole KO

ResourceBundle myResources = ResourceBundle.getBundle("MyResources", currentLocale); <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> <property name="basenames"> <list> <value>file:/projekt/neco/messages</value> <value>file:/projekt/neco/exceptions</value> <value>file:/projekt/neco/disclaimer</value> </list> </property> <property name="defaultEncoding" value="UTF-8"/> <property name="fallbackToSystemLocale" value="false"/> <property name="cacheSeconds" value="0"/> </bean>

jQuery effects - quick start

function example1() { $("#example1do").hide(); $("#example1undo").show("fast"); } function example2() { $(".example2").toggle(10000); } function example3() { $("#example3paragraph").hide("slow", function() { $(this).load("/text.txt", function(data) { $(this).show("slow"); }); }); } function testAnimations() { //ukázka z prvního příkladu //bude spuštěno paralelně - jedná se o odlišné DOM elementy $("#example1do").hide(); $("#example1undo").show("fast"); //pokud se ale to samé bude týkat stejného DOM elementu //jako je na tomto příkladě, bude spuštění sériové $("#example1do").show(); $("#example1do").hide(); //celé to jde zapsat díky tomuto chování ještě jednodušeji $("#example1do").

JavaScript Closures - překvapení Java programátora

function example1() { //this shows no allert var myFnct = function() { alert("Hello World!") }; //this shows function as string - no execution will happen alert(myFnct.toString()); //there we'll execute it myFnct(); } function example2() { //we'll fetch a function and execute it on next line var myFnct = getSomeFunction(); myFnct("Father Fourah"); //we can do it even in shorter way - looks quite ridiculous - doesn't it? getSomeFunction()("Reader"); } function getSomeFunction() { return function(name) {alert("Hello " + name)}; } function example3() { var names = ["Jan", "Petr", "Milan"]; var myFnct = function(name) {alert(name)}; forEachExecute(names, myFnct); //or the same in more compressed way forEachExecute([1,2,3], function(nmb) {alert(nmb)}); } function forEachExecute(data, callback) { for(i = 0; i < data.

Exkurz do templatovacích enginů v Javě

<HTML> <HEAD> <TITLE>Hello World!</TITLE> </HEAD> <BODY> <CENTER> <B>We've reached $downloadCount of Firefox 3!</B> <BR/> We are proud to announce that we've achieved new Guiness record. <BR/> Top countries in download were: <TABLE> #foreach($country in $countryList) <TR> <TD>$velocityCount.</TD> <TD>$country</TD> </TR> #end </TABLE> <BR/> <I>Stay loyal!</I> </CENTER> </BODY> </HTML> /* first, get and initialize an engine */ VelocityEngine ve = new VelocityEngine(); ve.init(); /* next, get the Template */ Template t = ve.

Acegi Captcha způsob integrace a možnosti použití

/** * Filter for web integration of the {@link org.acegisecurity.captcha.CaptchaServiceProxy}. * It basically intercept calls containing the specific validation parameter, use the {@link org.acegisecurity.captcha.CaptchaServiceProxy} to * validate the request, and update the {@link org.acegisecurity.captcha.CaptchaSecurityContext} if the request passed the validation. * This Filter should be placed after the ContextIntegration filter and before the {@link * org.acegisecurity.captcha.CaptchaChannelProcessorTemplate} filter in the filter stack in order to update the {@link org.acegisecurity.captcha.CaptchaSecurityContext} * before the humanity verification routine occurs.

Running AJAX with jQuery in Stripes Framework

<filter> <display-name>Stripes Filter</display-name> <filter-name>StripesFilter</filter-name> <filter-class>net.sourceforge.stripes.controller.StripesFilter</filter-class> <init-param><param-name>ActionResolver.UrlFilters</param-name><param-value>WEB-INF/classes</param-value> </init-param> <init-param><param-name>LocalePicker.Locales</param-name><param-value>cs_CZ:windows-1250</param-value> </init-param> ... other configuration ... </filter> <filter> <display-name>Stripes Filter Ajax</display-name> <filter-name>StripesFilterAjax</filter-name> <filter-class>net.sourceforge.stripes.controller.StripesFilter</filter-class> <init-param><param-name>ActionResolver.UrlFilters</param-name><param-value>WEB-INF/classes</param-value> </init-param> <init-param><param-name>LocalePicker.Locales</param-name><param-value>cs_CZ:UTF-8</param-value> </init-param> ... other configuration ... </filter> <filter-mapping> <filter-name>StripesFilter</filter-name> <url-pattern>*.x</url-pattern> <dispatcher>REQUEST</dispatcher> </filter-mapping> <filter-mapping> <filter-name>StripesFilterAjax</filter-name> <url-pattern>*.ajax</url-pattern> <dispatcher>REQUEST</dispatcher> </filter-mapping> @UrlBinding("/consultation/newQuery.x") @StrictBinding public class NewQueryAction extends AbstractAction implements ValidationErrorHandler { @SpringBean protected QueryManager queryManager; @ValidateNestedProperties({ @Validate(field = "idIssue", on = "createQuery", required = true), @Validate(field = "author", on = "createQuery", required = false), @Validate(field = "idUser", on = "createQuery", required = false), @Validate(field = "title", on = "createQuery", required = true), @Validate(field = "query", on = "createQuery", required = true) }) protected Query query = new Query(); @AllowBinding protected Integer idIssue; @AllowBinding .

Download binárního souboru přes HTTPS a Internet Explorer

Pragma: no-cache Cache-Control: no-cache public class XlsExportServlet extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { response.setContentType("application/vnd.ms-excel"); response.setHeader("Content-Disposition", "attachment; filename=callMeExport.xls" ); //writeBinaryOutput(response.getOutputStream()); } } catch(Exception e) { if(log.isFatalEnabled()) { log.fatal("Error during processing request!", e); } response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } finally { response.flushBuffer(); response.getOutputStream().close(); } } } <Host name="www.nesmysl.cz" appBase="/www/test-secure/" unpackWARs="false"> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="www_access_log." suffix=".txt" pattern="common"/> <Context path="/srv/www" docBase="_deploy/webapp"> <Valve className="org.apache.catalina.authenticator.BasicAuthenticator" disableProxyCaching="false" /> <Realm className="org.apache.catalina.realm.MemoryRealm" pathname="/www/test-secure/etc/tomcat-users.