#
Navigation Practice Agenda:
1, forward & redirect; Get & Post:
How to choose between them? How to apply by JSF/JSP? what's default in JSF?
How to resolve issue about resources not found caused by forward navigation?
Does the request scope objects still available after redirect?
2, done back
How to done back in client side? browser history back; js history back manager
How to done back at server side? JSF
3, How to navigation only inside of page?
scroll bar navigation: anchor? scroll bar ?
focus on different DOM elements?
4, How to do not navigate?
refresh page, ajax refresh
Could you make your page support Refresh with right navigate behavior?
5, How to navigate among tabs and windows?
form submit target:_blank,_self,_parent,_top,frameName
6, JSF navigation management
referrence: http://java.sun.com/dtd/web-facesconfig_1_1.dtd
How does JSF choose navigation rule case when match mutiple cases?
7, How to pass parameters during navigation?
page, request, session, application
I was told something about js module
framework two years ago. But without a deep dive into it, so that I have to ride
out large bundles of js files in a mess on our projects for a long time. After kejun’s
YUI presentation on D2 2009, I thought that it’s time to change.
Why use js module?
1, better js organization, readable + flexible
+ dependencies ordering
2, better performance, asynchronize loading
JIT
How we did it before?
1, inline script in jsp : hard to unittest,
make the file looks tedious and ugly
2, separated js script file: bad
organization, too many ugly import tag <script>
What is the existed solution?
1, YUI module: http://developer.yahoo.com/yui/yuiloader/
2, Jawr: a tunable packaging solution for
Javascript and CSS written in java
3, jQuery getSscript: http://ejohn.org/blog/degrading-script-tags/
4, jspkg: http://jspkg.sourceforge.net/docs/index.html
5, module.js http://ajaxian.com/archives/modulesjs-a-new-stand-alone-javascript-module-loader
to do ...
Pros and Cons:
Pros:
1, reduce configuration xml files
2, readable by self-documenting
Cons:
1, it adds deployment context to classes, which should be
generic enough.
2, interfere with design principles such as IOC and
dependency injection, because you need to introduce imports
Usage (annotation works only when handled by related
annotation processor):
- Information
for the compiler — Annotations can be used by the compiler to detect
errors or suppress warnings.
- Compiler-time
and deployment-time processing — Software tools can process annotation
information to generate code, XML files, and so forth.
- Runtime
processing — Some annotations are available to be examined at runtime.
1 import java.io.IOException;
2 import java.io.PrintStream;
3 import java.lang.reflect.AnnotatedElement;
4 import java.lang.annotation.Annotation;
5
6 import java.util.Date;
7 import java.lang.annotation.Documented;
8 import java.lang.annotation.Inherited;
9 import java.lang.annotation.Retention;
10 import java.lang.annotation.RetentionPolicy;
11
12 public class ReflectionTester {
13
14 public ReflectionTester() {
15 }
16
17 public void testAnnotationPresent(PrintStream out) throws IOException {
18 Class c = Super.class;
19 boolean inProgress = c.isAnnotationPresent(InProgress.class);
20 if (inProgress) {
21 out.println("Super is In Progress");
22 } else {
23 out.println("Super is not In Progress");
24 }
25 }
26
27 public void testInheritedAnnotation(PrintStream out) throws IOException {
28 Class c = Sub.class;
29 boolean inProgress = c.isAnnotationPresent(InProgress.class);
30 if (inProgress) {
31 out.println("Sub is In Progress");
32 } else {
33 out.println("Sub is not In Progress");
34 }
35 }
36
37 public void testGetAnnotation(PrintStream out)
38 throws IOException, NoSuchMethodException {
39
40 Class c = AnnotationTester.class;
41 AnnotatedElement element = c.getMethod("calculateInterest",
42 float.class, float.class);
43
44 GroupTODO groupTodo = element.getAnnotation(GroupTODO.class);
45 String assignedTo = groupTodo.assignedTo();
46
47 out.println("TODO Item on Annotation Tester is assigned to: '" +
48 assignedTo + "'");
49 }
50
51 public void printAnnotations(AnnotatedElement e, PrintStream out)
52 throws IOException {
53
54 out.printf("Printing annotations for '%s'%n%n", e.toString());
55
56 Annotation[] annotations = e.getAnnotations();
57 for (Annotation a : annotations) {
58 out.printf(" * Annotation '%s' found%n",
59 a.annotationType().getName());
60 }
61 }
62
63 public static void main(String[] args) {
64 try {
65 ReflectionTester tester = new ReflectionTester();
66
67 tester.testAnnotationPresent(System.out);
68 tester.testInheritedAnnotation(System.out);
69
70 tester.testGetAnnotation(System.out);
71
72 Class c = AnnotationTester.class;
73 AnnotatedElement element = c.getMethod("calculateInterest",
74 float.class, float.class);
75 tester.printAnnotations(element, System.out);
76 } catch (Exception e) {
77 e.printStackTrace();
78 }
79 }
80 }
81
82 class Sub extends Super {
83
84 public void print(PrintStream out) throws IOException {
85 out.println("Sub printing");
86 }
87 }
88
89 @InProgress class Super {
90
91 public void print(PrintStream out) throws IOException {
92 out.println("Super printing");
93 }
94 }
95
96 @Documented
97 @Retention(RetentionPolicy.RUNTIME)
98 @interface GroupTODO {
99
100 public enum Severity { CRITICAL, IMPORTANT, TRIVIAL, DOCUMENTATION };
101
102 Severity severity() default Severity.IMPORTANT;
103 String item();
104 String assignedTo();
105 String dateAssigned();
106 }
107
108 /**
109 * Marker annotation to indicate that a method or class
110 * is still in progress.
111 */
112 @Documented
113 @Inherited
114 @Retention(RetentionPolicy.RUNTIME)
115 @interface InProgress { }
116
117 class AnnotationTester {
118
119 @InProgress
120 @GroupTODO(
121 severity=GroupTODO.Severity.CRITICAL,
122 item="Figure out the amount of interest per month",
123 assignedTo="Brett McLaughlin",
124 dateAssigned="04-26-2004"
125 )
126 public void calculateInterest(float amount, float rate) {
127 // Need to finish this method later
128 }
129 }
130
Introduction:
JSF: MVC framework as Struts
DWR: java Ajax framework
Json: a data format definition like XML, YAML. We could use DWR or jsonlib to marshal/unmarshal between json and objects.
How to use?
1, when should we use json or not?
do JSF as much as possible;
only when dynamic collection size on page, do Json
2, when should we use DWR json convertor configuration or customize json convertor by java?
page scope update, do Ajax by DWR as much as possible;
otherwise, do JSF action by json convertor (consolidate convertor by jsonlib or dwr?)
DWR convertor VS Jsonlib convertor:
DWR:
convertor setting by xml, annotation or java;
Jsonlib:
convertor setting by java (only check @Transient), but more professional overall;
Requirement:
1, simple convertion, no VO or DTO:
PO to json: 1, cycle detect; 2,include/exclude;
Json to PO: 1, the same js handle; 2, ajax by dwr; jsf by hidden string
2, one PO map into two JSON model for different domains (e.g. bind different convertor by spring to different domain serviceImpl)
Not to do list:
1, do not use duplicated convertors definition in java/xml/annotation
2, do not DTO or VO when convert between json and objects
3, do not parse or transfer useless fields, e.g. use include / exclude configuration instead during convert objects into json; use "delete" during convert json into object
4, do not use json if could use JSF
1 var alltrue = [true, true, true];// false
2 var allfalse = [false, false, false];// false
3 var chaos = [true, false, true, false];// true
4 //1,logic operation;2,shorten-cycle;
5 function LogicXOR(){
6 var args = arguments;
7 if (args.length == 1) {
8 if (args[0].length) {
9 args = args[0];
10 }
11 else {
12 return args[0];
13 }
14 }
15
16 var count = args.length;
17 while (--count > 0) {
18 if (!args[count] !== !args[count - 1])
19 return true;
20 }
21 return false;
22 }
23
24 alert(LogicXOR(alltrue))
25 alert(LogicXOR(allfalse))
26 alert(LogicXOR(chaos))
27 alert(LogicXOR(true, true, true))
28 alert(LogicXOR(false, false, false))
29 alert(LogicXOR(true, false, true, false))
Collection>
boolean contains(Object o):return true only if has (o==null ? e==null :o.equals(e))
boolean removeAll(Collection<?> c); remove elements in c
boolean retainAll(Collection<?> c); remove elements not in c
Queue VS List VS Set
List>
ListIterator<E> listIterator();| Iterator<E> iterator();
next() & previous()|only has next()
add() & remove()|only has remove()
* you can not use list.add() during both two iteration, otherwise,ConcurrentModificationException
RandomAccess>
Marker interface used by List implementations to indicate that they support fast (generally constant time) random access. e.g.
for (int i=0, n=list.size(); i < n; i++)
list.get(i);
runs faster than this loop:
for (Iterator i=list.iterator(); i.hasNext(); )
i.next();
HashMap, HashSet, HashTable>
HashMap(int initialCapacity, float loadFactor) resize()
HashSet(int initialCapacity, float loadFactor) {map = new HashMap<E,Object>(initialCapacity, loadFactor);}
Hashtable(int initialCapacity, float loadFactor) extends Dictionary<K,V> ; synchronized ; rehash();
hash = hash(key.hashCode());
*TreeMap Red-black mechanics
String>
String|StringBuffer|StringBuilder
immutable|mutable|mutable <-- depends on the char[] value is final or not;
thread-safe|thread-safe|single thread
1, compile phase:
constance will be directly written. OuerClass.constance not refer to it during runtime.
+ =after compiled=> StringBuilder
2, Performance:
usually, StringBuilder>StringBuffer>+; but need to make sure the real generated class file.
String.intern() is better if too many duplicated string instance.
3, String <--> bytes
decode: String(byte bytes[], int offset, int length, Charset charset)
encode: String.getBytes(Charset charset)
4, StringTokenizer | String.split
better performance | RegEx
当IE中发生js对象与dom对象直接的循环引用,并且之后没有引用指向他们,
如果是IE 6, 内存泄漏,直到关闭IE进程为止
如果是IE 7,内存泄漏, 直到离开当前页面为止
如果是IE 8, GC回收器回收他们的内存,无论当前是不是compatibility模式。
为什么有内存泄漏?
之前的IE js引擎里的GC回收器只能处理js对象,不能处理DOM对象。
refer to: http://msdn.microsoft.com/en-us/library/dd361842%28VS.85%29.aspx#compat
1、 说话的时机:成事不说、遂事不谏、既往不咎
2、 不同事情,不同说法:好事情,用播新闻的方式;坏事情,先说结果
3、 试探性的说话:放话出去
4、 见人说人话,见鬼说鬼话,不人不鬼说胡话
摘选自:http://blog.csdn.net/zhaowei001/archive/2008/04/10/2279172.aspx