I am using a FileDownload control to show a list of attachments from a Notes document.
The dates are shown as: dd/MM/yy hh.mm - and since my users are Danish I would like to show the dates in the format: dd-MM-yyyy hh:mm.
That is pretty simple if you use a SimpleDateFormater. In SSJS that would look like:
var date:Date = new Date(aFile.getCreated());
if(date==null) return date;
return new java.text.SimpleDateFormat("dd-MM-yy hh:mm").format(date);
In the FileDownload control you can compute the value of "createdValue" property. However, the control expects an object of type "Date" which does not allow for the formating in the above example (it just throws an Error 500).
Any suggestions?
/John
You already found that the createdValue property expects a java.util.Date object, so the only way to change how that is formatted is by changing the browser locale used by the XPage (as answered here). Using the standard download control you can get a handle on every file by adding the var="file" attribute to it and use that in the createdValue property:
createdValue="new Date(file.getCreated());"
If you want to have more control on the list of files you could use a repeat control and bind it to the list of files from a RichText item:
<xp:repeat id="repeat1" rows="30" var="file" disableOutputTag="true">
<xp:this.value><![CDATA[#{javascript:document1.getAttachmentList("files")}]]></xp:this.value>
<xp:this.facets>
<xp:text escape="false" disableTheme="true" xp:key="header">
<xp:this.value><![CDATA[<table><tbody>]]>
</xp:this.value></xp:text>
<xp:text escape="false" disableTheme="true" xp:key="footer"><xp:this.value><![CDATA[</tbody></table>]]></xp:this.value></xp:text>
</xp:this.facets>
<tr>
<td>
<xp:text escape="true" id="computedField1" value="#{file.name}"></xp:text>
</td>
<td>
<xp:text escape="true" id="computedField2">
<xp:this.value><![CDATA[#{javascript:var date:Date = new Date(file.getCreated());
return new java.text.SimpleDateFormat("dd-MM-yy hh:mm").format(date);}]]></xp:this.value>
</xp:text>
</td>
</tr>
</xp:repeat>
By the way: another a disadvantage of the default download control is that it adds a content-disposition header to every link, so the browsers always asks you if you want to save or open the file instead of opening images (for instance) directly.
Related
I have a repeat control which displays a list of Attachments, which are saved as response documents to the current document. Right now I just see all the main docs and response docs in a list. How do I 1) Filter the view to only to include the response docs and not main docs? 2) Filter the view to only include responses to the current document?
I tried using the Filter by column value on the datasource, but I can't figure it out.
My Xpage datasources are "document1" document and "Requirements" view
<xp:dominoView var="Atts" viewName="Requirements">
</xp:dominoView>
<xp:repeat id="AttsContainer" rows="100"
var="Attachments" repeatControls="true" value="#{Atts}">
<xp:panel id="AttsPanel">
<xp:table style="width:100.0%;border-width:thin;border-color:rgb(0,0,0);border-style:solid">
<xp:tr>
<xp:td style="width:234.0px">
<xp:text escape="true"
id="computedField1" value="#{Attachments.AttName}">
</xp:text>
</xp:td>
<xp:td><xp:text escape="true" id="computedField2">
<xp:this.value><![CDATA[#{javascript:var doc:NotesDocument = Attachments.getDocument();
var sUNID = doc.getUniversalID();
sUNID}]]></xp:this.value>
</xp:text></xp:td>
<xp:td>
<xp:link escape="true"
id="link2">
<xp:this.text><![CDATA[#{javascript:Attachments.getColumnValue("Files")}]]></xp:this.text>
<xp:this.value><![CDATA[#{javascript:var doc:NotesDocument = Attachments.getDocument();
var sUNID = doc.getUniversalID();
ATT = Attachments.getColumnValue("Files");
"/bid.nsf/0/" + sUNID + "/$FILE/" + ATT}]]></xp:this.value></xp:link></xp:td>
</xp:tr>
</xp:table></xp:panel>
From the top of my head:
Create a view showing only the documents created with the response's form.
Disable the "show response documents in a hierarchy" property
Add a categorized first column with this formula: #Text($ref)
That gives you a view where all responses are categorized by their parents unid. You use that view in the data source and set the categoryFilter the the unid of the main document.
im using spring mvc framework with thymeleaf template engine
the problem is , i have 1 page with multiple check box iterated sing thymeleaf th:each iterator.When i clicked multiple check boxes i want to pass check box values to the controller method..
html content
<table>
<tr th:each="q : ${questions}">
<h3 th:text="${q.questionPattern.questionPattern}"></h3>
<div>
<p >
<input type="checkbox" class="ads_Checkbox" th:text="${q.questionName}" th:value="${q.id}" name="id"/>
</p>
</div>
</tr>
</table>
*Controller*
#RequestMapping(value = Array("/saveAssessment"), params = Array({ "save" }))
def save(#RequestParam set: String, id:Long): String = {
var userAccount: UserAccount = secService.getLoggedUserAccount
println(userAccount)
var questionSetQuestion:QuestionSetQuestion=new QuestionSetQuestion
var questionSet: QuestionSet = new QuestionSet
questionSet.setUser(userAccount)
questionSet.setSetName(set)
questionSet.setCreatedDate(new java.sql.Date(new java.util.Date().getTime))
questionSetService.addQuestionSet(questionSet)
var list2: List[Question] = questionService.findAllQuestion
var limit=list2.size
var qustn:Question=null
var a = 1;
for( a <- 1 to limit ){
println( a );
qustn= questionService.findQuestionById(a)
questionSetQuestion.setQuestion(qustn)
questionSetQuestion.setQuestionSet(questionSet)
questionSetQuestion.setCreatedDate(new java.sql.Date(new java.util.Date().getTime))
questionSetQuestionService.addQuestionSetQuestion(questionSetQuestion) } "redirect:/teacher/Assessment.html" }
I think you pretty much have it. With a checkbox, you can only send one piece of information back with the form...that being the value. So if you are trying to determine which checkboxes are checked when the user clicks the submit button, then I would have the checkboxes all use one name...like "id" (exactly like you have). Value is the actual id of the question (again like you have). Once submitted, "id" will be a String array which includes all the values of the checkboxes that were checked.
So your controller method needs to take param called "ids" mapped to parameter "id" which is a string[]. Now for each id, you can call questionService.findQuestionById.
(I'm not a Groovy guru so no code example sry :)
I have used JSTL with JSP and thymeleaf was something new. I read the THYMELEAF documentation.
There is a section which explains multi valued check boxes.
<input type="checkbox"
class="ads_Checkbox"
th:text="${q.questionName}"
th:value="${q.id}" name="id"/>
In the above code we are not binding the value to the field of the command object. Instead try doing this
<input type="checkbox"
class="ads_Checkbox"
th:text="${q.questionName}"
th:field="*{selectedQuestions}"
th:value="${q.id}" />
here the selectedQuestions is an array object present in the spring command object.
I have a setup where a user can enter a zip code into an ASP.NET TextBox control, and I have an AutoCompleteExtender from the Ajax Control Toolkit attached to that textbox. It gets its data from a static page method on the ASPX page.
When the user starts typing a Swiss zip code, e.g. 3 and then waits a brief moment, a list of matching zip code shows up - something like:
3000 - Bern
3001 - Bern
and so on. Works like a charm.
The normal way to pick one of the options shown is to move your mouse pointer to the list and select the one you want, click on it or press Enter, and get the zip code into that textbox (and the city name into a second textbox next to it).
Now, I got some additional requirements from my project manager:
we would like to be able to just press Enter without going into the list of choices to select one - he'd like to just get the first (or often times: only) entry shown put into those two textboxes...
we would like to be able to enter a valid 4-digit zip code and then just press Tab and move out of the textbox for the zipcode, and have the first (possibly only) entry with that zipcode be chosen and "selected" (and stuffed into the two textboxes).
Seems like a tall order to me (I'm not a great Javascript guru at all.....) - any ideas?
This is my ASP.NET page (in a standard ASP.NET 4.0 webforms sample app - with a master page; the script is simplified; in reality, I'm splitting up the text 3001 - Bern at the dash and stick the first part into the zip code and the second part into the city textbox):
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<script type="text/javascript">
function IAmSelected(source, eventArgs) {
$get('tbxCity').value = eventArgs.get_value();
}
</script>
<asp:ScriptManager runat="server" EnablePageMethods="True" />
<asp:Literal runat="server" ID="litPrompt" Text="Please enter zip code: " />
<asp:TextBox runat="server" ID="tbxZipcode" MaxLength="10" />
<act:AutoCompleteExtender runat="server" ID="acZipCode" TargetControlID="tbxZipcode" MinimumPrefixLength="1"
CompletionInterval="25" ServiceMethod="GetMatchingZipCodes" CompletionSetCount="15"
OnClientItemSelected="IAmSelected" />
<asp:TextBox runat="server" ID="tbxCity" MaxLength="50" />
</asp:Content>
and my code-behind (this, too, is simplified - of course, in reality, I get this data from a Entity Framework data model):
[WebMethod]
[ScriptMethod]
public static string[] GetMatchingZipCodes(string prefixText, int count)
{
return new string[] { "3000 - Bern", "3001 - Bern", "4000 - Basel", "6000 - Lucerne", "6001 - Lucerne" };
}
Check the FirstRowSelected property of AutoCompleteExtender. From your requirements seems like it's exactly what you need.
I have an odd problem whereby the model in my vbhtml file will correctly reference and bring up the model's attributes for 1 item but not for another.
FYI, The page is added as a partial page, connected to another vbhtml page.
My page is structured such that I want to list a number of people (beneficiaries), below each question (question text).
I am referencing my Model type using the syntax: #ModelType RHEAL_START.QuestionWithAnswers, so this should automatically allow the model items to be declared when instantiated.
The #ModelType declaration correctly allows the referencing of the 2nd model field (Model.benAnswers) but not the first one I have declared (Model.questionText).
Both items are part of the same model and, I have tried moving the declarations above and below the and headers but, this did not bring up an IntelliSense for the Model.questionText.
I looked at the following post and tried addding in a reference to the Layout file but alas, this did not bring up an IntelliSense either.
MVC3 - render view that is not a method in a controller
See the code below. Can anyone suggest where I'm going wrong and what else I can try?
If you need more information, please let me know.
#ModelType RHEAL_START.QuestionWithAnswers
#Code
Layout = "~/Views/MedicalQuestions/MedicalQuestions.vbhtml"
End Code
<div id="questionPanel">
#Code
Dim qAndARef As Integer = 0
End Code
<!-- Show question text and number -->
<h1>Model.questionText</h1>
<table>
<tr>
<td style="font-weight: bold">
Beneficiary </td>
<td style="font-weight: bold">
Yes/No </td>
<td style="font-weight: bold">
Details </td>
</tr>
<!-- !!Iterating over each beneficiary for Medical Question -->
#For Each benanswer As RHEAL_START.BeneficiaryAnswer In Model.benAnswers
Html.Partial("../MedicalQuestions/BeneficiaryAnswerPartial", benanswer)
Next
</table>
#*#Html.ValidationSummary()*#
</div>
#Section Scripts
#Scripts.Render("~/Scripts/RHEAL/YesNoDropDownValidation.js")
End Section
I'm not that familiar with the VB syntax for Razor, but it looks like you're missing a # sign in front of #Model.questionText
All -
I'm using stripes to do some form input for a problem I'm working on and I'm stuck on how best to submit a a pair of data using stripes and checkboxes.. for example my page looks like the following:
I have a list of options where users can enable a selection by clicking the box, and also supply some input for that item by entering data into the text field next to it:
<tr>
<td><stripes:checkbox name="item.enable" value="${item.id}"/></td>
<td><stripes:text name="item.value" value="${item.value}"/></td>
</tr>
.....
next item...
When the form is submitted I'd expect my Collection<Item> to be populated yet that's not the case..
How can I best submit a pair of items using the check box fields.
Thanks in advance.
..Chris
Read the documentation on indexed properties. You need to tell Stripes that you have multiple items, by naming them items[0], items[1], etc.:
<tr>
<td><stripes:checkbox name="items[0].enable" value="${item.id}"/></td>
<td><stripes:text name="items[0].value" value="${item.value}"/></td>
</tr>
<tr>
<td><stripes:checkbox name="items[1].enable" value="${item.id}"/></td>
<td><stripes:text name="items[1].value" value="${item.value}"/></td>
</tr>
This supposes that you action bean has a setItems(List<Item> items) method, that the Item class has a public no-arg constructor, and has a setEnable(String itemId) and a setValue(String value) method.
I would wrap this in a JSTL 'forEach' tag and I would put the items in a List. Similar to what JB Nizet said, you also need public setters in the action bean. If you are using Collection<Item> with some implementation other than List<Item> the below snippet won't work.
<c:forEach var='itemIndex' begin='0' end='2'>
<c:set scope='page' var='item' value='${items[itemIndex]}'>
<tr>
<td><stripes:checkbox name="items[${itemIndex}].enable" value="${item.id}"/></td>
<td><stripes:text name="items[${itemIndex}].value" value="${item.value}"/></td>
</tr>
</c:forEach>
There is another case when you don't want the list to default to 3 items. The one I'm thinking of is when the list is already populated. If that is the case I would change the 'end' attribute of the <c:forEach> to be: ${fn:length(actionBean.items) == 0 ? 3 : fn:length(actionBean.items)-1}