Wednesday, November 19, 2014

Jsf onclick

<script type="text/javascript">

                

                $( document ).ready(function() {

                    console.log("worksssssssssssssssssssssssssssssssssssssssssssss");

                 $("#testId\\:sendMailInitiateBtn").click();

                });

            </script>

            <h:form id="testId">

                <h:commandButton 

                    id="sendMailInitiateBtn" 

                    style="display: none"

                    action="#{createMailController.mailInit}"                    

                    />

            </h:form>

Monday, November 17, 2014

Jsf call

<h:form>

                                        <c:set var="grpId" value="#{param['grpId']}"  scope="view"/> 

                                        <h:commandButton value="Leave Group!" action="#{groupAction.leaveFromRingIDCircle(grpId)}" >

                                            <f:param value="#{param['grpId']}" name="grpId"/>

                                        </h:commandButton></h:form>







FacesContext fc = FacesContext.getCurrentInstance();

            Map<String, String> params

                    = fc.getExternalContext().getRequestParameterMap();

            long v_grpId = Long.valueOf(params.get("grpId"));

Monday, November 10, 2014

Jquery selector

Div for all div

Div > p all p under div

Div > p: first-child

Div strong decendent of div element

Mycls a all a under mycls div

P: even all even p element

# myid for specific id

. Clsname for all class with same cls name

Strong.myclsname all strong element that has myclsname as cls name

Sunday, November 9, 2014

Jqery additional data onclick

Add data-varName

Get inside onclick

$(this).data("varName") ;

Tuesday, October 28, 2014

MemorySafeUndeclaredThrowableStrategy

This happens when u have dependency mismatch. If u are using spring web mvc version 4 make sure spring aop is not v 3 or anything else for that matter.

You can easily see which dependency you are actually using if you have maven puffin for eclipse. There is a tab called dependency hierarchy. There in the resolved dependency you can see the actual dependency you are using and fix it accordingly.

Run tomcat as service in windows

1. Run cmd as Administrator
2. Go to the tomcat bin directory
3. Type service install servicename
4. sc start servicename


Friday, October 24, 2014

Saturday, October 18, 2014

Basic Spring application configaration

Config files


web.xml


<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
       /WEB-INF/spring-servlet.xml
   </param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>


spring-servlet.xml



<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:security="http://www.springframework.org/schema/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:lang="http://www.springframework.org/schema/lang"
xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util" xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/jee
        http://www.springframework.org/schema/jee/spring-jee.xsd
        http://www.springframework.org/schema/lang
        http://www.springframework.org/schema/lang/spring-lang.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/util
        http://www.springframework.org/schema/util/spring-util.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
        http://www.springframework.org/schema/security
        http://www.springframework.org/schema/security/spring-security-3.1.xsd">

    <mvc:annotation-driven />
<mvc:default-servlet-handler />
<context:annotation-config />
<context:component-scan base-package="com.lynas.test" />
<tx:annotation-driven />
</beans>













Tuesday, February 18, 2014

Show list in groups using JS

<div id="data"></div>

var ar = new Array();
ar.push({F: "A", L: "C"});
ar.push({F: "B", L: "D"});
ar.push({F: "C", L: "E"});
ar.push({F: "C", L: "X"});
ar.push({F: "A", L: "Z"});

var c = $(ar).sort(function(a,b) {
   var f1 = a.F;
    var f2 = b.F;
    return f1 > f2;
});
var oldHeader = "";
$.each(c,function() {
    if (oldHeader != this.F) {
        $("#data").append($("<p>").css({"font-weight": "bold", "margin-top" : "30px"})
                        .append("(Header " + this.F + ")"));
        oldHeader = this.F;
    }
    $("#data").append($("<p>").append(this.F + " " + this.L));
})



http://jsfiddle.net/Q7cpm/2/

Wednesday, February 12, 2014

Pc setup ubuntu

apt-get update
apt-get install openjdk-7-jdk
apt-get install git

chmod +x xampp.....
./xamppp.run
run>> /opt/lampp/lampp start

apt-get install nginx
pico /etc/nginx/site-enabled/default

change >> port 8081 in the server block

Tuesday, February 11, 2014

Spring Image Upload

