Sergeonclear

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Wednesday, August 29, 2007

Spring portlet mvc and spring servlet mvc validation

Posted on 11:10 PM by Unknown
Spring mvc is easy to get along with, unless we get the basic flow right. We end up wasting lot of time figuring out the flow of control/binding of errors for validation/etc.

Spring portlet mvc validation
  1. extend AbstractCommandController or SimpleFormController
  2. In case of AbstractCommandController implement the method handleRenderView(req,res,command,errors)
  3. Important thing to note is that you should return the ModelAndView as new ModelAndView(jspPage, errors..getModel());

  • Note the method handleRenderView() is called even if validation fails. Hence we have to return back the command object having errors using errors.getModel().

Spring servlet mvc validation
  • Implemented a simple form controller.
class ManageProfileController extend SimpleFormController
{
public ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception
{
Map modelMap = new HashMap();
return new ModelAndView(forwardJSP, modelMap);
}
}

  • The configuration in *-servlet.xml is as below (assume dispatcher servlet is configured already)

<bean id="manageProfileController" class="com.TEST.web2.portlet.controller.common.ManageProfileController">        
<property name="registrationService" ref="registrationService"/>
<property name="formView"><value>common/manageprofile</value></property>
<property name="commandClass"><value>com.TEST.web2.model.DpsUser</value></property>
<property name="validator" ><ref bean="userValidator"/></property>
<property name="successView"><value>common/manageprofile</value></property>

</bean>

  • On validation error, in servlet mvc, the onSubmit() is not called and the command object is available with errors.

  • To extract the errors in JSP use:


<spring:bind path="command.confirmPassword">

<c:out value="${status.expression}"/> <input name=confirmPassword type="password" style="width:200px; " onKeyUp="document.getElementById('cpw').value=this.value" value="<c:out value="${status.value}"/>">
<font > <c:out value="${status.errorMessage}"/> </font>

</spring:bind>
Read More
Posted in Spring portlet mvc and spring servlet mvc validation | No comments

Wednesday, August 22, 2007

Castor --The XML Marshaller

Posted on 8:48 PM by Unknown
Forget writing XML parser...Castor will take care of parsing. It generates the java
classes to work with XML.

To use castor,
-- put the below lib's in classpath
-- ./lib/castor-0.9.9.jar
./lib/castor-0.9.9-srcgen-ant-task.jar
./lib/castor-0.9.9-xml.jar
xercesImpl.jar;
commons-logging.jar

-- Run java org.exolab.castor.builder.SourceGenerator -i test.xsd -dest dtnFolder
--optionally specify the package name if required.

-- To convert from DTD to XSD use
java org.exolab.castor.xml.dtd.Converter dtdFileName newXSDFileName

To use the generated code:

  • To run the unmarshal the castor lib should be in class path and follow the sample code herewith.

// Create a Reader to the file to unmarshal from
reader = new FileReader("test.xml");

// Marshal the person object
Person person = (Person)Unmarshaller.unmarshal(Person.class, reader);

  • To marshal an instance of the person class you simply call the Marshaller as follows:
// Create a new Person
Person person = new Person("Ryan 'Mad Dog' Madden");
person.setDateOfBirth(new Date(1955, 8, 15));

// Create a File to marshal to
writer = new FileWriter("test.xml");

// Marshal the person object
Marshaller.marshal(person, writer);


Follow the document of castor for details.





Read More
Posted in Castor castor convert dtd to xsd | No comments

Wednesday, August 1, 2007

LINUX usefuls

Posted on 1:16 AM by Unknown

html'&gt;linux basic commands:
ls
ls -a -- lists all files (hidden as well .)
ls -l -- list with permission and details

ln -s A B -- create soft link btw two file/folders

ps -- see current process
ps -e -- see background process as well
ps -H -- list process hierarchy
ps -f -- ?
pstree
top - see all proc's at one shot
pmap [PID] : list all the resource held by this proc.
cat /proc/[PID]/maps :

kill -3 [PID] -to get the status of threads
$ killall httpd -kill all the procs with name httpd

grep -- useful for search. Very powerful if we combine with other commands
eg: ps -ef | grep liferay == will return all the liferay process

