Issue with Struts2 checkbox tag - struts2

Issue with Struts2 checkbox tag
<s:checkbox name="user.secondaryContactRequired" />
Here secondaryContactRequired is a boolean type in User Entity. When I click on check box value of secondaryContactRequired is true.
But when I uncheck the checkbox then secondaryContactRequired is taking as true only, but I want this value as false
Why this is happening? Please advise me what's wrong with this.
Thanks in advance

I have included interceptor...Now its' working...Thanks to all for sharing your valuable solutions

Related

Grails : Using select tag of grails with disabled property set to true ignores the value

I need to disable a select element in grails depending on its value. The problem is when I started to add the disable property something is quite wrong with the code.
An example is when the form is sent to the backend, its as if there is no value for that select element and the value sent is null. But, when I checked the DOM, there is a selected attribute in the element. I tried to remove that disabled property because I have a feeling that it has something to do with the bug that I'm encountering and I was right because after removing it, everything worked correctly again.
this is the select tag
<g:select name="detail-entryNameId"
value="${journalEntryName.savingId}"
from="${journalEntryNameInstanceList}"
optionKey="savingId"
optionValue="displayName"
readonly="${journalEntryInstance.paymentMade}"
/>
One more thing about this element is that it can occur as many as possible, which means I have a table and in every row, that element exist so I cannot simply manipulate it.
I've also read in this post how can i make a textfield read only in grails? that "If you use disabled="true" the value will not actually be submitted in the form, so the <g:field/> tag should be used." which proves that disable attribute affects the value of the element.
How can I disable the select element and at the same time, still get its value correctly?
The problem is that in HTML the mere existence of the disabled attribute disables the tag. The value of the attribute (true/false) is ignored.
In such cases the solution is to use an <g:if> to create the tag with or without the disabled attribute according to a condition.
In your case, since you want the value even when the tag is disabled you can add a <g:hiddenField> with the same name and value as the disabled select.

disable the validation when input text is blank

I want to disable the validation when user did not enter the text.I am trying to chech whether the input text is empty. plz suggest hot to check empty for text box.
<h:inputText value="#{countryBean.usersDetailsDTO.firstName}" id="empFName" disabled="#{not(countryBean.selectedEid eq '1')}">
<f:validator validatorId="nameValidation" disabled="#{empty countryBean.usersDetailsDTO.firstName}"/>
</h:inputText>
First, using the disabled attribute in this way would not work as intended because the value of the firstName attribute would be set in the Update Model Values phase, while validation will occur prior to that in the Process Validations phase. I would expect it to disable the validator only if the firstName field were already set to null/empty on the prior request.
As for how to accomplish the task. Please see https://stackoverflow.com/a/6113982/2725716

Clearing jQueryMobile DateBox value from an event

I have 2 DateBox (from & to). What I want to do is whenever I click on the "from" DateBox it will always clear the "to" DateBox.
I'm looking at the doclear method and I'm not sure if it is the right one or even know how to use it.
Just to be clear I'm using this.
Any help would be appreciated. Thanks!
In my testing setting the value of the box to an empty string ('') works.
Assuming id of fromDate and toDateon the two boxes the following code should do the trick:
$('#fromDate').click(function(){
$('#toDate').val('');
}

not able to find multi select dropdown, only h:selectManyListbox is present

I am looking for a dropdown something like this
I am not able to find any component that suits my need.Only following component is present, but this component is not fulfilling my needs as the data is not showing like a dropdown with multi-select capabilites in it.
<h:selectManyListbox id="option">
<f:selectItems value="#{supportData.states}" />
</h:selectManyListbox>
Please suggest , what shall I do?
you can use SelectCheckboxMenu in primefaces
The primefaces will help you and the showcase is here.
http://www.primefaces.org/showcase/ui/selectCheckboxMenu.jsf

Preselect radio button in Struts2

Using Struts2, I have a very simple radio tag like following
<s:radio label="correctOption" name="correctAnswer" list="
#{'1':'1','2':'2','3':'3','4':'4'}" value="questionVo.correctAnswer"/>
questionVo.correctAnswer returns 2. So I want the second radio button to be preselected but it is not happening. I even tried:
<s:radio label="correctOption" name="correctAnswer" list="
#{'1':'1','2':'2','3':'3','4':'4'}" value="%{1}"/>
But that does not work either.
What am I doing wrong?
Remove the value attribute from the jsp. Then in your Java code make sure that the "correctAnswer" variable has the value you want.
This has also the added effect that works in postbacks (when the user has selected something
on the radio and the form is shown again)
It works for me for the following:
<s:radio
label="correctOption"
name="correctAnswer"
list="#{'1':'1','2':'2','3':'3','4':'4'}"
value="%{1}"/>
I believe that the issue is that the value needs to be escaped properly eg:
value="%{'1'}"
and match the declaration exactly.
Here's the solution:
<s:radio label="correctOption" name="correctAnswer" list="
#{'1':'1','2':'2','3':'3','4':'4'}" value="1"/>
another one in case of strings in the static list:
<s:radio label="Gender" name="gender" list="
#{'male':'Male','female':'Female'}" value="'male'"/>

Resources