+public String pictureUpload(MultipartFile mpfGet,String userName,int x1,int y1,int w,int h) {
 +
 +// getting image and seeing output
 +MultipartFile mpf = mpfGet;
 +String extension = ".png";
 +// inserting image to the server
 +Rectangle rect = new Rectangle();
 +rect.height = h;
 +rect.width = w;
 +try {
 +BufferedImage src = ImageIO.read(mpf.getInputStream());
 +BufferedImage dest = src.getSubimage(x1, y1, rect.width, rect.height);
 +String rootPath = "/usr/local/var/www/";
 +File outputPath = new File(rootPath + "abc"+ extension);
 +ImageIO.write(dest, "png", outputPath);
 +} catch (IOException e) {
 +
 +}
 +return pictureName;
 +}



+ Dependencys
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.2.2</version>
</dependency>

<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>

</dependency>

Spring Send mail

//Dependencys

<dependency>

<groupId>javax.mail</groupId>

   <artifactId>mail</artifactId>

 <version>1.4</version>
</dependency>

// controller method 

@RequestMapping(value = "sendEmail/mailAddress/{mailAddress}", method = RequestMethod.POST )
 + public String sendEmail(Model model, @PathVariable String mailAddress) {
 +
 + SimpleMailMessage email = new SimpleMailMessage();
 + email.setTo("mail@gmail.com");
 + email.setSubject("Hello");
 + email.setText("Mail Testing....");
 +
 + // sends the e-mail
 + mailSender.send(email);
 + System.out.println("Mail sent...");
 + System.out.println("Mail sent..."+mailAddress);
 + return "regsuccess";
 + }




there is a servlet setting


<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
        <property name="host" value="smtp.gmail.com"/>
        <property name="port" value="25"/>
        <property name="username" value="mail@gmail.com"/>
        <property name="password" value="your password"/>
        <property name="javaMailProperties">
            <props>
                <!-- Use SMTP transport protocol -->
                <prop key="mail.transport.protocol">smtp</prop>
                <!-- Use SMTP-AUTH to authenticate to SMTP server -->
                <prop key="mail.smtp.auth">true</prop>
                <!-- Use TLS to encrypt communication with SMTP server -->
                <prop key="mail.smtp.starttls.enable">true</prop>
                <prop key="mail.debug">true</prop>
            </props>
        </property>
    </bean>

Spring how to make a class a Controller and different method type in controller

package com.lynas.controller;
@Controller
@RequestMapping("/product")
public class ProductController {
@Autowired
private EUserService userDao; //for Service
//This is a normal method not a controller method
private String getCurrentUser(){
return "MyString";
}
//controller method for dealing with form post method
@RequestMapping(value="/registeruser", method = RequestMethod.POST)
public ModelAndView registerUser(HttpServletRequest request,@RequestParam String username,@RequestParam String password,@RequestParam String email){
 
return new ModelAndView(forwardPage); // this is for forwarding to a new model view
}
//controller method that just show the view
@RequestMapping(value="/home")
public ModelAndView home(){
return "home"; //home is the jsp page for view
}

@RequestMapping(value = "/addnewproduct", method = RequestMethod.POST)
@PreAuthorize("hasAnyRole('ROLE_USER')") // this is for defining which type of user can access this method
public String addNewProduct() {
 
return "myproduct";
}
@RequestMapping(value = "/getsubcategory")
@ResponseBody // this is a controller method for dealing with ajax call
public String approveOneUser(@RequestParam String category) {
return stringBuilder.toString();
}
@RequestMapping(value = "/addToWishlist/{itemId}") // this is for grabbing path variable
@PreAuthorize("hasAnyRole('ROLE_USER','ROLE_ADMIN')")
public String wishListAdd(@PathVariable int itemId) {
return "updated";
}
}

Google shortcut for I'm Feeling lucky

in the manage search add the following url


{google:baseURL}search?{google:RLZ}{google:acceptedSuggestion}{google:originalQueryForSuggestion}sourceid=chrome&ie={inputEncoding}&q=%s&btnI

Sunday, February 9, 2014

Hibernate Criteria

Criteria criteria = session.getCurrentSession().createCriteria(
Item.class);




criteria.addOrder(Order.desc("dateCreated"));

criteria.setMaxResults(1);

criteria.add(Restrictions.eq("email", email));

criteria.add(Restrictions.isNotNull("approvedBy"));

criteria.add(Restrictions.not(Restrictions.eq("empSal", 6700.0)));







return criteria.list();

return (Item) criteria.uniqueResult();




Hibernate by example

User user = new User();
user.setName("name"); //it does not take primary key e.g user.setId() wont consider for showing result

//

Example example = Example.create(user);


Criteria criteria = session.createCriteria(User.class).add(example)


//for ignoring
Example example = Example.create(user).excludeProperty("userName");

//for like property
user.setName("name %");
Example example = Example.create(user).enableLike()