fg -- bring the process to foreground
bg -- send the process to background
CTRL Z -- send the process to background..Can bring it to foreground using fg.
CTRL C -- close a program.

tail myfile.txt -n 100 -- list the last 100 lines in
the file

mail -s "picture of me surfing" sylvia@home.com &lt; surfing.jpeg --- To mail a file
tail -f catalina.out --display the contents in real time
head -15 myfile.txt - Would display the first
fifteen lines of myfile.txt.

diff -r -N folder1/ folder2/ ---find difference b/n folders.. -N do display diff content.


cat test.txt --display content of file test.txt

cat t.txt t2.txt &gt; t3.txt -- merge t.txt+t2.txt= t3.txt

difference b/n folder
du -hs liferay1/webapps/* liferay2/webapps/*


touch file.txt -- quickly create a empty file

VI editor commands
i -- insert mode
r -- replace mode
/ -- search
:%s/fred/joe/igc : general substitute command(replace)
w -- write
wq --write and quit
q-- quit
:#20 - moving to a line 20
Ctrl u --page up
Ctrl d -- page down
:set number -- to set the number
~ Toggle case of the character under the cursor, or all visually-selected characters.
q: You can bring up the command line history while in Normal mode.
:42G -- ways to go to a particular line (line 42 for example)
Multiple Files Management

vim test xyz


:bn -- next file

:bp -- next file

:wn -- write file and move to next (SUPER)

Screen
Ref: http://www.kuro5hin.org/story/2004/3/9/16838/14935

Screen is best described as a terminal multiplexer.
Using it, you can run any number of console-based
applications--interactive command shells,logging, curses-based
applications,
text editors, etc.--within a single terminal.Also can reattach again to
the screen even after logout.Excellent isn't it. Should have had a
separate blog :0). Any way the quick reference below:



$screen --Start screen just by typing screen at your favorite command shell prompt

Ctrl a c --create another screen

ctrl a
ctrl A --switch screen

ctrl a n -- switch next screen

ctrl a p -- switch prev screen

ctrl a A -- Give a name to the current screen.

ctrl a " -- to get a full-screen list of windows

ctrl a K --You can also kill misbehaving programs

$screen -r --will reattach the screen to the current session which.

Networking commands:

ping

netstat -- active connections
netstat -r --shows routing table


ifconfig (like ipconfig in windows)
ifconfig eht0 down -- shutdown lan card (to renew ip u can do this)
ifconfig eht0 up --startup lan card

iptraf
nmap -- port sniff
dig

NATing
/etc/hosts file
It is used to map simple human readable names with ip address.
Eg:
127.0.0.1 localhost.localdomain localhost
127.0.0.1 access.idp1.com

Installation
rpm -i foo-v123.rpm ---install a package
rpm -i http://oss.oracle.com/kernel-2.4.20-18.10.1.i686.rpm
rpm -e foo
rpm -qi foo -- To query a RPM package and display info
more details refer http://www.idevelopment.info/data/Unix/Linux/LINUX_RPMCommands.shtml

Autoexec.bat in linux
vi /root/.bashrc # the user is root here.
---Do whatever needs to be done on login in the .bashrc
To load the properties without relogging in use : source /root/.bashrc

Secured remote copy:
scp &lt;target1&gt; &lt;target2&gt;
eg: scp test.zip sandeepm@xHost:/export/home/sandeep -- copies the test.zip to the target2 from target 1.
scp sandeepm@xHost:/export/home/sandeep/test22.zip . -- copies the test22.zip from target2 to target1 .


Use grep recursively

You can search recursively i.e. read all files under each directory for a string “192.168.1.5″

cd /etc

$ grep -R "192.168.1.5" *

Use grep to search words only


When you search for boo, grep will match fooboo, boo123, etc. You
can force grep to select only those lines containing matches that form
whole words i.e. match only boo word:

$ grep -w "boo" /path/to/file


Grep invert match


You can use -v option to print inverts the match; that is, it
matches only those lines that do not contain the given word. For
example print all line that do not contain the word bar:

$ grep -v bar /path/to/file

Count line when words has been matched


grep can report the number of times that the pattern has been matched for each file using -c (count) option:

$ grep -c 'word' /path/to/file

To get the DB conn list
$ netstat|grep -c app610

Shell script
The below will run a command for configurable no of times.
chmod +x test
usage : ./test [NO_TIMES] [COMMAND]

for (( i = 0 ; i &lt; $1; i++ ))
do
echo "Executing $2";
$2;
sleep 1;
done

More scripts here http://www.usd.edu/~sweidner/lsst/



One of the best methods to capture a Unix terminal session is to use the `script` command.



In this example we start a script session, run a couple of commands,
and then use the `exit` command to stop capturing the terminal session:



$ script
Script started, output file is typescript
$ pwd
/home/will
$ ps
PID TT STAT TIME COMMAND
11909 p0 Ss 0:00.05 -bash (bash)
25622 p0 S+ 0:00.01 script
25623 p1 Ss 0:00.01 /usr/local/bin/bash -i
25624 p1 R+ 0:00.00 ps
$ exit

Ref:
http://vim.wikia.com/wiki/Best_Vim_Tips




Read More
Posted in LINUX usefuls | No comments
Newer Posts Older Posts Home
Subscribe to: Comments (Atom)

Popular Posts

  • LinuxPerformance Tuning(apache,tomcat,linux) and related
    Web profiling -- HTTPAnalyzer -- -- YSlow --CSS,Javascript report , time/size measurement for individual component is good. -- F...
  • (no title)
    Hardware/Software stack:  iPhone 3Gs having iOS 5.1.1(latest as of today).  The Xcdode 4.2 failed to detect this iphone as it has support on...
  • Spring interceptor ordering
    SimpleUrlHandlerMapping uses a hashMap to hold the interceptors. Ordering can only be guaranteed by setting  order property.. By default it ...
  • SVN/ Subversion Tips and traps
    SVN could be tricky and waste a hell lot of time. Case Issue : Normally we run SVN server in linux. Our dev env will be in windows NT. Windo...
  • Liferay CMS/ web content management/ workflow/ staging
    Liferay out of the box has a web content management system. The web pages can mostly have these web content (articles) as web pages. The web...
  • Cobertura- junit coverage tool
    First, you need to add a task definition to the build.xml file. This top-level taskdef element specifies that the cobertura.jar file is i...
  • XSLT caching Transformers
     The usage of cached transformer objects is recommended here A sample implementation of CachingTransformerFactory is here The above code abs...
  • Rewrite rules in apache and IIS
    Well we can control how the server serves stuff to clients by defining rewrite rules. As servers are dumb, its important to explain well abo...
  • Real-Time Tracking and Tuning for Busy Tomcat Servers
    A very nice article which details on possible options for tomcat server monitoring to tweak its performance. http://www.devx.com/Java/Articl...
  • External Javascript from Java Servlets
    Copied from http://myappsecurity.blogspot.com/2007/01 Like to thank anurag for the content. /breaking-same-origin-barrier-of.html External ...

Categories

  • AJAX javascript
  • All about UK Visa HSMP VS H1
  • All about UK Visa HSMP VS H1 hsmp assistance
  • amazon
  • android apps ship control radio hindi
  • Apache 2.x setup Quick guide for Linux
  • apache commons configurator usage
  • apache commons usage
  • arsenals for developers
  • article
  • Batch script to load developer environment
  • Blind folded chess
  • Castor castor convert dtd to xsd
  • cloud comparision price
  • cloud comparison blog
  • cloud computing monthly price
  • cloud usage
  • Cobertura- junit coverage tool
  • Code generators
  • cron jobs expressions
  • cruisecontrol cruise control
  • debugging eclipse tips
  • developer tools
  • document library
  • easy mock jmock vs mocking java tdd
  • External Javascript from Java Servlets
  • fedora 9 lenovo 3000 n200 windows xp dual boot problem
  • Fire fox plugins and tweaks
  • Free PHP hosting
  • gods debris the religion war scott adams dilbert
  • google app engine
  • gwt javascript
  • hibernate second level cache
  • i18n locale localization internationalization spring liferay portlet locale
  • ibatis sybase mapping
  • image gallery
  • iphone apps bri8 apple
  • iphone shsh 3gs ipsw downgrade ifaith tinyumbrella ios5.1.1 to ios5.0
  • java
  • java JDBC
  • javascript junit testing
  • Javascript trouble shooting tool
  • Jboss overview
  • jmeter load testing custom java sampler javasamplerclient xml test
  • JNDI test JSP page
  • Joomla CMS
  • JProfiler setup jprofiler on linux
  • jquery IE AJAX issues
  • jquery spring AJAX
  • keyboard music java typing soothing notes auto suggest
  • liferay kids version
  • liferay web 2.0 java/j2ee
  • linux - the difference between hard and soft links
  • linux mysql
  • linux mysql setup quick start
  • Linux ssh autologin with putty
  • LINUX usefuls
  • linux)
  • LinuxPerformance Tuning(apache
  • log4j setup useful
  • lucene solr
  • mac m701 android skype not working crash
  • maven
  • maven cut reduce build time
  • microsoft ODBC oracle dll connection issues
  • Mobile Ad Services (adwhirl)
  • opsourcecloud
  • oracle connect by hierarchy
  • oracle table previlege
  • Oracle thin vs OCI(type II/thick) drivers
  • pdf 2 text
  • Pega PRPC
  • php
  • rackspacecloud
  • Rewrite rules in apache and IIS
  • scaffold
  • setting up a static ip on SKY broadband
  • setup quick start
  • Single Sign on - OpenSSO with Liferay
  • smart gwt
  • smtp email test mock server james
  • SMTP MAIL telnet windows
  • Software tools mind map freemind j2ee tools
  • Speed typing tips.
  • Spring + Hibernate Usefuls BaseDAOHibernate
  • Spring annotations with spring-mock not working 2.0 2.5.6
  • spring jndi datasource lookup
  • Spring portlet mvc and spring servlet mvc validation
  • Spyware trojan and virus removal tools
  • struts magic
  • SVN/ Subversion Tips and traps
  • tabbed ms dos console cygwin console
  • Texter - An auto text expander autotyper
  • Textpad tricks
  • The art of debugging
  • tomcat
  • Tomcat Exploded war - cut deployment time
  • Tomcat on linux tips
  • Tomcat on linux tips commands
  • TypeIt4Me
  • Typinator
  • Useful Eclipse Plugins
  • Useful Eclipse Plugins eclipse shortcuts keys
  • Useful tools
  • web content
  • xcode cocos2d iphone box2d
  • xpath xml xquery

Blog Archive

  • ►  2013 (19)
    • ►  August (17)
    • ►  July (1)
    • ►  January (1)
  • ►  2012 (7)
    • ►  August (1)
    • ►  June (4)
    • ►  April (2)
  • ►  2011 (20)
    • ►  November (1)
    • ►  October (1)
    • ►  August (1)
    • ►  July (3)
    • ►  June (1)
    • ►  April (2)
    • ►  March (4)
    • ►  February (1)
    • ►  January (6)
  • ►  2010 (27)
    • ►  December (3)
    • ►  July (2)
    • ►  May (3)
    • ►  April (2)
    • ►  March (5)
    • ►  February (10)
    • ►  January (2)
  • ►  2009 (32)
    • ►  December (5)
    • ►  November (2)
    • ►  September (3)
    • ►  August (6)
    • ►  June (4)
    • ►  May (4)
    • ►  April (3)
    • ►  March (2)
    • ►  February (3)
  • ►  2008 (28)
    • ►  December (1)
    • ►  October (2)
    • ►  September (2)
    • ►  August (4)
    • ►  July (7)
    • ►  June (1)
    • ►  April (2)
    • ►  March (2)
    • ►  February (2)
    • ►  January (5)
  • ▼  2007 (24)
    • ►  December (3)
    • ►  November (2)
    • ►  October (6)
    • ►  September (1)
    • ▼  August (3)
      • Spring portlet mvc and spring servlet mvc validation
      • Castor --The XML Marshaller
      • LINUX usefuls
    • ►  July (8)
    • ►  June (1)
Powered by Blogger.

About Me

Unknown
View my complete profile