I've got an application using Spring MVC and Velocity. On one of my forms, I want to show all errors related to the form at the top of the page. I've figured out how to show errors related to one particular field (using the #springShowErrors macro), but I really want to have one large block of errors at the top of the form, instead of listing the errors next to each individual item.
I've done quite a bit of googling, and a few people have suggested something like
#if ($status && $status.errors.hasErrors())
#foreach( $error in $status.errorMessages )
<p>$error</p>
#end
#end
...but this gives me no output when placed just below the initial #springBind macro that attaches my command object to the form. Putting #springShowErrors just after the #springFormInput macro for each field works fine, so I know my validator is running and generating errors.
Any ideas? Have I missed something really silly?
Here's the complete form, with my non-working attempt just after the first #springBind
<form name="standardForm" id="standardForm" method="post" action="#springUrl("/requestAccess")">
#springBind("accessRequest")
#if ($status && $status.errors.hasErrors())
#foreach( $error in $status.errorMessages )
<p>$error</p>
#end
#end
<fieldset>
<label for="name">Name</label>
#springFormInput("accessRequest.name" " ")
<label for="company">Company</label>
#springFormInput("accessRequest.company" " ")
<label for="title">Title</label>
#springFormInput("accessRequest.title" " ")
<label for="email">Email</label>
#springFormInput("accessRequest.email" " ")
<button type="submit" value="send">Send</button>
</fieldset>
</form>
Thanks for any help or advice!
I think you're on the right track. There's no direct way I know of to get all the object error messages and field error messages in one aggregated list, however you can do this:
#springBind("bindName")
#if($status.errors.hasErrors())
## Global error messages
#foreach($e in $status.errorMessages)
<p>${e}</p>
#end
## Field error messages
#foreach($f in $status.errors.fieldErrors)
#springBind("bindName.${f.field}")
#foreach($e in $status.errorMessages)
<p>${e}</p>
#end
#end
#end
Not so clean, but it works.
Related
Good evening to all,
I have an error when I want to modify an entity.
I have my post entity, another error entity, and an associative postError entity.
So I want to modify the errors chosen for the concerned item on the updatePosteErreur form.
I already managed the case for the addition of the itemError, and it works.
However, when I want to modify the itemError by modifying the errors, I have this error message:java.lang.IllegalArgumentException: Parameter value [6] did not match expected type [com.MailleCoTech.SuiviProduction.entities.Poste (n/a)]
I don't understand...
Here is my service and my updateView:
<th:block th:each="erreur: ${erreurs}">
<input class="form-label mt-4" type="checkbox" name="erreurs" th:field="*{erreurs}" th:value="${erreur.id}"/>
<label th:text="${erreur.name}"></label>
<br>
</th:block>
if(!posteUpdateForm.getErreurs().isEmpty()){
List<PosteErreur> posteErreurs = posteUpdateForm.getErreurs().stream().map(erreur -> {
PosteErreur posteErreur = posteErreurService.findByIdPoste(posteUpdateForm.getId());
posteErreur.setId(posteErreur.getId());
posteErreur.setIdErreur(erreur);
posteErreur.setIdPoste(poste);
return posteErreur;
}).collect(Collectors.toList());
this.posteErreurService.save(posteErreurs);
}
return poste;
I don't put all the code, because I have the same view to add, and an add function in the service and everything works, it's when I modify that I get this error message :/
thank you in advance for your help and your time
I m building an app with a procedure to deposit folder so the user must browse different pages like this:
firstPage->secondPage->thirdPage...
So I used this:
<input type="button" value="Go Back" class="btn btn-primary">
But when I'm in the third page and go back it does:
thirdPage->secondPage->thirdPage...
With an infinite loop
How can I fix this?
Thank
Just using {{ URL::previous() }} won't solve your problem, because imagine you're at second page then goes to third, then come back to second: At this moment, the previous page is the third one, that's why this is happening. So if you want to fix this, you'll have to know to where each page should go and place that logic there. So if page2 must go back to page1, you'll have to do something like this:
#if( Request::is('secondPage') )
<script type="text/javascript">
window.location = "{ url('/firstPage') }";
</script>
#else
.....
#endif
i have been working on this problem for hours.
I have a form, with a textarea. I use the nicEdit texteditor. It replaces the textarea and shows a nice text editor, because i want my users to add some style to their content.
I use codeIgniter (PHP), and i use the form_helper to create the form. Also i use the form_validation for ss-validation and jquery validation for cs-validation
When i click submit, the form submits seemingly fine. I say this because i use fiddler (an http logger) and i see my text with the right html tags wrapped around it by the text editor.
but when i get the #_pots data in the view, somehow some part of the tags have been removed.
How fiddler traces the HTTP call and the submitted form data (seems correct)
Hello SO, <br><br>
<span style="font-weight: bold;">the following line should be bold</span><br><br>
<span style="font-style: italic;">the following line should be italic</span><br><br>
<span style="text-decoration: underline;">the following line should be underlined</span><br>
How my html looks in my view and in my print_r result from my #_post data
Hello SO,<br><br>
<span bold;"="">the following line should be bold</span><br><br>
<span italic;"="">the following line should be italic</span><br><br>
<span underline;"="">the following line should be underlined</span><br>
It looks like somehow, when i get my data back, it removes the style="font-weight
Does $_post do anything with special characters?!?! has someone experienced similar issues with this?
all responses are greatly appreciated.
You need extend the CI_Security class from Codeigniter and comment/remove/modify this line:
/*
if(in_array($_SERVER['REQUEST_URI'],$allowed))
{
$evil_attributes = array('on\w*', 'xmlns');
}
else
{
$evil_attributes = array('on\w*', 'style', 'xmlns');
}
*/
I have a simple form where there is a list:
<form method ="post" action ="">
<select>Select subject
<option value="1">Maths</option>
<option value="2">Science</option>
</select>
<input type="submit" name="Submit" />
My question is, if I select the option Maths, I would like the value to be sent eg /1.
What should be written in action? How should the route be written ?
get '' do
end
Your route could look something like this:
post '/subject' do
#subject = params[:subject]
# do whatever you want now
end
But you would need to give your select tag a name and your form an action:
<form method="post" action="/subject">
<select name="subject">
<!-- etc etc -->
Also have a look at related questions.
we tend to look at queries as GETs (makes sense, it is after all retrieving information)
rather than a POST which (doesn't actually change data) yet responds with a result page
a common (gnarly) pattern we often see is to rewrite (in js or redirect)
to the form
GET '/search/:q1/and/:q2' do
// result of search filtered by q1 and q2
end
which is also quite neat
How do you set different placements for different input types? More specifically how do you add another li after the one whos child label has an error class? To be more clear I want to specify that for fieldset "#SomeID" the error elements are in a new div/li/p whatever below their parent input.
<fieldset id="SomeID">
stuff
<div class="toggle"><input type="checkbox" name="BP" id="BP">I have read and agree to the Billing Policy above.</div>
<div class="toggle"><input type="checkbox" name="TA" id="TA">I have read and agree to the Terms and Agreement <a class="linkTA"><span>Learn More...</span></a></div>
</fieldset>
Do u mean this?
$("label.errorclass").append($("<li class='errmsg'>some error</li>"));
I think you want to select the li with the error class and use $.after to insert some html directly after it.
$('li.error_class').after('<li>some stuff here</li>');