jsp servlet pass variable in table row to servlet without form - database

<table id="searchTable"><%
for (int i=0; i<userList.size();i++){
User user=userList.get(i);%>
<tr>
<td id="leftSearchResult">
<span class="resultUsername">Name: <%=user.getUserName()%></span></br>
</td>
<td>
<!--Button to visit profile here-->
</td>
</tr>
<%}%>
</table>
I have this search user function, and for each result a table row is created with the username of the user. What I want to do is that when you press the visit profile button in the table row it will send the username in that row to the servlet. How do I do that? Also, can you pass variables to servlets without the use of forms? I know how to retrieve data from forms to the servlet with request.getParameter(), but not sure what to do in this situation. (The userList array is an arraylist of User objects retrieved from the database when you perform the search function. Did not include that code portion here.)

Use a link with a request parameter. And learn not to use scriptlets in JSPs. Use the JSP EL and the JSTL instead:
<table id="searchTable">
<c:forEach items="${userList}" var="user">
<tr>
<td id="leftSearchResult">
<span class="resultUsername">
Name: <c:out value="${user.userName}"/>
</span>
</td>
<td>
<a href="<c:url value="/userDetails">
<c:param name="userId" value="${user.id}"/>
</c:url>">Details</a>
</td>
</tr>
</c:forEach>
</table>
The above will generate a link with a URL like /userDetails?userId=1234, and the servlet mapped to /userDetails will then be able to access the user ID using request.getParameter("userId").

Related

Ng-repeat - What is the right syntax to send the user to its dynamic id?

So, in my object index I'm working inside a ng-repeat.
Now, when I click on an object, it should go to its matching id.
How would I do this with Angular?
I got something like this now:
<tr ng-repeat="dossier in dossiers">
<td>
#{{dossier.license_plate}}
</td>
</tr>
Why don't you try ngHref directive
<tr ng-repeat="dossier in dossiers">
<td>
<a ng-href="/dossiers/{{dossier.id}}">#{{dossier.license_plate}}</a>
</td>
<a ng-href="http://www.gravatar.com/avatar/{{hash}}">link1</a>
https://docs.angularjs.org/api/ng/directive/ngHref

how to open row at the same index in ng-repeat , nested ng-repeat

I am new to angularjs and facing an issue with ng-repeat. A list of invoices repeated with ng-repeat, each invoice has List of Payments. I'm trying to get the payments on click of one of the repeated row and then another and so on.
when I open the first one it opens with exact data, when we open other row payments it opens with new payments by replacing the old one. Both payments of the First row payments and second row payments are same.
List of payments has to open with ng-repeat of that particular index. it has to happen for every invoice which is not happening with following
here is my html
<tbody data-ng-repeat="invoice in relatedInvoices>
<tr>
<td class="td-bottom-border">
{{invoice.PayableCurrencyCode}} {{invoice.PayablePaidAmount | number: 2}}<br />
<small>
<a data-ng-click="isOpenPayablePayments[$index] = !isOpenPayablePayments[$index]; togglePayablePayments(invoice.PayableInvoiceId)">Paid</a>
</small>
</td>
</tr>
<tr data-ng-show="isOpenPayablePayments[$index]">
<td>
<table>
<thead>
<tr>
<th>Transaction Id</th>
</tr>
</thead>
<tbody>
<tr data-ng-repeat="payment in payablePayments">
<td>{{payment.TransactionId}}</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
Here is my javascript
var getPayments = function (invoiceId) {
paymentService.getPayments(invoiceId).then(function (paymentsResponse) {
return paymentsResponse.data;
});
};
$scope.togglePayablePayments = function(invoiceId) {
$scope.payablePayments = getPayments(invoiceId);
};
Every time on toggle click payments getting replaced with new payments. My problem is how to maintain the payments of particular index of every click and show at respective index. please help me out
Working Demo
<tbody>
<tr data-ng-repeat="city in name.cities">
<td>{{city.city}}</td>
</tr>
</tbody>
Actually you have to specifies main object name with the cities. name.cities
That's all !!!
Hope this will help you.
Feel free to ask any doubt on this.

Ng-repeat Input Fields

