Friday, 23 October 2015

Inject the value of an Static Variable

Assuming you have a class like this: Add these lines to your spring context file to inject the value of "staticTestValue"

Wednesday, 10 December 2014

Responsive Design: Include @media queries as mixins using LESS

I have to includ the @media queries as a seperate file and sections before.
That was very circumstantial and took a long time to find and redefine each elemnt to display properly on Mobile Devices.

Since LESS has included the support of mixins, it is very comfortable to define such queries.

All you need is:

  1. Define your preferred Breakpoints as Variables 
  2. Include the queries inside the main element 
Sample:


Step 1: Define your preferred Breakpoints as Variables
@extraSmall: ~"only screen and (max-width: 360px)";
@small: ~"only screen and (max-width: 640px)";
@medium: ~"only screen and (max-width: 768px)";
@large: ~"only screen and (max-width: 960px)";
view raw gistfile1.less hosted with ❤ by GitHub


Step 2: Include the queries inside the main element
.menuWrapper {
position: relative;
width: 100%;
& .menu {
display: table;
margin: auto;
width: 70%;
@media @medium {
width: 90%;
}
@media @extraSmall {
width: 95%;
}
}
}
view raw gistfile1.less hosted with ❤ by GitHub


Wednesday, 8 January 2014

nice HTML HR (horizontal rule) with CSS

here is a sample of creating a horizontal rule with only CSS commands without using an Image. The point here is to define a DIV element with same settings as HR and rotate and put it over the HR.


your page with look like here:
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
and here is the code:
<style>
div.container {
width: 60%;
margin: 30px auto;
font-family: Verdana, Geneva, Tahoma, sans-serif;
font-size: 12px;
background-color: #888;
padding: 10px;
}
hr.style1 {
border: none;
border-top: 2px dashed #fff;
height: 2px;
width: 80%;
}
hr.style2 {
border: none;
border-top: 2px dashed #fff;
height: 2px;
margin: 30px auto;
width: 80%;
}
hr.style2:after {
content: "\00a0";
left: 50%;
position: absolute;
display: block;
width: 30px;
height: 30px;
background-color: #888;
margin-top: -16px;
pointer-events: none;
-webkit-transform: rotate(135deg);
-moz-transform: rotate(135deg);
-ms-transform: rotate(135deg);
-o-transform: rotate(135deg);
transform: rotate(135deg);
z-index: 1;
border: none;
border-top: 2px dashed #fff;
border-right: 2px dashed #fff;
}
</style>
<div class="container">
<span>
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
</span>
<hr class="style1">
<span>
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
</span>
<hr class="style2">
<span>
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
</span>
</div>
view raw gistfile1.html hosted with ❤ by GitHub

Wednesday, 26 June 2013

Schedule a Method to run later

If you do not want to run a method in the normal application process flow, you can use ScheduledExecutorService to run it later. This sample code executes the "myFunction" 5 Seconds later.

final ScheduledExecutorService exec = Executors.newScheduledThreadPool(1);
exec.schedule(new Runnable() {
@Override
public void run() {
System.out.println("=================> Running");
myFunction();
}
}, 5, TimeUnit.SECONDS);
view raw gistfile1.java hosted with ❤ by GitHub

Tuesday, 4 December 2012

JAXB : IllegalAnnotationExceptions - Class has two properties of the same name

just developing a test jaxb application and wanted to let getters and setters be created automatically with Lombok.
As I was attempting to assign annotations of private field members, got this exception:


Exception in thread "main" com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
Class has two properties of the same name "name"
this problem is related to the following location:
at public java.lang.String de.domain.jaxbtest.model.Book.getName()
at de.domain.jaxbtest.model.Book
at private java.util.List de.domain.jaxbtest.model.Bookstore.bookList
at de.domain.jaxbtest.model.Bookstore

the solution was easy as just adding @XmlAccessorType(XmlAccessType.FIELD) to defined class:

@Data
@XmlRootElement(name = "book")
@XmlAccessorType(XmlAccessType.FIELD)
public class Book {
@XmlElement(name = "title")
private String name;
private String author;
private String publisher;
private String isbn;
}
view raw Book.java hosted with ❤ by GitHub

Tuesday, 27 November 2012

Wait for an AJAX call to complete with Selenium 2 WebDriver


private ExpectedCondition WaitForAjax(final long timeout) {
return new ExpectedCondition() {
public Boolean apply(WebDriver driver) {
final long startTime = System.currentTimeMillis();
final JavascriptExecutor javascriptExecutor = (JavascriptExecutor) driver;
while ((startTime + timeout) &gt;= System.currentTimeMillis()) {
final Boolean scriptResult = (Boolean) javascriptExecutor.executeScript("return jQuery.active == 0");
if (scriptResult)
return true;
delay(100);
}
return false;
}
};
}
private void delay(final long amount) {
try {
Thread.sleep(amount);
}
catch (InterruptedException e) {
e.printStackTrace();
}
}
view raw gistfile1.java hosted with ❤ by GitHub

here is a sample to use this method:

public class SeleniumTest {
private final static String BASE_URL = "http://localhost:8080";
private final static WebDriver driver = new FirefoxDriver();
@Before
public void startUp() {
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
driver.manage().window().setPosition(new Point(0, 0));
driver.manage().window().setSize(new Dimension(800, 600));
}
@Test
public void testMyPage() {
final Wait wait = new WebDriverWait(driver, 60);
driver.get(BASE_URL + "/myweb/");
boolean isListPopulated = wait.until(WaitForAjax(60000));
Assert.assertTrue(isListPopulated);
}
@After
public void tearDown() {
// Close the browser
driver.quit();
}
}

Friday, 23 November 2012

JSF - Show content only if Messages is empty

<h:panelgroup rendered="#{facesContext.validationFailed or empty facesContext.messageList}">



. . .

</h:panelgroup>