How to show validation errors as a list - struts2

I have a simple login form with this code in jsp file:
<s:form
action="conexion" validate="true" theme="xhtml" target="formError">
<s:textfield name="username" key="profile.rut" />
<s:password name="password" key="profile.password" />
<s:submit id="boton_ingreso"/>
</s:form>
when that is rendered, it renders this way:
<form onreset="clearErrorMessages(this);clearErrorLabels(this);" method="post" target="formError" action="/AgendaPlus/conexion.action" onsubmit="return validateForm_conexion();" name="conexion" id="conexion">
<table class="wwFormTable">
<tbody><tr>
<td class="tdLabel"><label class="label" for="conexion_username">RUT:</label></td>
<td><input type="text" id="conexion_username" value="" name="username"></td>
</tr>
<tr>
<td class="tdLabel"><label class="label" for="conexion_password">ContraseƱa:</label></td>
<td><input type="password" id="conexion_password" name="password"></td>
</tr>
<tr>
<td colspan="2"><div align="right"><input type="submit" value="Submit" id="boton_ingreso" class="ui-button ui-widget ui-state-default ui-corner-all" role="button" aria-disabled="false">
</div></td>
</tr>
</tbody></table></form>
That way, when an error occurs, the error is shown above each field with error as a <tr> tag and since it is a table, I cannot style it to move to other place. I tried with target attribute of <s:form> tag but it did not work.

See the tag docs for fielderror:
<s:fielderror />
You know there are other themes, and that you can create your own, right?
For example, the "simple" theme doesn't render any tables or errors.
The target attribute seems a weird use for error reporting.

Related

Get Checkbox value from the database into a table row (MVC)

This may be a simple question but I am new to MVC. So please bear with me.
I want to get the checkbox value into the table row. Here is my code for the table.
<tbody>
#foreach (var itms in Model.takeoverdlist)
{
<tr id="#itms.TAKEOVER_D_id">
<td class="text-left">
<input type="hidden" name="tasklist[]" id="task_id" value="#(itms.TAKEOVER_D_id)" />
</td>
<td class="text-left">
<input type="text" id="task#(itms.TAKEOVER_D_id)" name="task#(itms.TAKEOVER_D_id)" value="#(itms.TAKEOVER_D_task)" style="width:100%" />
</td>
<td class="text-left">
<input type="text" id="amnt#(itms.TAKEOVER_D_id)" name="amnt#(itms.TAKEOVER_D_id)" value="#(itms.TAKEOVER_D_amount)" style="width:100%" />
</td>
<td class="text-left">
<input type="checkbox" id="donebit#(itms.TAKEOVER_D_id)" name="donebit#(itms.TAKEOVER_D_id)" value="#(itms.TAKEOVER_D_done)" style="width:100%" />
</td>
</tr>
}
I get other values just fine, but the checkbox is unchecked. It should be checked.
When I inspect the table the value for the checkbox is "value".

Grails - Edit - does not retain the values when created

Grails issue :
When clicking over the Edit in the following screen : Domain and Variable values does not seem to retain their values (When creating it, we are able to enter the values - Domain and Variable, but it does not retain the values when editing..
Clicking over EDIT in the following screen :
does not retain the values of domain and variable alone:
.gsp code below
<tr>
<td>Domain<span style="color: red">*</span></td>
<td><g:if test="${isCreate}">
<g:select class="statSele" id="domain_name" name="domain_name" from="${com.datumrite.master.DomainMaster.list()}" optionKey="id" noSelection="['':'Select Domain']" onchange="${remoteFunction(
action:'driveVariableFromDomain',
params:'\'id=\'+escape(this.value)',
update: 'variable_select'
)}"></g:select> <br>
</g:if>
<g:else>
<input disabled="true" id="dN" name="name" type="text" style="margin-bottom:4px" value="${(data.domain_name instanceof String)?'':com.datumrite.master.DomainMaster.get(data.domain_name)}" />
</g:else>
</td>
</tr>
<tr>
<td>Variable<span style="color: red">*</span></td>
<td><g:if test="${isCreate}">
<span id="variable_select">
<g:select class="statSele" name="var_name" from="${[]}" value="${data?.var_name}" noSelection="['':'Select Variable']"></g:select></span> <br>
</g:if>
<g:else>
<input disabled="true" type="text" name="name" style="margin-bottom:4px;margin-left:5px" value="${data?.var_name}" />
</g:else></td>
</tr>
<tr>
<tr>
<td>Condition<span style="color: red">*</span></td>
<td><g:if test="${isCreate}">
<g:select class="statSele" id="constrain_type" name="constrain_type"
from="${['Lesser than','Greater than','Lesser than nor Equal','Greater than nor Equal','Equal To','Not Equal To']}"
value="${data?.constrain_type}" noSelection="['':'Select Condition']">
</g:select>
</g:if>
<g:else>
<input disabled="true" name="name" value="${data?.constrain_type}" type="text" style="margin-bottom:4px"/>
</g:else></td>
</tr>
And, I am using MySQL DB for the same.
can anyone help me with this issue ?
You need to make sure the subscription instance is passed when you click Edit link. (possibly under <g:link...> tag) The gsp you've posted is for create view. Check your List of Subscription view. (possibly show.gsp)

