Anand Sivathanu

Ranch Hand
+ Follow
since Jun 25, 2010
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
4
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Anand Sivathanu


In HTTP Servlet request object, "foo" is set to value "bar".

Using @RequestAttribute("foo"), I try to fetch the value.

In spring showcase tutorial,they have mentioned that we can fetch the value of foo using @RequestAttribute("foo").

But not fetch. why it is not fetching? this is my question
8 years ago
Hi Friends,

@RequestAttribute in spring mvc not fetch the value.

I have a modelAttribute.here "foo" attribute is set a value of "bar"




I try to invoke the request attribute value for "foo" using @RequestAttribute("foo").But value is null.

Then i try using request.getAttribute("foo").value is printed. I not know what is wrong in @RequestAttribute("foo").





Please help me in this issue.

Regards,
Anand
8 years ago
Hi friends,

I am new to spring mvc.doing a sample project using spring mvc.
In the project,I have a href.I mentioned the correct URL path
in that h ref.but due to append of duplicate URL path,Jsp page
which I am trying to hit is not triggered.

I googled,but not find a suggestion.

For that reason I have mentioned the below story.



In inventory.jsp,this code will invoke "priceincrease.jsp" through FormController's initForm(mentioned below)
<c:url value="price/increase" var="theAction" />
<a href="<c:url value="${theAction}"/>">Increase Prices</a>





In priceincrease.jsp,I am submitting the form,and "inventory.jsp" is called now.
"price" is getting appended with "submitter" because priceincrease.jsp is called
by the above code("/price/increase")
<c:url value="submitter" var="theAction" />
<form:form method="post" commandName="priceIncrease" action="${theAction}">
<input type="submit" align="center" value="Execute">



inventory.jsp is called now.
So far so good.

The issue arise here.
In inventory.jsp,I have a href,
<c:url value="price/increase" var="theAction" />
<a href="<c:url value="${theAction}"/>">Increase Prices</a>

the url found here is "price/price/increase" which is wrong.
"price" is getting appended with the "price/increase".

So when I click the href,page is not displayed due to the wrong path.("price/price/increase")
"price" from @RequestMapping("/price") PriceIncreaseFormController,is getting appended with
"price/increase" of inventory.jsp.

How to handle this?.
"price" of @RequestMapping("/price") PriceIncreaseFormController is appended
to any url(price/increase) that we are calling.and this makes the invalid path("price/price/increase").

Please help me in this issue.

Regards,
Anand
8 years ago

Bill Gorder wrote:My first suggestion to you if you are learning Spring is going to be use the modern controllers. Your controllers should not need to implement any Spring interfaces or extend any Spring classes (like SimpleFormController etc). I would first recommend you to update your Spring to the latest version and rework your projects controllers with the modern @Controller style.

You can see some examples of this here:

http://krams915.blogspot.com/2010/12/spring-3-mvc-using-modelattribute-in.html
https://github.com/SpringSource/spring-mvc-showcase



Hi Bill Gorder,

Thanks for the suggestion. URL that you have mentioned looks good. will practice with this also and get a good idea about spring mvc

Now I am following @Controller

I able to solve the above issue by using map,instead of using list."key" will be the actual value of the label and label will be the present as value against the key.

eg:-
map.put("spring3","Spring Framework")

"Spring Framework" will label displayed in JSP page and "spring3" is the actual value of the label "Spring Framework"

Regards,
Anand

8 years ago
Hi Friends,
I have created a web using spring mvc.

I have a field in web page called

Favourite Web Frameworks: checkbox struts checkbox springmvc checkbox hibernate

My requirement is
label will be "Struts"
value is "struts"

label will be "Spring MVC"
value is "springmvc"

Trial 1 - starts
I have create a class called
"Framework.java"

In UserRegistrationFormController.java,

In UserRegistration.jsp,

Now when i try to submit the form,form is not submitted and "invalid data" is thrown.
Trial 1 - ends

Trial 2 - starts
So I tried the other way,instead of using "Framework" class,I used "String" class.

In UserRegistration.jsp,