So I'm working on a project where I need to form a grid of text input fields, a la an excel spreadsheet to display values and allow them to be updated.
Using angular, the snippet of html that does this with a regular table structure is:
<table >
<tr>
<th></th>
<th ng-repeat="week in weeks">{{week['weekEndDate']}}</th>
</tr>
<tr ng-repeat="field in fields" id={{field['fieldID']}}>
<td>{{field['displayName']}}</td>
<td ng-repeat="week in weeks" id={{week['weekID']}}>
{{ week[field.name] }}
</td>
</tr>
</table>
Where I have a table: weeks (checking, saving, expense) and fields (fieldID, name). The fields.name column maps directly to the column names in the weeks table.
My thing is, I want these to be type fields with the same table structure.
I tried:
<table >
<tr>
<th></th>
<th ng-repeat="week in weeks">{{week['weekEndDate']}}</th>
</tr>
<tr ng-repeat="field in fields" id={{field['fieldID']}}>
<td>{{field['displayName']}}</td>
<td ng-repeat="week in weeks" id={{week['weekID']}}>
<input ng-model="{{ week[field.name] }}" placeholder="{{ week[field.name] }}">
</td>
</tr>
</table>
But that gave me the error of
Syntax Error: Token '{' invalid key at column 2 of the expression [{{ week[field.name] }}] starting at [{ week[field.name] }}].
And also, I have buttons that allow you to move forward and backwards by one week at a time, which basically does the same query with different date parameters -- and each time a button is hit, it spawns an additional column of input fields rather than 'replacing' the current one.
So I'm wondering what the proper syntax for this type of desired behavior could be, as it is not liking the way I have it set up.
As always, thanks in advance gals and guys.

ngRepeat with Table: Change a cell's display text

I have a list of mails which I want to show in a grid (<table>). Some of these mails have attachments. For their corresponding rows, I would like to show an attachment icon in the attachment column. For rest, it should be empty.
JsFiddle: http://jsfiddle.net/6s4Z5/
My template is as follows:
<table id="resultTable">
<thead>
<tr>
<th ng-repeat="columnId in schema.columnOrder">
<img src="icon_attach.png" ng-if="columnId == 'hasAttachments'">
{{schema.columns[columnId].displayText}}
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="row in results.mails">
<td ng-repeat="columnId in schema.columnOrder">
<img src="icon_attach.png" ng-if="columnId == 'hasAttachments' && row.hasAttachments">
<span ng-if="columnId != 'hasAttachments'" >{{ row[columnId] }}</span>
</td>
</tr>
</tbody>
</table>
where schema.columnOrder is an array of columnIds to be shown in the table.
This template is working but is this the best way to implement this? Moreover, I have to add an extra <span> for ng-if statement. Can that also be removed?
You pretty much can change it to something like:
<span ng-if='your check'><img src=''/>{{row[columnId}}</span>
You could set (in the controller) the value of the column hasAttachments to be the image you want to display there.

ICEfaces: How to pass parameters from one page to another

I have this simple scenario which doesn't work: I use icefaces and i have a simple page with some inputTexts and a submit button, this button will redirect to another page that will display the values of these inputTexts... my question is how can i get the values of these inputTexts from the request and display them in another page?
When i use the following API in the other page backbean, i get only the name of the page that holds the inputTexts:
FacesContext.getCurrentInstance().getExternalContext().getRequestMap();
I really did spent alot of time trying to get this thing to work, so any help will be appreciated.. THx
my page code is:
<ice:form id="form1">
<table border="0">
<tbody>
<tr>
<td><ice:outputText value="Name"></ice:outputText><br></br></td>
<td><ice:inputText id="name" value="#{newContest.name}"></ice:inputText></td>
</tr>
<tr>
<td><ice:outputText value="End Date"></ice:outputText></td>
<td><ice:inputText id="endDate" value="#{newContest.endDate}"></ice:inputText></td>
</tr>
<tr>
<td><ice:outputText value="private? (only you can see the entries)"></ice:outputText></td>
<td><ice:inputText id="private" value="#{newContest.isPublic}"></ice:inputText></td>
</tr>
<tr>
<td><ice:outputText value="Price"></ice:outputText></td>
<td><ice:inputText id="price" value="#{newContest.price}"></ice:inputText></td>
</tr>
<tr>
<td><ice:outputText value="Description"></ice:outputText></td>
<td><ice:inputTextarea id="description" value="#{newContest.description}"></ice:inputTextarea></td>
</tr>
<tr>
<td><br></br><ice:commandButton value="proceed to payment" style="color:blue" action="#{newContest.createContest}"></ice:commandButton></td>
</tr>
</tbody>
</table>
You can bind another bean with current one as a managed property in faces-config.xml as follows.
<managed-bean>
<managed-bean-name>newContest</managed-bean-name>
<managed-bean-class>com.newContest</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
<managed-property>
<property-name>anotherBackingBean</property-name>
<property-class>com.AnotherBackingBean</property-class>
<value>#{anotherBackingBean}</value>
</managed-property>
</managed-bean>
<navigation-rule>
<navigation-case>
<from-outcome>view-anotherBackingBean</from-outcome>
<to-view-id>/jsp/another-page.jspx</to-view-id>
</navigation-case>
</navigation-rule>
Bean Content
Class NewContest {
public AnotherBackingBean anotherBackingBean;
//-- set/get & other methods
public String redirectToAnotherBackingBean(){
anotherBackingBean.setSomeObject(object);
//-- set custom fields
return "view-anotherBackingBean";
}
}
Then you can get your fields directly available in other bean which have been set in current bean.

Resources