How to add links in wickets - wicket

In java class i need to add list (E.g. list.getFirstName()) to the Label in wicket and that first name shoulb be a hyper link in the html. Below i have code of java and html
the html code
<tr >
<a wicket:id="gotoClass">
<span wicket:id="firstname"></span>
</a>
</tr>
the java class
Iterator<String> brds = list.iterator();
RepeatingView repeating = new RepeatingView("repeating");
add(repeating);
while (brds.hasNext())
{
AbstractItem item = new AbstractItem(repeating.newChildId());
repeating.add(item);
String contact = brds.next();
item.add(new Label("firstname", contact));
}
The above code works for me and i am able to add the label i.e if i have 10 first names in the list i am able to add 10 labels in html.But i try to add the anchor tag in html and
form.add(new BookmarkablePageLink<String>("firstname", gotoClass.class)); in java
then i get the below exception
Last cause: Unable to find component with id 'firstname' in [ [Component id = formname]]
Expected: 'formname.firstname'.
Found with similar names: ''
can anybody help me on this
Regards
Sharath

The link element must be son of the repeating element (as you did firstly). For example:
//...
BookmarkablePageLink<String> link = new BookmarkablePageLink<String>("firstname", gotoClass.class);
item.add(link);
link.add(new Label("firstname", contact));

Related

How to select specific data in dynamic table using protractor?