Here web page displayed checkboxes for springmvc,struts1,struts2,jsf,apachewicket.
here both label and value of check box are same.when form is submitted it is working.
But here we cannot achieve, label displayed in web page to be different with actual value

As label should be more readable and value of a label will not be same
for eg:-
Label is "Spring MVC" (displayed to user)
value is "springmvc" (actual value for processing).
I used Trial 1 (mentioned above).But "invalid data" in red font is coming.

I googled for the issue.Cannot able to find the suggesstions.

Please guide me in this issue.

Regards,
Anand
8 years ago

Mark Spritzler wrote:Well, you can put @Transactional on the class level and then all methods from your interfaces that that class implements are now all transactional.

That is a way to put the annotation in once and get many methods covered.

So one trick it to make sure you put all those methods that start with into a single interface that that class implements. Or just put @Transactional on that interface.

Mark



Oh.
You are telling to put @Transaction in the class level or interface level

1.
class level - flavor 1


2.
interface level - flavor 2


These are the two flavors you are coming to say. Am I right?

Regards,
Anand
8 years ago

Mark Spritzler wrote:To use @Transactional Annotations. Your config has to have <tx:annotation-driven/> And you need to have a transactionManager bean. That is all. Now you can put @Transactional on any service method and it will be transactional.

No need for any aop or aspect classes. Everything that you did before in xml is taken care of. That is why using annotations for Transactional methods is so much easier than using xml for it.

Mark



Hi Mark Spritzler,
Thanks for your comment. I understood your comment and totally agree with that.
My question here is,
I keep on put @Transactional for any service methods that i needed.I feel lazy to put @Transactional also.
Instead I would like to put in some common area @Transactional and declare that methods starting with book*(bookBusTicket,bookPlaneTicket,bookTrainTicket) present in org.simple.service.TicketBookingService class.
This I can put in xml as


But I would like in programmatic way.(@Transactional in common area and declare methods starting with book*(bookBusTicket,bookPlaneTicket,bookTrainTicket) present in org.simple.service.TicketBookingService class)
Is there any programmatic way?(May be annotation or something)
(My question may be wrong.correct me if i am wrong)

Regards,
Anand
8 years ago
Hi friends,
I have a question regarding spring transaction using AOP.
I can able to declare an transaction advice in spring.xml and able to apply the advice to respective methods using pointcut.




Here transactionAdvice(txAdvice) is applied to all methods starting with book present in org.simple.service.TicketBookingService.



But,

I would like to use annotation.So what i did is

This is also working fine.

Now what I feel is,here @Transactional is repeated in all methods which is starting with book.So i would like to put in some common area.
So I did the following,

1.
in spring.xml,by mentioning this spring will scan for aspect components.

2.
I created a class called TransactionLoggingAspect.





My question is,
what is the annotation equivalent of the above "txAdvice"?
In TransactionLoggingAspect.java,Where I can put the annotation equivalent?

In spring tutorial,
http://static.springsource.org/spring/docs/3.0.x/reference/transaction.html
they have mentioned for XML part,which is working fine.
But I am searching for annotation part.But not found.

Please help me in this issue.

Regards,
Anand
8 years ago
Thanks for your reply Ulf Dittmer. I will try the CrossContext
8 years ago
Hi Friends,

I need to communicate to a servlet present in another web application of the same web container.

As I googled, I found of using getServletContext().getContext("/Cart");

Current web application is "HelloWorld" and I need to commuicate to Cart.

So i invoked


But I printed the value of otherContext, it is null.

so I not able to forward the req and res.



Please help.

Regards,
Anand
8 years ago
But some of them have mentioned that Spring in Action is more theoretical
8 years ago
Hi friends,

I am new to spring framework. Please suggest a good book for spring.I have googled and searched for good book in spring.But not
able to come to a conclusion.Please suggest a good book for spring

Regards,
Anand
8 years ago
@Steve Luke

Oh. you are telling about intercepting filters. To ensure the "logged user" not null for each request hit

am i right?
9 years ago
JSP
Hi Friends,

I am new to SQL. Please suggest good book for SQL, So that a lay man can understand.