Showing posts with label html. Show all posts
Showing posts with label html. Show all posts

Tuesday, December 10, 2013

Broken Image handling in jsp/html

Instead of showing a blank image, the best thing is to hide the img element itself from html page. 
This can be done using following script:-

<script>
// Hide img tag
$("img").error(function(){ $(this).hide(); });
</script>

In case you want to show a blank image jpg, this can be achieved using following script:

<script>
// Replace missing image $('img').error(function(){ $(this).attr('src', 'missing.jpg'); });
</script>






Wednesday, December 4, 2013

Chrome's Developer Tool - Handy when debugging your web application for CSS issues.

Wanted to share the benefits of using Chrome's developer tool. I know most of you would be using it for lot of debugging and profiling. We can also use Chrome to see all our incorrectly defined CSS properties on our website. Just go to the following icon on your Chrome and select Developers Tools under Tools.


Once you open your developers tool console, it appears at the bottom of your browser.

Now you can view all your invalid CSS on a web page when you open that webpage on the browser and view "Resource" section of the developers Tool. This will list all invalid CSS properties defined on the page and you can go to your code and remove / Change them.


Friday, November 22, 2013

Struts 2 -Repopulating a page with updated data after form submit

This post is an extension of my previous post( Creating sample Struts 2 Web Application ) that talks about creating Struts 2 web application. In this post I will talk about a much smaller and simpler trick to reload the submitted page with some updated content. I have seen on lots of forums, this question being asked that how do we show the same submitted page with new content.

 For that you need following entry as your struts.xml entry:-
<action name="loginaction" method="execute"  class="com.myorg.LoginAction">
<result name="input" >/sampleapp/Login.jsp</result>
<result name="success">/sampleapp/Login.jsp</result>
</action>


Now the entry in your Login.jsp page is, 


    <body>
              <s:form action="loginaction" method="post" > 
              <label for="name"><p>Enter your Name</p></label>
              <input type="text" size="50" name="id"/>
             <s:submit value="Submit" />
            </s:form>
      <s:if test="%{id != null}">
         <br/><p>Hello 
         <s:property value="id"/></h3>
     </s:if>

</body>


Your action class looks like this:-


public String execute() throws Exception {

if(null != id)
this.id = "Dear "+id;

        return SUCCESS;

    }


Now when you submit your page, and you have entered a name, it will be go to the action, and then repopulated on the refreshed Login page with text "Hello Dear <yourname>".