I need to add links to my resteasy api xml and json output.
So I wrote a JAXB AtomLink class as follows
package samples;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
#XmlRootElement(name="link", namespace="http://www.w3.org/2005/Atom")
public class AtomLink {
private String rel;
private String href;
private String type;
public AtomLink() {}
public AtomLink(String rel, String href, String type) {
this.rel = rel;
this.href = href;
this.type = type;
}
public AtomLink(String rel, String href) {
this(rel,href,"application/xml");
}
#XmlAttribute
public String getRel() {
return rel;
}
public void setRel(String rel) {
this.rel = rel;
}
#XmlAttribute
public String getHref() {
return href;
}
public void setHref(String href) {
this.href = href;
}
#XmlAttribute
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
and set the link values in my JAXB xml or json object.
I got the output as follows. But the links are not clickable.
output:
<data xmlns:ns2="http://www.w3.org/2005/Atom">
<bucket id="2" name="2012-APR-09 12:05 AM">
<av_data unit="percent" value="100"/>
<data_count unit="#" value="10"/>
<pf_data unit="seconds" value="4.618"/>
</bucket>
<ns2:link href="http://localhost:8080/webapp/api/getrawdata?start=3&size=2" rel="next" type="application/xml"/>
</data>
What should i do to make the links clickable.
Thanks in advance.
Anitha
XML and JSON are just text based representations of data. The ability to click on a link depends upon the browser you are using to view the data ability to recognize a portion of that text as a link and render it as a hyperlink.
Related
I want to create a keyword search referring to "UserName__c" api on Salesforce Apex class.
compile error Unexpected token 'UserName__c'.
public with sharing class AccountListCon {
static List<String> TARGET_FIELDS = new List<String>{
'Name'
,'UserName__c'
,'CompanyName__c'
};
public SearchCondition condition{ get;set; }
public String UserName__c results { get;set; }
public String sortingField { get;set; }
public void init(){
this.condition = new SearchCondition();
this.results = new String UserName__c();
}
public PageReference clear(){
init();
return null;
}
There is no such type String UserName__c. It's not entirely clear what you want to do here, but I suspect you intend just to declare a String variable. The fact that you're looking for values in some field whose API name is UserName__c is not relevant to the type system
public String UserName__c results { get;set; } is wrong. Is this supposed to be just
public String results { get;set; } ?
I have created a project in .net CF 3.5 another project creates an XML files which I will be using in CF project which is in Winform.I am using VS2012.
While deserializing the XML I am getting invalid operation exception.
The class which does the deserialization is a simple one
class DeserOp
{
byte[] contentBytes = Properties.Resources.test; //The test is xml file I put in resources for simplicity
XmlSerializer serializer = new XmlSerializer(typeof(Vision));
MemoryStream stream = new MemoryStream(contentBytes);
Vision myClass = (Vision)serializer.Deserialize(stream);
}
Class Vision will be :
public class Vision
{
[XmlArrayItem(Type = typeof(Mercedes)),
XmlArrayItem(Type = typeof(BMW))]
public List<Cars> ItemArray { get; set; }
public Vision() { ItemArray = new List<Cars>(); }
}
Class Cars will be:
public class Cars
{
string _name;
public string Name
{
get { return _name; }
set
{
if (_name != value)
{
_name = value;
}
}
}
public string _type;
public string Type
{
get { return _type; }
set
{
if (_type != value)
{
_type = value;
}
}
}
}
Class Mercedes/BMW will be:
public class Mercedes : Cars
{
string _make;
public string Make
{
get { return _make; }
set
{
if (_make != value)
{
_make = value;
}
}
}
}
The XML test will be:
The XML will be look alike:
<?xml version="1.0" encoding="utf-8"?>
<Vision xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ItemArray>
<Mercedes>
<Name>ABC</Name>
<Type>Luxery</Type>
<Make>Cclass</Make>
</Mercedes>
<BMW>
<Name>BDD</Name>
<Type>Sedan</Type>
<Make>Perfect</Make>
</BMW>
</ItemArray>
</Vision>
I tried all possible attributes also like [XmlIncludeAttribute(typeof(Mercedes))] on a class Car but still it is throwing error.
Also all the elements are public and the file also has public access.
I'm trying to use #Consumed on jpa entity with camel.
this is my route :
<route id="incomingFileHandlerRoute">
<from
uri="jpa://com.menora.inbal.incomingFileHandler.Jpa.model.MessageToDB?consumer.nativeQuery=select
* from file_message where mstatus = 'TODO'&consumer.delay=5000&consumeDelete=false&consumeLockEntity=true&consumer.SkipLockedEntity=true" />
<to uri="bean:incomingFileHandler" />
</route>
and my entity:
#Entity
#Table(name = "file_message")
public class MessageToDB implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
#Id
private String uuid;
private String fileName;
private String body;
private String mstatus;
#Temporal(TemporalType.TIMESTAMP)
private Date mtimestamp;
#Consumed
public void updateMstatus() {
setMstatus(MessageStatus.DONE.name());
}
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public String getBody() {
return body;
}
public void setBody(String body) {
this.body = body;
}
public String getMstatus() {
return mstatus;
}
public void setMstatus(String mstatus) {
this.mstatus = mstatus;
}
public Date getMtimestamp() {
return mtimestamp;
}
public void setMtimestamp(Date mtimestamp) {
this.mtimestamp = mtimestamp;
}
}
I do get to incomingFileHandler bean with results from db but I do not get to the Consumed method updateMstatus . The incomingFileHandler bean is getting called continuously as always there are results from db
I have a similar implementation with camel-jpa and annotations #Consumed and #PreConsumed in the entity but none of these methods is called.
I look the camel-jpa source code and found this in JpaConsumer.java:
protected DeleteHandler<Object> createPreDeleteHandler() {
// Look for #PreConsumed to allow custom callback before the Entity has been consumed
final Class<?> entityType = getEndpoint().getEntityType();
if (entityType != null) {
// Inspect the method(s) annotated with #PreConsumed
if entityType is null the entity class inst inspect the method annotated with #Consumed and #PreConsumed.
Solution: add entityType=com.xx.yy.MessageToDB to your URI to set Endpoint Entity type.
I have an HTML page and created the page objects of that page. This page contains a dynamic html table. I'm unable to use it as page objects as it is dynamically created. I want to use any row and column of the page in my test cases.
Page Object class:
public final class AgentsPage
{
#FindBy(how=How.XPATH, using="//table[#id='gwt-debug-com.seamless.ers.client.agentPortal.client.view.screens.SubAgentsReportScreen']//input[#id='gwt-debug-Phone_Number']")
public WebElement phoneNumber;
public String getTextOfPhoneNumber()
{
return phoneNumber.getAttribute("value");
}
public void setTextForPhoneNumber(String value)
{
phoneNumber.clear();
phoneNumber.sendKeys(value);
}
#FindBy(how=How.XPATH, using="//table[#id='gwt-debug-com.seamless.ers.client.agentPortal.client.view.screens.SubAgentsReportScreen']//input[#id='gwt-debug-Name']")
public WebElement name;
public String getTextOfName()
{
return name.getAttribute("value");
}
public void setTextForName(String value)
{
name.clear();
name.sendKeys(value);
}
#FindBy(how=How.XPATH, using="//table[#id='gwt-debug-com.seamless.ers.client.agentPortal.client.view.screens.SubAgentsReportScreen']//input[#id='gwt-debug-Reseller_ID']")
public WebElement resellerId;
public String getTextOfResellerId()
{
return resellerId.getAttribute("value");
}
public void setTextForResellerId(String value)
{
resellerId.clear();
resellerId.sendKeys(value);
}
#FindBy(how=How.XPATH, using="//table[#id='gwt-debug-com.seamless.ers.client.agentPortal.client.view.screens.SubAgentsReportScreen']//input[#id='gwt-debug-Terminal_Serial']")
public WebElement terminalSerial;
public String getTextOfTermialSerial()
{
return terminalSerial.getAttribute("value");
}
public void setTextForTerminalSerial(String value)
{
terminalSerial.clear();
terminalSerial.sendKeys(value);
}
#FindBy(how=How.XPATH, using="//table[#id='gwt-debug-com.seamless.ers.client.agentPortal.client.view.screens.SubAgentsReportScreen']//select[#id='gwt-debug-Rows_Per_Page']")
public WebElement rowsPerPage;
public String getSelectedValueOfRowsPerPage()
{
Select select=new Select(rowsPerPage);
return select.getFirstSelectedOption().getText();
}
public void setValueForRowsPerPage(String visibleText)
{
if(!(visibleText.equals("")||visibleText==null))
{
Select select=new Select(rowsPerPage);
select.selectByVisibleText(visibleText);
}
}
public void setValueForRowsPerPage(int index) throws Exception
{
Select select=new Select(resellerId);
select.selectByIndex(index);
}
#FindBy(how=How.XPATH, using="//table[#id='gwt-debug-com.seamless.ers.client.agentPortal.client.view.screens.SubAgentsReportScreen']//button[#id='gwt-debug-submit_button']")
public WebElement submit;
public String getTextOfSubmit()
{
return submit.getText();
}
#FindBy(how=How.XPATH, using="//table[#id='gwt-debug-com.seamless.ers.client.agentPortal.client.view.screens.SubAgentsReportScreen']//button[#id='gwt-debug-clear_button']")
public WebElement reset;
public String getTextOfReset()
{
return reset.getText();
}
#FindBy(how=How.XPATH, using="//table[#id='gwt-debug-com.seamless.ers.client.agentPortal.client.view.screens.SubAgentsReportScreen']//button[#id='gwt-debug-nextPage']")
public WebElement next;
public String getTextOfNext()
{
return next.getText();
}
#FindBy(how=How.XPATH, using="//table[#id='gwt-debug-com.seamless.ers.client.agentPortal.client.view.screens.SubAgentsReportScreen']//button[#id='gwt-debug-prevPage']")
public WebElement previous;
public String getTextOfPrevious()
{
return previous.getText();
}
#FindBy(how=How.XPATH, using="//table[#id='gwt-debug-com.seamless.ers.client.agentPortal.client.view.screens.SubAgentsReportScreen']//button[#id='gwt-debug-lastPage']")
public WebElement last;
public String getTextOfLast()
{
return last.getText();
}
#FindBy(how=How.XPATH, using="//table[#id='gwt-debug-com.seamless.ers.client.agentPortal.client.view.screens.SubAgentsReportScreen']//button[#id='gwt-debug-firstPage']")
public WebElement first;
public String getTextOfFirst()
{
return first.getText();
}
#FindBy(how=How.XPATH, using="//table[#id='gwt-debug- com.seamless.ers.client.agentPortal.client.view.screens.SubAgentsReportScreen']//div[contains(text(),'Page:') and contains(text(),'/')]")
public WebElement pageCount;
public String getTextOfPageCount()
{
return pageCount.getText();
}
//Need page objects for the dynamic html table
}
![Page Image][1]: http://i.stack.imgur.com/o94F0.png
I don't want to use any xpath or any loops for iterating through rows of the table in my test cases. I just want to use it like any other static page object elements like AgentsPage.submit button. How can this be achieved?
Well without xPath you won't even locate needed elements of the table (well you may use CssSelectors but it's the same).
Do do it right I suggest you to create a list of web elements that will include table rows (<tr> tags). This list should be initialized by #FindBy attribute.
Then I suppose it's good idea to create "get" methods for your data.
For example:
public String getName(int row, int cell)
{
return theTable[row].findElement(By.xpath(".//td[" + cell + "]")).getText();
}
Store the webelements like row number, phone number, name, etc etc in a list of its own. You can easily get the data as string using streams.
#FindBy(xpath="xpath to the row number")
private List<WebElement> rowNum;
#FindBy(xpath="xpath to the phone number")
private List<WebElement> phoneNum;
Similarly for other two. The data will be in order as found on the page. You can easily access data using index on the list.
How do I obtain values of an array that is located inside a java object in a jsp page?
I have set an object attribute so that in the jsp page I can call the object like so
${obj.property}
My question is how would I obtain property String [] example from Object obj?
<c:forEach var="prop" items="${obj.example}">
<td>${prop}</td>
</c:forEach>
I get Errors that tell me the class obj.Obj does not have the property property 'example'
and obviously I don't get the data out.
Actual errors:
org.apache.jasper.JasperException: javax.el.PropertyNotFoundException: The class 'roommate.Roommate' does not have the property 'favProfessors'.
javax.el.PropertyNotFoundException: The class 'roommate.Roommate' does not have the property 'favProfessors'
And my actual class:
package roommate;
public class Roommate{
public String firstname;
public String lastname;
public String gender;
public String place;
public String[] favProfessors;
public Roommate(String fname, String lname, String roommateGender, String hangout,String[] professors) {
firstname= fname;
lastname= lname;
gender= roommateGender;
place= hangout;
favProfessors= professors;
}
public String getFirstname()
{
return firstname;
}
public void setFirstname(String newFirstname)
{
this.firstname = newFirstname;
}
public String getLastname()
{
return lastname;
}
public void setLastname(String newLastname)
{
this.lastname = newLastname;
}
public String getGender()
{
return gender;
}
public void setGender(String newGender)
{
this.gender = newGender;
}
public String getHangout()
{
return place;
}
public void setHangout(String newPlace)
{
this.place = newPlace;
}
public String[] getProfessors()
{
return favProfessors;
}
public void setProfessors(final String[] newfavProfessors)
{
this.favProfessors = newfavProfessors;
}
public void addRoommate(String fname, String lname, String roommateGender, String hangout,String[] professors)
{
}
}
I create the object in my servlet as well ass the Atrribute
String [] profArray = request.getParameterValues("professor");
Roommate roommate= new Roommate(
session.getAttribute("fname").toString(),
session.getAttribute("lname").toString(),
session.getAttribute("gender").toString(),
session.getAttribute("hangout").toString(),
profArray);
session.setAttribute("roommate",roommate);
I asked this earlier but did not receive a clear answer. I think my issue is in pulling the data out in the jsp alone in my forEach that I mentioned at the top
javax.el.PropertyNotFoundException: The class 'roommate.Roommate' does not have the property 'favProfessors'
Java is right. You do not have a getFavProfessors() method in that class. It's instead the following:
public String[] getProfessors()
{
return favProfessors;
}
You have 2 options: use ${roommate.professors} instead, or fix the getter method name to be getFavProfessors().
In contrary to what most starters think, EL does not access private properties directly. EL just calls the public getter/setter methods according the Javabeans specification. The real private property behind it can have a completely different name or even not exist at all.