URL found in auth.gsp - beginner

I need to know the following. I copied the following code from auth.gsp. I need to know what:
1.) I need to know what '${postUrl}' means?
2.) I did copy this code and paste it in another GSP called index.gsp, but the page didn't login successfully.
<form action='${postUrl}' method='POST' id="loginForm" name="loginForm" autocomplete='off'>
<div class="sign-in">
<h1><g:message code='spring.security.ui.login.signin'/></h1>
<table>
<tr>
<td><label for="username"><g:message code='spring.security.ui.login.username'/></label></td>
<td><input name="j_username" id="username" size="20" /></td>
</tr>
<tr>
<td><label for="password"><g:message code='spring.security.ui.login.password'/></label></td>
<td><input type="password" name="j_password" id="password" size="20" /></td>
</tr>
<tr>
<td colspan='2'>
<input type="checkbox" class="checkbox" name="${rememberMeParameter}" id="remember_me" checked="checked" />
<label for='remember_me'><g:message code='spring.security.ui.login.rememberme'/></label> |
<span class="forgot-link">
<g:link controller='register' action='forgotPassword'><g:message code='spring.security.ui.login.forgotPassword'/></g:link>
</span>
</td>
</tr>
<tr>
<td colspan='2'>
<s2ui:linkButton elementId='register' controller='register' messageCode='spring.security.ui.login.register'/>
<s2ui:submitButton elementId='loginButton' form='loginForm' messageCode='spring.security.ui.login.login'/>
</td>
</tr>
</table>
</div>
</form>
Spring security work on filters. If you print postUrl in your gsp file then it looks like /myApp/j_spring_security_check, only /j_spring_security_check URL is processed by Spring Security filter.
If you past auth.gap and not sending this url then cannot login. Change your gsp slightly to make this run, replace ${postUrl} with ${createLink(uri: '/j_spring_security_check')}.

CodeIgnitier CSRF protection how submit form which is loaded via jquery tabs

I'm working on some backend project and want to load form via jQueryUI tabs
<div id="parameters_tabs" style="width:920px;">
<ul>
<li><?=$this->lang->line('tab_name')?></li>
</ul>
</div>
in response I produce few forms as in example below:
<?
for ($i = 0; $i < count($groups); $i++)
{
?>
<form id="group_form<?=$i?>" method="POST" action="<?=base_url()?>update_group">
<input type="hidden" name="<?=$this->config->item('csrf_token_name')?>" value="<?=$token?>" />
<input type="hidden" name="id" value="<?=$groups[$i]['id']?>" />
<tr>
<td>
<input type="text" value="<?=$groups[$i]['name']?>" name="name" />
</td>
<td>
<input type="text" value="<?=$groups[$i]['short_name']?>" name="short_name" />
</td>
<td>
<textarea cols="80" rows="4" name="desc"><?=$mgroups[$i]['desc']?></textarea>
</td>
<td style="width: 30px">
<a class="save" onclick="$('#group_form<?=$i?>').submit();"><?=$this->lang->line('save')?></a>
</td>
</tr>
</form>
<?
}
?>
when clicking on "save" I got standard error about CSRF protection:
"An Error Was Encountered
The action you have requested is not allowed."
Can anyone help me and tell where I made mistake? Of course in source I see proper csrf_token_name.
This article helped me when I was experiencing the same issue. Using the built-in form helper form_open() function might also help solve the problem (as it generates the hidden CSRF field for you).

How do i adjust the label width n make it bold ? in the jsp of Struts2 aplication?

I have an struts2 application with jsp pages where i have struts2 tags something like this
<s:form action="contactus.action" method="post" name="ContactUs Form" >
<s:textfield name="cust.fname" key="fname" size="25" maxlength="20" required="true" />
<s:textfield name="cust.lname" key="lname" size="25" maxlength="20" required="true"/>
</s:form>
where i get the "label" and the "input " box , I have to make the label as bold and adjust the width for the long labels ,In the text.ftl i cannot make such changes i guess ?
Here i display the label from the resource bundle .
Then how do i adjust the label width n make it bold ?
When you write struts tags that are converted ultimately to HTML code as follows
JSP Code using Struts Tags
<s:form method="post">
<s:textfield label="Name" name="name"/>
<s:textfield label="Age" name="age"/>
<s:submit/>
</s:form>
Converted HTML Code
<form id="quizBasic" name="quizBasic" onsubmit="return true;"
action="/struts2-showcase/validation/quizBasic.action" method="post">
<table class="wwFormTable">
<tr>
<td class="tdLabel">
<label for="quizBasic_name" class="label">Name:</label>
</td>
<td>
<input type="text" name="name" value="" id="quizBasic_name" />
</td>
</tr>
<tr>
<td class="tdLabel">
<label for="quizBasic_age" class="label">Age:</label>
</td>
<td>
<input type="text" name="age" value="0" id="quizBasic_age" />
</td>
</tr>
<tr>
<td colspan="2">
<div align="right">
<input type="submit" id="quizBasic_0" value="Submit" />
</div>
</td>
</tr>
</table>
</form>
so you can define default css class for label having name "label" and define clas like this in your css file, import that css file in your jsp and you can do what ever you want with that label
.label{
color: red;
font: bold;
font-size: 20px;
}

Resources