This worked a month ago and now i reload the code and it doesn't work. here is my struts snip
<action name="checkManager" class="CheckAction">
<result>/pages/check_manager.jsp</result>
</action>
<action name="submitFile" class="SubmitFileAction">
<result name="success">/pages/submit_file.jsp</result>
<result name="error">/pages/check_manager.jsp</result>
</action>
So, the first page is checkManager. it has a button that calls the submitFile action. When that fires, it checks a password, if it fails the action class sends an error result. Now a month ago the result error above would redirect the user back to the original check_manager.jsp page complete with data that was loaded originally and the error message. Today, it redirects the user to the raw check_manager.jsp page. no data, its like the servlet never fired and its just rendering a blank jsp page. I checked the source history and nothing has changed in this application.
I don't understand why this would stop working, can anyone give me an idea? i have to present this to the client in about an hour and a half so i'm really stuck here.
note, i tried changing the error to this
<result name="error" type="redirectAction">checkManager</result>
and I get my data back, but i loose my error message which isn't a good thing. ugh, any ideas?
if (enteredHash.equals(storedHash)) {
_log.debug("The password matched");
UserSession<User> userSession = (UserSession<User>) session
.get("user");
#do logic#
} else {
_log.debug("The password didn't match");
addActionError("The password you entered was incorrect, nothing was sent to the bank.");
return ActionSupport.ERROR;
}
return ActionSupport.SUCCESS;
my jsp
<s:if test="hasActionErrors()">
<div class="errors">
<s:actionerror/>
</div><br>
</s:if>
again, this worked perfectly a month ago. All i did was check out that branch which has been untouched and deploy it. Now it doesn't work.
A quick fix could be to add this to getCheckList in the CheckAction:
public Collection<Check> getCheckList() {
ActionContext.getContext().getSession().put("checkList", checkList);
return checkList;
}
and add this to the SubmitFileAction:
public Collection<Check> getCheckList() {
return (Collection<Check>) ActionContext.getContext().getSession().get("checkList");
}
This is not a good permanent solution but should get you where you need to get in a crunch!
Related
I get an error when I refresh a page displayed during a conversation. How to avoid this error?
The situation:
I have 2 JSF pages, index.xhtml and age.xhtml.
index.xhtml contains a form where the user enter a birthdate (a property of the backing bean "bean"). When the user submits the form, age.xhtml displays the age according to the birthdate.
The form is submitted with a redirection:
<h:commandButton value="Submit" action="#{bean.computeAge()}" />
computeAge method:
conversation.begin();
return "age?faces-redirect=true";
The same backing bean "bean" is used by both pages. This backing bean has a conversation scope.
Page age.xhtml:
Your age: #{bean.age} years
getAge method:
if (!conversation.isTransient()) {
conversation.end();
}
return ejb.computeAge(birthdate);
All is OK, except when I refresh age.xhtml. Then I receive this error message:
WELD-000321 No conversation found to restore for id 3
The URL displayed by the browser before and after the refresh:
http://localhost:8080/tpjsf1/faces/age.xhtml?cid=3
The problem comes from cid=3 at the end. Is it possible to avoid the error page when the user refreshes age.xhtml?
The error occurs as you are ending the conversation in the getAge method. In your case the conversation should end when you navigate back to the index page. In order to handle the non existent conversation exception, add the below tags to the web xml. This will redirect the exception to the mentioned page.
<error-page>
<exception-type>org.jboss.weld.context.NonexistentConversationException</exception-type>
<location>/my-foo-bar-exception-page.xhtml</location>
</error-page>
I wonder whether i can use 1 action to load data and update it?
It mean i have a page call about.jsp, manager will click a link to access this page. after redirect into this page, this page load content of about and update content if user edited data but two tasks can be use 1 action.
my i dea is, user use a action call AboutAction to load data to about.jsp page, after end user edited data on about.jsp and click submit, it will send data to AboutAction and update it?
Can i do that? and how?
First thing What you asked is one of the beauty of Struts2
xml :
<action name="AboutAction" class="AboutAction" method="load">
<result>showMe.jsp</result>
<result name="input">about.jsp</result>
</action>
<action name="AboutAction" class="AboutAction" method="update">
<result>showMe.jsp</result>
<result name="input">editsuccess.jsp</result>
</action>
Action :
public String load(){
//logic to load
return SUCCESS;
}
public String update(){
//logic to update
return SUCCESS;
}
I have question regarding redirection in Grails web-flow.
I am in a view state which will allow users to enter the answers for a question. On 2 wrong attempts I should be able to re-direct the user to view page from different controller. What i mean is
challengeQuestionOne{
onRender() {
//Display question
}
on('next') {BuildQuestion command ->
bindData(flow.recovery,command)
[return the model to flow]
if(command.hasErrors()) {
flow.command = command
return error()
}
if(check for status. If doesnot pass){
flash.message=message(code:'loginForm.account.locked', default: 'Please Contact Admin.')
redirect(controller : "login",action: "login")//how to redirect from here to diff controller
}
if (//compare answer entered) {
}
else{
//set status not active
}
}.to("challengeQuestionTwo")
on(Exception).to("error")
on('cancel').to('finish')
}
I have tried to redirect from onRender . It was redirecting to the page. But how do I display the error msg on the redirected page. How can i forward the error message from one controller to other??
Ivo Houbrechts wrote an excelent tutorial about grails webflow:
Webflow defines its own flash scope. Although it has the same semantics as the standard grails flash scope (the main purpose is to store objects only until after the next request), it is a different scope. This means that objects stored in webflow's flash scope are not visible in standard grails actions.
import org.springframework.web.context.request.RequestContextHolder
....
RequestContextHolder.currentRequestAttributes().flashScope.message = "YourMessage"
You can read more here:
http://livesnippets.cloudfoundry.com/docs/guide/
Flash scope will not work in this case as expected.
Try to use another approach to show error. E.g. you can pass parameters with redirect. Or you can throw some exception and check it on rendered page as follow:
<g:if test="${flowExecutionException}">
<div class="error"><g:message code="loginForm.account.locked"/></div>
</g:if>
I have integrated Spring Security in my application , and would like to display an error message to the user in case of Bad credentials.
I have wired everything in to display the message , but it does not work. Please find the code snippets below
spring-security.xml
<form-login
login-page="/spring/login"
authentication-failure-url="/spring/login?error=true"
default-target-url="/spring/index"/>
<authentication-manager>
<authentication-provider user-service-ref="customService">
</authentication-provider>
</authentication-manager>
CustomService implements UserDetailsService , and in the loadUserByUsername method , i am returning the Spring UserDetails object which contains the details of the user.
My Controller looks as follows
#RequestMapping(value="/login", method = RequestMethod.POST)
public String getLogin(#RequestParam(value="error", required=false) boolean error,
ModelMap model){
if (error == true) {
// Assign an error message
model.put("error", "You have entered an invalid username or password!");
} else {
model.put("error", "");
}
return "loginpage";
}
My loginpage contains the following div to paint the error
<div id="login-error">
<c:if test="${not empty param.error}">
Your login attempt was not successful, try again.<br />
</c:if>
</div>
When I enter wrong credentials , it is redirected to the login page, but the message is not being displayed.
Please help and correct me if I am doing anything wrong.
Issue Resolved.
The real reason for the error message not being painted was that the ${not empty param.error} was not being evaluated.
To fix this issue , modified my web.xml to conform to the Servlet 2.5 Spec. and it worked like a charm. :)
Please refer my post on changing the Servlet Spec to v2.5
Issue with evaluating ${error} in Spring
Hope this helps all those who might face this issue.
We are working on SmartGWT 2.2, and Struts2.
I have created a sample form(DynamicForm) which asks to upload file and mapped action class for processing file upload.
I have setup form.setCanSubmit(true);
My call is succefully gets transferred to struts action class and file is getting uploaded also.
struts.xml
<action name="FileUploadAction" class="FileUploadAction" >
<result name="success" type="redirect">success</result>
</action>
But the problem is that control is not getting back to...
form.submit(new DSCallback(){
#Override
public void execute(DSResponse response, Object rawData,
DSRequest request) {
System.out.println("Response: " + response.getHttpResponseCode());
SC.say("back");
System.out.println("BACK...........");
}
});
I read in Smartgwt, Dynamic Form API that,
if this.canSubmit is true, callback is ignored..
As, we are not using DataSource, I have to use this.canSubmit to true.
Response from ActionClass gets struck at 'http://127.0.0.1:8888/success'
So, what is an alternate solution?
you can use hidden iframe and JSNI call that hidden iframe from your server action class....
Thank you.