I am trying to automate some scenarios using protractor where we need to verify whether the data is updating in dynamic table.
Please find below
HTML Code:
enter image description here
Table in page:
enter image description here
It can be done by verifying that element is present in the DOM with the added Group ID or Group Name.
For Group ID:
element(by.xpath("*//table//tbody//tr//td[1]//p[text()='Amanda Test
Group']")).isDisplayed()
For Group name:
element(by.xpath("*//table//tbody//tr//td[2]//p[text()='Amanda
Group']")).isDisplayed()
I'm assuming you're using Angular2+, yes?
In your HTML Template, you are probably using an *ngFor directive to populate the table dynamically. Add an index to the *ngFor (it's best practices for updating the DOM) in order to add a dynamic id to each element:
<tr *ngFor="let user of user; index as u" id="user-{{u + 1}}">
<td id="userName-{{u + 1}}">
{{user.firstName}} {{user.userName}}<br />
{{user.userName}}
</td>
<td id="userRoles-{{ u + 1 }}">
<span id="role-{{u + 1}}-{{ r + 1 }}" *ngFor="let role of user.roles; index as r">
{{ role.toUpperCase() + ', '}}
</span>
</td>
<!- Omitted code -->
</tr>
In your Page Object:
// Get first user on the table
get firstUser() {
return element(by.id('user-1');
}
// Get a specific user by id
public getUser(index: number) {
return element(by.id(`user-${index}`);
}
// Get all of the attributes for a single user by id
get userAttributes(index: number) {
return element.all(by.id(`user-${index}`);
}
I am not a fan of xpath selectors. Yes, they are faster. But in code that is dynamic or changes frequently, they are the most fragile of selectors. There is no reason your dynamic data cannot have a dynamic ID that clearly identifies each portion of the code you need.
Good luck!

JAX-RS, #FormParam display result in the same page

I have this program that I am coding, the main thing is mostly to get familiar with Jax-rs and rest API. I am sending from a form in JSP page one input and with POST I pass it to my java Response class(that I use annotation #FormParam), it does what calculation I need and then I get the result in another link, what can i do to take the result just below my button on the same page? For my button function I use javascript, and when I push it I don't want to be redirected and take the result like this.
So i use this form and a javascript function in my jsp to pass the value in my POST method in java throw #FormParam
<form name="Form1" method="post">
<p>
Name : <input type="text" name="malename" id="malename" autofocus
value="enter your name..." />
</p>
<input type="submit" name="action" id="malename" value="I'm feeling lucky"
onclick="OnButton1();"> </form>
function OnButton1() {
document.Form1.action = "webapi/perfectmatcher/mate"
document.Form1.target = "_self"; // Open in a new window
document.Form1.submit(); // Submit the page
//return;
}
Here after i have the value i use two other classes to do the calculations and return the result i need. In a few words i pass a value in my form and when i push the button i am redirected in another link(the path of POST) and i display the result. I want to display the result below my button. I hope the code is helpful and i hope i am clear with my explanation
#POST
#Path("/mate")
#Produces(MediaType.TEXT_PLAIN)
public Response postMaleName(#FormParam("malename") String malename) {
String femalename = NumMatcher.numMatcher(Numberizer.numberizer(malename));
// FemaleName female = new FemaleName(femalename);
female.setName(femalename);
System.out.println(female.getName());
return Response.status(200).entity("Perfect Match for " + malename + " is " + femalename).build();
}
P.S.:The object female that i am trying to create its for testing purposes, i was trying somehow to get the information that i store but i cannot find how!!I used even jsp expressions but i get null value of course ...
<%
FemaleName female = new FemaleName("john");
String string = female.getName();
out.print(string);
%>

Using Meteor what is the JS equivelent of {{{member}}}

I have a meteor helper that uses a reactive variable in a find to get a unique document using an id. My item button template looks like this:
<template name = "itemButton" >
<div class = "itemButton" name = {{_id}}>
{{{title}}}
</div>
</template>
using a reactive variable:
Template.landing.onCreated(function _OnCreated() {
this.f = new ReactiveVar();
this.f.set(false);
const handle = Meteor.subscribe("Feed");
});
now I have a method in a template several itemButton.
Template.landing.events({
'click .itemButton' : function(event, template){
alert(event.target.name);
template.f.set(event.target.name);
}
});
and I would like to use that name in a helper that would use this value as the _id.
Template.landing.helpers({
"GetFocus": function(){
alert(Template.instance().f.get()); // alerts undefined...
return(items.find({'_id':Template.instance().f.get()}));
}
});
So where I expect GetFocus to give me the document that generated the button I don't seem to be so lucky. Let me know if I can provide any additional clarification, and as always your input is appreciated.
Where I have template.f.set(event.target.name); I needed template.f.set(event.currentTarget.getAttribute('data-id')); where the html uses data-id instead of name.

Mootools: get text from clicked link's sibling table node

here's the situation:
| ID | Name | ...
+----+--------+---
| 12 | Henry | ... a whole list of names, ids,&c ...you get the idea
+----+--------+---
| 13 | Julia | ...
+-------------+---
...
all the names are links. when selected, they load the rest of the table for editing by passing the name into a quick mysql query. but since i'm getting dupes, i need to grab the id as well to pass along. i also need it for updating the corrected (and correct!) record.
so, using MooTools, how do i grab the text from the neighbouring sibling when i click the link? hell, even just plain ol' JS will do.
here's the existing function:
function loadRecord(aName) {
console.log("loadRecord called with: "+aName);
user = $('submitterName').value;
id = $('table-id').text; // THIS IS THE PROBLEM RIGHT HERE. >_<
console.log('with user: '+user);
$('recordName').value = aName;
$('addRecordButton').value = 'Update Record';
$('addRecordData').action='_php/updateRecord.php'; // this isn't working either...
var action=$('addRecordData').action;
console.log(action);
checkUserDB(aName,user,id);
}
since there are multiple rows to the table, i can't assign a unique identifier to each ID to any benefit. i'm still stuck trying to pull the table-id's text that relates to the clicked link.
i hope i am clear. any help or illumination would be much appreciated.
TIA crew!
WR!
Here is the solution
HTML
<!--Change your HTML-->
<table>
<tr>
<th>ID</th>
<th>Name</th>
</tr>
<tr>
<td>12</td>
<td><a>Henry</a></td>
</tr>
<tr>
<td>13</td>
<td><a>Julia</a></td>
</tr>
</table>
MooTools
window.addEvent('load', function(){
window.addEvent('click:relay(a)', function(event){//Add your selector inside relay
event.preventDefault();
console.log($(this).getParent('td').getPrevious().get('html'));
//Add Your AJAX code here
});
});
Here you are attaching a click event to anchor then selecting
parent(http://mootools.net/core/docs/1.5.2/Element/Element#Element:getParent)
then as you have ID in previous
element(http://mootools.net/core/docs/1.5.2/Element/Element#Element:getPrevious)
you can grab the previous element and get it's HTML
You can check the pen here http://codepen.io/arifmahmudrana/pen/yYQeJX

How to create a html select in code behind c#?

We need to create html dropdown list dynamically. Following is our current code. Option1 and Option2 are strings that include all the items. The reason we have two strings is we split all the items in two groups.
<td>
<div id="dvGroup" style="display:none;" runat="server"></div>
</td>
string Option1 = "<optgroup label='Group1'><option>1</option><option1>2</option>";
string Option2 = "<optgroup label='Group2'><option>a</option><option>b</option><option>c</option>;
…
dvGroup.InnerHtml = "<Select name='ddGroup' id='ddGroup'>" + Option1 + Option2 + "</Select>";
But by setting InnerHtml will potentially bring some security problem. So I changed it to:
HtmlSelect select = new HtmlSelect();
select.ID = "ddGroup";
select.Name = "ddGroup";
select.ClientIDMode = ClientIDMode.Static;
dvGroup.Controls.Add(select);
select.Controls.Add(new LiteralControl(Option1 + Option2));
However, it threw following error at the line select.Controls.Add…
'System.Web.UI.HtmlControls.HtmlSelect' does not allow child controls.
How do I fix this? Another problem is, setting ClientIDMode to Static only make sure the id is not changed, but name still being added extra stuff. How do I make sure name is not changed either?
You can do this way:
HtmlSelect mHtmlSelect = new HtmlSelect();
mHtmlSelect.ID = "ddGroup";
mHtmlSelect.Name = "ddGroup";
mHtmlSelect.ClientIDMode = ClientIDMode.Static;
String Option1 = "Hello";
String Option2 = "World";
mHtmlSelect.Items.Add(new ListItem(Option1 + Option2));
this.Controls.Add(mHtmlSelect);
Output:
<select name="ddGroup" id="ddGroup">
<option value="HelloWorld">HelloWorld</option>
</select>