This question already has an answer here:
How to fetch all select box value in one array list
(1 answer)
Closed 6 years ago.
I am using struts2 select tag: http://struts.apache.org/2.0.14/docs/select.html
this is the code
<s:select name="fmrTenant.terminationReason" multiple="true" headerKey="-1" list="rejectionReasons" value="%{fmrTenant.terminationReason}" required="true" size="10"/>
name="fmrTenant.terminationReason"
refers to the following code
public void setTerminationReason(List terminationReason) {
this.terminationReason = (String[])terminationReason.toArray();
}
my code is having issues here. Should the parameter type of a variable that stores values coming from select box be List??
I tried looking online for the solution but there seem to be no examples that use struts2 select tag with multiple attribute enabled and show what the java method should look like. I am so confused.
The following should work just fine (assuming this.terminationReason is a String[]):
public void setTerminationReason(String[] terminationReason) {
this.terminationReason = terminationReason;
}
Alternatively, if terminationReason is stored as a list the following should work:
private List terminationReason = new ArrayList();
public void setTerminationReason(List terminationReason) {
this.terminationReason = terminationReason;
}
Related
Im new to vue.js, and Im trying to do a simple if with a date field within my ASP.NET MVC project.
I've seen examples on vue tutorials where the condition is done in the js file, but Im not convinced that this would help me.
I currently have a date field in my ViewModel that has two drop downs. This is for an application form that asks a person how long have they lived at their address. They can select up to 11 months and 6+ years. I have a button that allows them to add another address. When you click this button, the viewModel for the date fields are repeated so they can add another one (stored in a List).
However I want to wrap this around a condition that says only if the date entered is less than 6 years then the button would appear. Like I said, at the min it is there always.
my code for the address and its button is:
<fieldset>
<legend>Please provide all your addresses in the last 6 years</legend>
#Html.EditorFor(m => m.PreviousAddresses)
</fieldset>
<button class="button">Add another previous address</button>
What im trying to do is something like v-if="PreviousAddress < 6" but I dont think thats right. Can someone help with the syntax?
EDIT: The validation works on the back end. Just need the client side to work with it:
[Minimum(72, ErrorMessage = "Please enter 6 years address history")]
public int TotalAddressHistoryInMonths
{
get
{
int totalMonths = CurrentAddress?.Duration?.TotalPeriodInMonths ?? 0;
if (PreviousAddresses != null)
{
foreach (ResidencyInputViewModel residency in PreviousAddresses)
{
totalMonths += residency?.Duration?.TotalPeriodInMonths ?? 0;
}
}
return totalMonths;
}
}
The solution you have appears to be correct, but can you post the rest of your code. Seeing the data object should help.
This question already has an answer here:
How can I bind a text which contains url as html
(1 answer)
Closed 8 years ago.
My colleague Patrick & I currently converting an autocomplete component from Web UI to Polymer.dart.In Web UI we provided a HTML rendered list to the autocomplete in order to give a programmer the opportunity to style the results. Based on the input's value we filtered the list and displayed the matching results.
What would you recommend to achieve the same behaviour in Polymer.dart? Should we approach this completly differently?
Old Web UI code:
<template iterate="entry in filteredEntries">
<li class="b-autocomplete-results-li">{{ entry.sanitizedHtml }}</li>
</template>
Class for one entry:
class AutocompleteEntry {
final String id;
final String searchableText;
final Element _element;
AutocompleteEntry(this.id, this.searchableText, this._element) {
// remove the data-id and data-text since we don't need them in the html
_element.dataset.remove('text');
_element.dataset.remove('id');
}
get sanitizedHtml {
var validator = new NodeValidatorBuilder()..allowHtml5();
var documentFragment = document.body.createFragment(_element.outerHtml, validator: validator);
return documentFragment;
}
}
Update
A ready-to-use element for Dart Polymer 1.0 is bwu-bind-html
No there isn't. This is intentional because it is prone to XSS attacks.
What you can do is to use an element like <safe-html> instead.
My answer to this question HTML Tags Within Internationalized Strings In Polymer.dart shows the full source code.
I trying to drag and drop of rows using primefaces datatable/datagrid.But this is issue in primefaces.What is best way to integrate drag and drop of primefaces datatable/datagrid with jquery or other third party api plugin.Please suggesst to me.
You need to add some JavaScript (JQuery) in your JSF page to make Datatable sortable and to disable selection mode. Listed below doReorder() method gets the new order of the rows and save to order_q variable:
<script type="text/javascript">
$(document).ready(function () {
$('.ui-datatable tbody').sortable();
$('.ui-datatable tbody').disableSelection();
});
function doReorder() {
var order = '';
var len = $('.row').length;
$('.row').each(function (index) {
order += ($(this).text() + ((index == (len - 1)) ? '' : ';'));
});
$('#order_q').val(order);
return true;
}
</script>
Add some code to your Datatable component. You see a new column with number of the row as value with attribute styleClass set to „row” . There is a hidden variable order_q updated during execution JavaScript method doReorder() :
<p:dataTable rowIndexVar="rowIndex"
var="entry" value="#{myBean.list}" >
<p:column headerText="#">
<h:outputText styleClass="row" value="#{rowIndex}"/>
</p:column>
... (other colums as you wish)
</p:dataTable>
<h:inputHidden id="order_q" value="#{myBean.order}"/>
<p:commandButton value="Submit order" ajax="false" onclick="return doReorder()" action="#{myBean.reorder}"/>
Your bean class should contain a String field order (with getters and setters of course). The variable wil store a value from the JavaScript – the new order of our list (source data of the Datatable widget). We need to implement also a method mentioned in the xhtml - reorder() to handle action from button „Submit order”
public String reorder() {
Map < String, String > tmp = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
String order = tmp.get("order_q");
if (order != null && !order.isEmpty()) {
ArrayList < YourData > reordered = new ArrayList < > ();
for (String s: order.split(";")) {
try {
Integer i = Integer.parseInt(s);
YourData data = list.get(i);
reordered.add(data);
} catch (NumberFormatException nfe) {}
}
list = reordered;
}
return null;
}
That’s all! Now you can reorder your Datatable using drag&drop feature and save the new order by clicking a button. I leave a reference to my blog where all of this is described:
http://michalu.eu/wordpress/drag-and-drop-rows-to-reorder-your-datatable-in-primefaces/
Just use
<p:dataTable draggableRows="true"
On Primefaces 5.0 DataTable documentation you can see the parameter draggableRows, like this :
draggableRows | false | Boolean | When enabled, rows can be reordered using dragdrop.
http://www.primefaces.org/documentation
As far as i know from datatables (primefaces) in my applications, they have 2 main states/modes. It may be not the correct word but i stay with it. The 1st is display only, and 2nd editing.
(In display i dont see events triggering so DnD wont work.) in editing they have a serious issue with selectivity. u have to press at the edge of the table and not in inline components reach to get the focus on the row. So The drop must be done in that area and only propably for events to trigger. If u see the examples...all drops are made on an outer component(panel etc) and the table is just updated because the ondrop event in ajax has run and changed the data the drop table will contain. That may be magic for incrementing data...but not for rearranging and updating cell or row data.
SO the answer for that up to primefaces 3.5.x is i dont think you can achieve it...I dont think you can doit with jquery either because they run client side? i havent used them before so i cant tell for sure.
A bit of rework of your forms may be needed.
Based on this Im implementing a rich:autocomplete with a dynamic list to the autocomplete. What i want to do next is, when the user edits this field to update another field based on its value.
I've found various links and references declaring this is a bug, that it triggers when the form in used is submitted, workaraounds but from at least a year ago. here, here and here.
Fragment of my code:
<rich:autocomplete value="#{cotizacionBean.currentOpcionEditable.sumaAsegurada}" style="width:100px;" id="sumaAseguradora"
required="true" validatorMessage="#{msgs['global.etiqueta.sumaAseguradoraRequerida']}"
autocompleteMethod="#{cotizacionBean.getAutocompleteListSumaAsegurada}"
valueChangeListener="#{cotizacionBean.sumaAseguradaModificada}"
requiredMessage="#{msgs['global.etiqueta.sumaAseguradoraRequerida']}" converterMessage="#{msgs['global.etiqueta.sumaAseguradoraRequerida']}">
</rich:autocomplete>
And my bean:
public void sumaAseguradaModificada(){
System.out.println("entro sumaAseguradaModificada");
}
So my questions are two: is this already fix? How can i do it?
Here's how I got that to work:
<a4j:jsFunction name="submitSearch"
execute="sumaAseguradora"
render="sumaAseguradora"
action="#{cotizacionBean.sumaAseguradaModificada}" />
<rich:autocomplete style="width:100px;" id="sumaAseguradora"
required="true" validatorMessage="#{msgs['global.etiqueta.sumaAseguradoraRequerida']}"
autocompleteMethod="#{cotizacionBean.getAutocompleteListSumaAsegurada}"
requiredMessage="#{msgs['global.etiqueta.sumaAseguradoraRequerida']}" converterMessage="#{msgs['global.etiqueta.sumaAseguradoraRequerida']}"
onselectitem="submitSearch()"
value="#{cotizacionBean.currentOpcionEditable.sumaAsegurada}">
</rich:autocomplete>
In the Bean, I had to change the signature of the method:
public Object sumaAseguradaModificada() {
System.out.println("entro sumaAseguradaModificada");
return "success";
}
I am trying to make a input form for answers in my application and I start with four "empty" answers which the view loops over and make input fields for. I have an add answer button which I add one question to the array of answers and then the view render the answers again, but now with an additional input field. The backing bean is viewscoped. However if I submit the form without pressing the add answer button it all works. The data is saved in the database. But if I add an answer after the four is filled out the last one does not get the data from the inputfield (answer.description). If I press the add answer first (without filling out any input fields) the data from the fields are not captured at all leaving all 5 empty so no data is saved in the database.
I have this in the form:
<ui:repeat var="answer" value="#{bean.answers}">
<div class="field">
<h:outputLabel for="answerAlternative-#{answer.serialNumber}"
value="Svaralternativ #{answer.serialNumber}" />
<h:inputText id="answerAlternative-#{answer.serialNumber}"
value="#{answer.description}" size="40" />
</div>
</ui:repeat>
This is the method for creating a new input field:
public String addAnswer() {
if (answers.size() + 1 < 6) {
Answer answer = new Answer();
answer.setSerialNumber(answerSerialNumber + "");
answerSerialNumber++;
answers.add(answer);
}
return null;
}
Used for initializing the answers array with four empty input fields:
#PostConstruct
public void initBean() {
answers = new ArrayList<Answer>();
for (int i = 0; i < 4; i++) {
addAnswer();
}
}
This look to match the current problems of <ui:repeat> in Mojarra. It is totally broken in Mojarra.
You have basically 2 options:
Replace Mojarra by MyFaces which has a way more stable implementation of <ui:repeat>.
Use an UIData component instead of <ui:repeat>, e.g. <h:dataTable>, Tomahawk's <t:dataList>, PrimeFaces' <p:dataList>, etc.